cmake_pywhl
A CMake module for building Python wheels directly from CMake projects. It integrates compiled C/C++ extensions (via nanobind, pybind11, ctypes, etc.) and pure Python source files into PEP 427-compliant wheel archives, with full support for PEP 660 editable installs.
Requirements
- CMake 3.20+
- Python 3.12+
2. Integrate into your CMakeLists.txt
nanobind_add_module(_myext src/_myext.cpp)
# Declare a pywhl module (maps to a top-level Python package)
add_pywhl_module(mypackage
TARGETS _myext
SCRIPTS
# Can be individual files or folders
# Rules for files
folder1/file1.py # -> file1.py
folder4/file1.py@ext1 # -> ext1/file1.py
# Rules for folders
folder2 # folder2/subfolder1/file1.py -> subfolder/file1.py
folder3@ext1 # folder3/subfolder1/file1.py -> ext1/subfolder1/file1.py
)
# Create wheel and editable-install targets
add_pywhl_package(mypackage
VERSION "${PROJECT_VERSION}"
MODULES mypackage
LICENSE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
METADATA_FILE "${CMAKE_CURRENT_SOURCE_DIR}/METADATA"
)
3. Build
cmake -B build -DCMAKE_MODULE_PATH=/path/to/pywhl
cmake --build build # builds editable install (ALL target)
cmake --build build --target mypackage # builds the .whl file
The editable install target (mypackage_dev_whl) runs as part of ALL and installs import hooks into the active Python environment via a .pth file. The wheel target (mypackage) produces a distributable .whl archive.
API Reference
add_pywhl_module(name ...)
Registers a Python module (package directory) that will be included in a wheel.
| Parameter | Description |
|---|---|
TARGETS target1 ... |
CMake targets (compiled libraries or executables) whose output files are bundled |
SCRIPTS file_or_dir ... |
Python source files or directories; a directory with __init__.py is treated as a package |
DATA_FILES file ... |
Arbitrary data files to bundle |
EXCLUDE_REGEX pattern |
Regex pattern to exclude matching paths |
Scripts and data files can use src@dest syntax to rename items inside the wheel: mymodule/config.ini@config.ini.
add_pywhl_package(targetName ...)
Creates two CMake targets: a wheel-build target (targetName) and an editable-install target (default: targetName_dev_whl, runs as ALL).
| Parameter | Default | Description |
|---|---|---|
MODULES mod1 ... |
required | List of module names registered with add_pywhl_module |
VERSION x.y.z |
0.0.1 |
Wheel version |
LICENSE_FILE path |
./LICENSE |
License file (required) |
METADATA_FILE path |
./METADATA |
Package metadata template (Python string.Template syntax with ${name}, ${version}) |
ENTRY_POINTS_FILE path |
./entry_points.txt |
Console scripts / entry points |
EDITABLE_TARGET name |
targetName_dev_whl |
Override the editable target name |
whl_file_OUTVAR var |
— | CMake variable to receive the output wheel path |
METADATA template
The METADATA file is a Python string.Template supporting ${name} and ${version} substitutions:
Metadata-Version: 2.1
Name: ${name}
Version: ${version}
Summary: My package
Author: Your Name
License: MIT
entry_points.txt
Standard INI format accepted by pip:
[console_scripts]
my-tool = mypackage.cli:main
Project layout example
myproject/
├── CMakeLists.txt
├── LICENSE
├── METADATA
├── entry_points.txt # optional
├── src/
│ └── _myext.cpp # C++ nanobind extension
└── mypackage/
├── __init__.py # imports from _myext
└── helpers.py
License
MIT — see LICENSE.
Metadata
Release files for cmake-pywhl 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cmake_pywhl-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for cmake_pywhl-0.0.5-py3-none-any.whl |
Release files / cmake_pywhl-0.0.5-py3-none-any.whl
| Download URL | cmake_pywhl-0.0.5-py3-none-any.whl |
|---|---|
| Size | 15.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3cacdeccb113a8917be73057c9b0c5101c4c48787ca9970e0399be9ca54ea342
|
|
BLAKE2b-256 checksum How to use checksums |
485961898ae3abb313bd599e718c110bd18a57cd694fc3a81b65ec2659dd0dc4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logSecurity for cmake-pywhl 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
1 file in this release has been uploaded with provenance metadata.
Attestation for cmake_pywhl-0.0.5-py3-none-any.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.