CMake is an open-source, cross-platform family of tools designed to build, test and package software
npx @tessl/cli install tessl/pypi-cmake@4.1.0CMake is an open-source, cross-platform family of tools designed to build, test and package software. This Python distribution provides a convenient way to install CMake via pip and execute CMake commands through Python wrapper functions.
pip install cmakeimport cmakeFor accessing constants:
from cmake import CMAKE_BIN_DIR, CMAKE_DATA, CMAKE_DOC_DIR, CMAKE_SHARE_DIRFor accessing command functions:
from cmake import cmake, cpack, ctest, ccmakeimport cmake
import sys
# Execute cmake directly (equivalent to running cmake command-line tool)
# This will execute cmake with any command-line arguments provided to the script
cmake.cmake()
# Execute other CMake tools
cmake.cpack() # Package generation tool
cmake.ctest() # Testing tool
cmake.ccmake() # GUI configuration tool
# Access CMake installation paths
print(f"CMake binary directory: {cmake.CMAKE_BIN_DIR}")
print(f"CMake data directory: {cmake.CMAKE_DATA}")
print(f"CMake documentation directory: {cmake.CMAKE_DOC_DIR}")
print(f"CMake share directory: {cmake.CMAKE_SHARE_DIR}")The cmake package provides Python wrapper functions that execute the corresponding native CMake binaries. The package automatically locates the CMake installation within the Python package and provides path constants for accessing different components of the CMake installation.
These functions execute the corresponding CMake command-line tools, passing through all command-line arguments from sys.argv[1:]. Each function replaces the current process with the CMake binary (on Unix-like systems) or exits with the binary's return code (on Windows).
def cmake():
"""
Execute the cmake binary with command-line arguments.
This function does not return normally - it either replaces the current
process with cmake (Unix) or raises SystemExit with cmake's exit code (Windows).
Returns:
NoReturn: Function does not return normally
"""
def cpack():
"""
Execute the cpack (CMake packaging) binary with command-line arguments.
This function does not return normally - it either replaces the current
process with cpack (Unix) or raises SystemExit with cpack's exit code (Windows).
Returns:
NoReturn: Function does not return normally
"""
def ctest():
"""
Execute the ctest (CMake testing) binary with command-line arguments.
This function does not return normally - it either replaces the current
process with ctest (Unix) or raises SystemExit with ctest's exit code (Windows).
Returns:
NoReturn: Function does not return normally
"""
def ccmake():
"""
Execute the ccmake (CMake GUI) binary with command-line arguments.
This function does not return normally - it either replaces the current
process with ccmake (Unix) or raises SystemExit with ccmake's exit code (Windows).
Returns:
NoReturn: Function does not return normally
"""These constants provide access to the CMake installation paths within the Python package.
CMAKE_BIN_DIR: str
"""
Path to the CMake binary directory containing cmake, cpack, ctest, and ccmake executables.
Type: str
"""
CMAKE_DATA: str
"""
Path to the base CMake data directory. This is the root directory of the CMake installation
within the Python package.
Type: str
"""
CMAKE_DOC_DIR: str
"""
Path to the CMake documentation directory containing CMake help files and documentation.
Type: str
"""
CMAKE_SHARE_DIR: str
"""
Path to the CMake share directory containing modules, templates, and other shared resources.
Type: str
"""
__version__: str
"""
The version of the cmake package.
Type: str
"""# In a script that needs to run cmake
import cmake
import sys
# Add cmake arguments to sys.argv before calling
sys.argv = ['script.py', '--version']
cmake.cmake() # Executes: cmake --versionimport cmake
import os
# Get path to cmake binary
cmake_binary = os.path.join(cmake.CMAKE_BIN_DIR, 'cmake')
# Access CMake modules directory
cmake_modules = os.path.join(cmake.CMAKE_SHARE_DIR, 'cmake', 'Modules')
# Check if documentation exists
doc_exists = os.path.exists(cmake.CMAKE_DOC_DIR)The package can also be executed as a module:
python -m cmake --versionThis is equivalent to calling cmake.cmake() directly.
When installed, the package provides console scripts that can be executed directly from the command line:
cmake - Executes the cmake binarycpack - Executes the cpack binaryctest - Executes the ctest binaryccmake - Executes the ccmake binaryThese scripts are automatically installed when the package is installed via pip and are equivalent to calling the corresponding Python functions.
All command execution functions (cmake, cpack, ctest, ccmake) handle errors by:
SystemExit with the binary's return codeos.execlNo custom exceptions are raised by the package itself - all error handling is delegated to the underlying CMake binaries.
The package works across all platforms supported by CMake:
subprocess.call and SystemExit for command executionos.execl for efficient process replacement