Home

Awesome

cmake_example for pybind11

Gitter

CIstatus
MSVC 2019AppVeyor
conda.recipeConda Actions Status
pip buildsPip Actions Status
cibuildwheelWheels Actions Status

An example pybind11 module built with a CMake-based build system. This is useful for C++ codebases that have an existing CMake project structure. This is being replaced by scikit_build_example, which uses scikit-build-core, which is designed to allow Python packages to be driven from CMake without depending on setuptools. The approach here has some trade-offs not present in a pure setuptools build (see python_example) or scikit-build-core. Python 3.7+ required; see the commit history for older versions of Python.

Problems vs. scikit-build-core based example:

Prerequisites

Installation

Just clone this repository and pip install. Note the --recursive option which is needed for the pybind11 submodule:

git clone --recursive https://github.com/pybind/cmake_example.git
pip install ./cmake_example

With the setup.py file included in this example, the pip install command will invoke CMake and build the pybind11 module as specified in CMakeLists.txt.

Building the documentation

Documentation for the example project is generated using Sphinx. Sphinx has the ability to automatically inspect the signatures and documentation strings in the extension module to generate beautiful documentation in a variety formats. The following command generates HTML-based reference documentation; for other formats please refer to the Sphinx manual:

License

Pybind11 is provided under a BSD-style license that can be found in the LICENSE file. By using, distributing, or contributing to this project, you agree to the terms and conditions of this license.

Test call

import cmake_example
cmake_example.add(1, 2)