cmake-pip
CMake bindings to pip made simple.
This project makes easy the creation and distribution of python packages with
extensions built with CMake and with complex set of dependencies through its
integration with conan.
Why using cmake-pip
Python extension system through setuptools is simple and effective, but hardly scales up
beyond a few source files, and does not handle dependencies that are outside the python ecosystem
well: linking the python extension to eg. a system library makes the packaging less
portable and harder to maintain.
CMake is a mature tool for defining C/C++ projects with more than 2 decades of updates and running, it is widely accepted as an industry standard for building simple or complex projects, in a platform agnostic way. It provides a wide spectrum of features and integration with libraries and compilers.
Your own C/C++ library is just one side of the story: a common case is when a project needs
to integrate with features provided by libraries that are external to your project. CMake usually
integrates well with this, but performs not so well when several projects, each with their own build
infrastructure, variables, options... are involved. And this is where conan shines:
its simplicity for injecting external projects to yours and its great community support
provides you the missing piece in the C/C++ world for constructing software with complex
dependencies.
Documentation
The full documentation of cmake-pip is available
online — start with the
worked examples, each of which is a fixture of the test suite and installs
end-to-end.
Features
- one declaration in
setup.py, plain modern CMake on the project side - wheels, source distributions and PEP 660 editable installs
- version injection into the cmake configuration (
setuptools_scmfriendly) - relocatable packages:
rpathrewriting, runtime dependency collection, and linuxsonamemangling of the vendored libraries - conan integration: dependencies declared in
setup.py, recipes pulled fromconan-center-indexat a pinned revision, self-provisionedCONAN_HOME - build only what the wheel needs (the
cmake_pip_targetumbrella target) and optionally run the project'sctestsuite before anything is staged
How to use
The interface is made very simple:
-
on the
setup.py/pyproject.tomlside, use a specific extension to instruct the python packaging system about CMake and conan dependencies.For your
pyproject.toml, you just need to specify a build dependency:[build-system] requires = ["setuptools", "cmake-pip"]
On the
setup.py, declare your CMake project and instructsetuptoolsas follow:# setup.py -- everything else lives in pyproject.toml from setuptools import setup from cmake_pip.cmake_extension import ExtensionCMake my_cmake_extensions = ExtensionCMake( "my_package.my_extensions", "my_cmake_project/CMakeLists.txt", cmake_install_component="python_ext_component") setup(ext_modules=[my_cmake_extensions])
-
on the cmake side: use directives to declare the content of a python package,
# this declares "python_package_add_target" and is provided # by cmake-pip find_package(cmakepip) python3_add_library(my_module1 MODULE src/my_module1.cpp) python3_add_library(my_module2 MODULE src/my_module2.cpp) python_package_add_target(TARGET my_module1 DESTINATION my_extensions/ PYTHON_PACKAGE python_ext_component) python_package_add_target(TARGET my_module2 DESTINATION my_extensions/ PYTHON_PACKAGE python_ext_component)
Et voilà! With very little changes to your CMake and python package side, you
can define a python package with many python extensions. No need to specify those
in the python package, cmake-pip takes care of it. No need also to package the shared libraries
your extensions depend on, neither complicated renaming: cmake-pip is there for this.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cmake_pip-0.1.tar.gz.
File metadata
- Download URL: cmake_pip-0.1.tar.gz
- Upload date:
- Size: 117.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3783e5e9ca3e0c52da66b591d9e9bbc4ef169e4b0b63ec483f76d562cfffc380
|
|
| MD5 |
baa45bb601c22df1faa2f9659d674a05
|
|
| BLAKE2b-256 |
c92865bf1cb279112c83938c80e6e0810b7a99214204c139724206b911a2f7ad
|
File details
Details for the file cmake_pip-0.1-py3-none-any.whl.
File metadata
- Download URL: cmake_pip-0.1-py3-none-any.whl
- Upload date:
- Size: 42.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a632dfd01197c69c8610226a5a899943c4171d9fb14a3fc9d9e2ead3fc796d70
|
|
| MD5 |
cf5f9b58c65976a21a3d0ba0da125c74
|
|
| BLAKE2b-256 |
6b17a37a07aa88d68d449e403f02e50e6b08a1e7515fd8ab9af07151ea9e1023
|