Welcome to cmake-pip’s documentation!

Contents:

Declaring a CMake extension

cmake_pip.cmake_extension.ExtensionCMake(...) Defines a cmake type extension.
cmake_pip.cmake_extension.build_cmake(dist) Calls cmake to build Yayi
cmake_pip.cmake_extension.setup(*args, **kwargs)

Reference

class cmake_pip.cmake_extension.ExtensionCMake(name, cmake_file, cmake_target=None, cmake_locate_extensions=None, cmake_options=None, cmake_package=None, cmake_src_layout=None, cmake_external_project=None, cmake_install=None, cmake_install_component=None, cmake_builder=None, *args, **kwargs)[source]

Defines a cmake type extension.

  • name : name of the package
  • cmake_target the target used to generate the extension. If empty, the default ALL target will be used.
  • cmake_install: an install command in the cmake sources installs the target in a specific location. Specify cmake_install_component if the install is for a particular component
  • cmake_install_component the component used for installation. See documentation. Implied cmake_install.
  • cmake_file the location of the cmake file or the cmake file itself
  • cmake_options cmake options
  • cmake_src_layout indicates that the layout is a regular one
  • cmake_external_project an external cmake project to download
  • cmake_builder the optional builder for the platform. Defaults to Makefiles on Linux/OSX and VS 2012 on Win32. The Win64 part should be omitted as it is automatically deduced by the current python executable/interpreter.

Overrides of the regular distutils commands

class cmake_pip.cmake_extension.build_cmake(dist)[source]

Calls cmake to build Yayi

cmake_configure(ext, options)[source]

Configuring CMake.

This is the main function for configuring CMake on all platforms. It takes

get_outputs()[source]

Returns the list of files generated by this specific build command

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',
    )

Indices and tables