CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-scikit-build

Improved build system generator for Python C/C++/Fortran/Cython extensions

Pending
Overview
Eval results
Files

cmake-interface.mddocs/

CMake Interface

Direct interface to CMake executable for project configuration, building, and installation. Provides programmatic access to CMake operations with Python integration for version detection, cache management, and platform-specific build handling.

Capabilities

CMaker Class

Main interface class for interacting with CMake executable, providing methods for configuration, building, and installation of CMake projects.

class CMaker:
    def __init__(self, cmake_executable: str = CMAKE_DEFAULT_EXECUTABLE) -> None:
        """
        Initialize CMaker with path to CMake executable.
        
        Parameters:
        - cmake_executable: Path to cmake executable (default: "cmake")
        """

Project Configuration

Configure CMake project with specified parameters, handling generator selection, source directory setup, and build configuration.

def configure(
    self, 
    clargs: Sequence[str] = (), 
    generator_name: str | None = None, 
    skip_generator_test: bool = False, 
    cmake_source_dir: str = ".", 
    cmake_install_dir: str = "", 
    languages: Sequence[str] = ("C", "CXX"), 
    cleanup: bool = True
) -> dict[str, str]:
    """
    Configure CMake project with specified parameters.
    
    Parameters:
    - clargs: Additional command-line arguments for CMake
    - generator_name: CMake generator to use (auto-detected if None)
    - skip_generator_test: Skip generator compatibility testing
    - cmake_source_dir: Directory containing CMakeLists.txt
    - cmake_install_dir: Installation directory for CMake
    - languages: Programming languages to enable in CMake
    - cleanup: Clean build directory before configuration
    
    Returns:
    Dictionary of CMake cache variables and their values
    
    Raises:
    SKBuildError: If configuration fails
    SKBuildGeneratorNotFoundError: If no suitable generator found
    """

Project Building

Build CMake project using the configured generator with support for different build configurations and parallel builds.

def make(
    self, 
    clargs: Sequence[str] = (), 
    config: str = "Release", 
    source_dir: str = ".", 
    install_target: str = "install", 
    env: Mapping[str, str] | None = None
) -> None:
    """
    Build CMake project using configured generator.
    
    Parameters:
    - clargs: Additional command-line arguments for build
    - config: Build configuration (Release, Debug, etc.)
    - source_dir: Source directory for build
    - install_target: CMake target to build and install  
    - env: Environment variables for build process
    
    Raises:
    SKBuildError: If build fails
    """

Project Installation

Install built CMake project and return list of installed files for package management.

def install(self) -> list[str]:
    """
    Install built CMake project.
    
    Installs the built project using CMake and returns list of
    files that were installed for package management.
    
    Returns:
    List of installed file paths
    
    Raises:
    SKBuildError: If installation fails
    """

Cache Management

Static methods for retrieving cached CMake configuration values from previous builds.

@staticmethod
def get_cached(variable_name: str) -> str | None:
    """
    Retrieve cached CMake variable value.
    
    Parameters:
    - variable_name: Name of CMake cache variable
    
    Returns:
    Variable value if found, None otherwise
    """

@classmethod  
def get_cached_generator_name(cls) -> str | None:
    """
    Return cached CMake generator name from previous build.
    
    Returns:
    Generator name if cached, None otherwise
    """

def get_cached_generator_env(self) -> dict[str, str] | None:
    """
    Return environment variables for cached generator.
    
    Returns:
    Dictionary of environment variables if available, None otherwise
    """

Python Integration

Static methods for detecting Python configuration and integration with CMake builds.

@staticmethod
def get_python_version() -> str:
    """
    Return current Python version string.
    
    Returns:
    Python version in format "major.minor"
    """

@staticmethod
def get_python_include_dir(python_version: str) -> str | None:
    """
    Return Python include directory path for given version.
    
    Parameters:
    - python_version: Python version string
    
    Returns:
    Path to Python include directory, None if not found
    """

@staticmethod
def get_python_library(python_version: str) -> str | None:
    """
    Return Python library path for given version.
    
    Parameters:
    - python_version: Python version string
    
    Returns:
    Path to Python library file, None if not found
    """

