Welcome to cmake-pip’s documentation!¶
Contents:
cmake-pip is a simple wrapper around CMake in order to be able to have CMake extensions as python modules.
Getting started¶
Suppose our repository has the following layout:
setup.py
my_cmake_project
|CMakeLists.txt
|source_code
|python_extension.cpp
python_src
|__init__.py
|my_pure_python.py
In this very simple use case, what we want is:
- to declare a package called my_package
- include a pure python module my_pure_python
- include a python extension that is built with cmake:
- The location of the CMakeLists.txt is ./my_cmake_project/CMakeLists.txt. The underlying layout is up to the cmake project
- The generated python extension will be called extension1
- The generated python extension will go to the root of my_package
Then what we need to declare is an ExtensionCMake in which we instruct the setup.py
- what extension we are about to generate: in this case this is my_package.extension1
- the location of the CMakeLists.txt generating this extension: ./my_cmake_project/CMakeLists.txt
- and the ExtensionCMake to look for all suitable extensions generated by cmake (option cmake_locate_extensions=True).
This gives:
# source the cmake-pip extensions
from cmake_pip.cmake_extension import ExtensionCMake, setup
# define a CMake package
ext1 = ExtensionCMake('my_package.extension1',
'my_cmake_project/CMakeLists.txt',
cmake_locate_extensions=True)
# calls the setup and declare our 'my_cool_package'
setup(name='my_cool_package',
version='1.0',
packages=['my_package'],
package_dir={'my_package': 'python_src'}, # those are the python files of the package
ext_modules=[ext1], # those are the extensions, including all the CMake extensions
author='Raffi Enficiaud',
url='https://bitbucket.org/renficiaud/cmake-pip',
description='This is a test',
license='BSD-3-Clauses',
)