CMake (Python distribution)

4.3.1 · active · verified Sun Apr 05

CMake is an open-source, cross-platform family of tools designed to build, test, and package software. The `cmake` Python package provides Python wheels for the CMake executable, making it easy to install and use CMake within Python environments. It is currently at version 4.3.1 and typically releases new versions in sync with upstream CMake releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to retrieve the path to the CMake executable provided by the `cmake` package and execute a basic CMake command using Python's `subprocess` module. It also shows how to get the version string directly from the `cmake` package.

import cmake
import subprocess
import sys

try:
    cmake_executable = cmake.cmake_path()
    print(f"Found CMake executable at: {cmake_executable}")

    # Run a simple CMake command, e.g., --version
    result = subprocess.run([cmake_executable, '--version'], capture_output=True, text=True, check=True)
    print("\nCMake --version output:")
    print(result.stdout)

    # Example of getting CMake version programmatically
    print(f"\nCMake version from package: {cmake.cmake_version()}")

except subprocess.CalledProcessError as e:
    print(f"Error running CMake: {e}", file=sys.stderr)
    print(f"Stderr: {e.stderr}", file=sys.stderr)
except Exception as e:
    print(f"An unexpected error occurred: {e}", file=sys.stderr)

view raw JSON →