@staticmethod
def check_for_bad_installs() -> None:
    """
    Check for problematic Python installations.
    
    Validates Python installation and warns about known
    problematic configurations that may affect building.
    
    Raises:
    SKBuildError: If critical installation problems detected
    """

Version Detection

Utility functions for CMake version detection and validation.

def get_cmake_version(cmake_executable: str = CMAKE_DEFAULT_EXECUTABLE) -> str:
    """
    Execute CMake to extract version information.
    
    Parameters:
    - cmake_executable: Path to cmake executable
    
    Returns:
    CMake version string
    
    Raises:
    SKBuildError: If cmake executable not found or fails
    """

Argument Utilities

Helper functions for processing CMake arguments and cache variables.

def pop_arg(
    arg: str, 
    args: Sequence[str], 
    default: str | None = None
) -> tuple[list[str], str | None]:
    """
    Remove and return argument from argument list.
    
    Pops an argument from an argument list and returns the new list
    and the value of the argument if present, or default otherwise.
    
    Parameters:
    - arg: Argument name to find and remove
    - args: List of arguments to search
    - default: Default value if argument not found
    
    Returns:
    Tuple of (remaining_arguments, argument_value)
    """

def has_cmake_cache_arg(
    cmake_args: list[str], 
    arg_name: str, 
    arg_value: str | None = None
) -> bool:
    """
    Check if CMake cache argument exists in argument list.
    
    Return True if -D<arg_name>:TYPE=<arg_value> is found in cmake_args.
    If arg_value is None, return True only if -D<arg_name>: is found in the list.
    
    Parameters:
    - cmake_args: List of CMake arguments  
    - arg_name: Cache variable name to check
    - arg_value: Optional specific value to match
    
    Returns:
    True if argument found, False otherwise
    """

Usage Examples

Basic CMake Operations

from skbuild.cmaker import CMaker
from skbuild.constants import CMAKE_DEFAULT_EXECUTABLE

# Initialize CMaker
cmaker = CMaker(CMAKE_DEFAULT_EXECUTABLE)

# Configure project
config_vars = cmaker.configure(
    clargs=["-DCMAKE_BUILD_TYPE=Release"],
    cmake_source_dir="src",
    languages=["C", "CXX"]
)

# Build project  
cmaker.make(config="Release", install_target="install")

# Install and get file list
installed_files = cmaker.install()
print(f"Installed {len(installed_files)} files")

Advanced Configuration

from skbuild.cmaker import CMaker, get_cmake_version
import os

# Check CMake version
cmake_exe = "/usr/local/bin/cmake"
version = get_cmake_version(cmake_exe)
print(f"Using CMake version: {version}")

# Initialize with custom executable
cmaker = CMaker(cmake_exe)

# Configure with custom environment
env_vars = {"CC": "gcc-9", "CXX": "g++-9"}
config_vars = cmaker.configure(
    clargs=[
        "-DCMAKE_BUILD_TYPE=Debug",
        "-DENABLE_TESTING=ON",
        f"-DPYTHON_EXECUTABLE={sys.executable}"
    ],
    generator_name="Unix Makefiles",
    cmake_source_dir="native",
    languages=["C", "CXX", "Fortran"]
)

# Build with parallel jobs
cmaker.make(
    clargs=["-j", "4"],
    config="Debug", 
    env=env_vars
)

Cache Variable Access

from skbuild.cmaker import CMaker

# Check cached values from previous builds
generator = CMaker.get_cached_generator_name()
if generator:
    print(f"Using cached generator: {generator}")

python_version = CMaker.get_python_version()
include_dir = CMaker.get_python_include_dir(python_version)
python_lib = CMaker.get_python_library(python_version)

print(f"Python {python_version}")
print(f"Include dir: {include_dir}")
print(f"Library: {python_lib}")

Install with Tessl CLI

npx tessl i tessl/pypi-scikit-build

docs

build-commands.md

cmake-interface.md

constants-utilities.md

exception-handling.md

index.md

platform-integration.md

setup-configuration.md

tile.json