cmeel-boost: Boost C++ Libraries for CMake-based Python Wheels
cmeel-boost is a cmeel distribution that packages the widely used Boost C++ source libraries. It enables Python projects that utilize `cmeel` as their build backend to seamlessly incorporate and link against Boost C++ components within their CMake-based build process. The library aims to simplify the distribution of Boost for Python wheels. Version 1.89.0 is the latest stable release, with a release cadence that often aligns with upstream Boost versions.
Warnings
- gotcha cmeel-boost is a distribution of the *C++ Boost libraries* for `cmeel`-based Python wheels, not a Python wrapper library. You cannot `import cmeel_boost` in Python code and expect to access Boost C++ functionality directly through Python functions or classes. Its purpose is to provide the underlying C++ headers and compiled libraries for other C++/Python projects to link against.
- breaking Building projects that depend on `cmeel-boost` (and thus `cmeel` and CMake) requires a robust C++ development environment, including a compatible C++ compiler and CMake. Build failures can occur due to missing toolchains, incorrect compiler versions, or environment misconfigurations, especially on Windows where `pip install` can be challenging for such projects.
- gotcha When consuming `cmeel-boost` in your CMake project, ensure you use `find_package(Boost REQUIRED COMPONENTS ...)` correctly. While `cmeel-boost` provides the Boost libraries, CMake still needs to be instructed to find them and link them to your targets. Issues can arise if the Boost version requested by `find_package` is incompatible or if required components are not specified or available.
Install
-
pip install cmeel-boost
Imports
- Boost C++ Headers/Libraries
#include <boost/...
Quickstart
# Assume a C++ project 'my_cpp_lib' that uses Boost.
#
# 1. pyproject.toml for a Python package that depends on my_cpp_lib
# and needs cmeel-boost as a build dependency:
#
# [build-system]
# requires = ["cmeel[build]", "cmeel-boost~=1.89.0"]
# build-backend = "cmeel.build"
#
# [project]
# name = "my-python-package"
# version = "0.1.0"
#
# 2. CMakeLists.txt for my_cpp_lib (e.g., in a 'src' subdirectory):
#
# cmake_minimum_required(VERSION 3.15)
# project(my_cpp_lib LANGUAGES CXX)
#
# # Find Boost components. cmeel-boost will have installed Boost
# # in a location discoverable by CMake through CMAKE_PREFIX_PATH set by cmeel.
# find_package(Boost 1.89.0 REQUIRED COMPONENTS system thread)
#
# add_library(my_cpp_lib SHARED my_cpp_lib.cpp)
# target_include_directories(my_cpp_lib PUBLIC ${Boost_INCLUDE_DIRS})
# target_link_libraries(my_cpp_lib PUBLIC Boost::system Boost::thread)
#
# 3. my_cpp_lib.cpp (example C++ file using Boost):
#
# #include <iostream>
# #include <boost/version.hpp>
# #include <boost/system/error_code.hpp>
#
# extern "C" void say_boost_version() {
# std::cout << "Boost Version: " << BOOST_VERSION / 100000 << ".";
# std::cout << (BOOST_VERSION / 100 % 1000) << ".";
# std::cout << (BOOST_VERSION % 100) << std::endl;
# boost::system::error_code ec;
# // Example use, not doing anything meaningful with ec here
# if (ec) {
# std::cerr << "Error: " << ec.message() << std::endl;
# }
# }
#
# 4. To build a wheel for 'my-python-package':
# (Ensure your environment has a C++ compiler compatible with Boost.)
# python -m pip wheel .
# Note: This code block demonstrates the C++/CMake usage. The `python -m cmeel cmake` command
# is typically run internally by `pip` when building a `cmeel`-based package that depends on `cmeel-boost`.
# For debugging or manual usage in a C++ project outside `cmeel`, you might run:
# export CMAKE_PREFIX_PATH=$(python -m cmeel cmake)
# cmake -S . -B build
# cmake --build build
import os
# Placeholder for a Python script that might invoke the C++ library (if bindings existed)
# cmeel-boost itself does not provide Python callable functions.
print("cmeel-boost provides C++ libraries, not direct Python imports for Boost functionality.")
print("To use it, your Python package must be built with cmeel and link against Boost in its CMake project.")