or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/pypi-cmake

CMake is an open-source, cross-platform family of tools designed to build, test and package software

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/cmake@4.1.x

To install, run

npx @tessl/cli install tessl/pypi-cmake@4.1.0

index.mddocs/

CMake

CMake 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.

Package Information

  • Package Name: cmake
  • Package Type: pypi
  • Language: Python
  • Installation: pip install cmake

Core Imports

import cmake

For accessing constants:

from cmake import CMAKE_BIN_DIR, CMAKE_DATA, CMAKE_DOC_DIR, CMAKE_SHARE_DIR

For accessing command functions:

from cmake import cmake, cpack, ctest, ccmake

Basic Usage

import 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}")

Architecture

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.

Capabilities

Command Execution Functions

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
    """

Path Constants

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
"""

Usage Examples

Running CMake Commands

# 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 --version

Accessing CMake Installation Paths

import 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)

Using as Command-Line Module

The package can also be executed as a module:

python -m cmake --version

This is equivalent to calling cmake.cmake() directly.

Console Scripts

When installed, the package provides console scripts that can be executed directly from the command line:

  • cmake - Executes the cmake binary
  • cpack - Executes the cpack binary
  • ctest - Executes the ctest binary
  • ccmake - Executes the ccmake binary

These scripts are automatically installed when the package is installed via pip and are equivalent to calling the corresponding Python functions.

Error Handling

All command execution functions (cmake, cpack, ctest, ccmake) handle errors by:

  1. Exit codes: The functions exit with the same exit code as the underlying CMake binary
  2. SystemExit: On Windows, functions raise SystemExit with the binary's return code
  3. Process replacement: On Unix-like systems, functions replace the current process with the CMake binary using os.execl

No custom exceptions are raised by the package itself - all error handling is delegated to the underlying CMake binaries.

Platform Support

The package works across all platforms supported by CMake:

  • Windows: Uses subprocess.call and SystemExit for command execution
  • Unix-like systems (Linux, macOS): Uses os.execl for efficient process replacement
  • All platforms: Path constants work consistently across operating systems