cmake-build-extension is a Setuptools extension designed to simplify the integration of C++ projects based on CMake with Python packaging tools. It enables configuring and building CMake projects directly from `setup.py`, installing their artifacts into the resulting Python package, and passing custom CMake options. The library also provides a context manager for reliable CPython module imports across operating systems. It is currently at version 0.6.1, with releases occurring on an as-needed basis for features and bug fixes.
pip install cmake-build-extensionVerified import paths — ran on the pinned version, not inferred.
To use `cmake-build-extension`, you typically define `CMakeExtension` objects within the `ext_modules` list in your `setup.py` and register `BuildExtension` in `cmdclass`. The `CMakeExtension` points to your CMake project and specifies installation details. Ensure your `CMakeLists.txt` is configured to build and install the necessary artifacts.
Upgrade Python to 3.7+ or pin cmake-build-extension to <0.6.0.
Review your `setup.py` and any `CMAKE_ARGS` environment variables for generator specification. Utilize the `cmake_configure_options` in `CMakeExtension` for explicit control.
Always use a dedicated build directory for CMake, and ensure your `setup.py` configuration respects this. Consider adding a check to your `CMakeLists.txt` to enforce out-of-source builds.
Thoroughly test package installation and import in isolated environments. For `manylinux` wheels, use tools like `auditwheel` or CI solutions like `cibuildwheel`.
Install the package using `pip install cmake-build-extension` within your active Python environment. If issues persist, ensure no conflicting 'cmake' Python package is installed, or try installing in a clean virtual environment.
Install CMake globally on your system (e.g., via your system's package manager, Homebrew on macOS, or the official CMake website) and ensure its binary directory is added to your system's PATH.
Install CMake on your operating system and verify that the `cmake` executable is available in your system's PATH. On Linux, this might be `sudo apt-get install cmake`; on macOS, `brew install cmake`; on Windows, install from the official CMake website and ensure 'Add CMake to the system PATH' is selected during installation.
Ensure your `CMakeExtension` in `setup.py` correctly specifies the output directory for the compiled C++ module, typically within your Python package. `cmake-build-extension` usually handles this by default, but check `CMAKE_RUNTIME_OUTPUT_DIRECTORY` or `CMAKE_LIBRARY_OUTPUT_DIRECTORY` settings in your CMakeLists.txt or custom `CMakeExtension` logic to ensure binaries are placed where Setuptools expects them (e.g., alongside your Python source files or in the appropriate site-packages subdirectory).