CMake

The cmake macro supports CMake configuration, builds, and CTest execution.

Dependencies

CMake 3.20 or newer providing cmake and ctest is required.

The selected CMake generator and project toolchain must also be available. For example, using generator="Ninja" requires the ninja executable. Compilers and linkers are project toolchain requirements rather than cikit dependencies.

Features

  • CMake configuration

  • optional clean configuration

  • CMake build execution

  • CMake version metadata

  • compiler metadata collection through the CMake File API

  • optional compile_commands.json generation in the build directory

  • optimization and LTO metadata from the compilation database

  • CTest execution

  • parallel execution

  • configure, build, and total build time metrics

  • compiled file counts

  • compiler warning and error counts

  • linker memory usage metrics

  • configure and build command logs

  • JUnit XML output

  • cikit data updates

  • artifact registration

  • RST build reports

Typical build usage

from pathlib import Path

from cikit.macros import cmake

build_dir = cmake.get_build_dir(env)

cmake.gather_cmake_meta(env)

cmake.cmake_configure(env, source_dir=Path("."), build_dir=build_dir, generator="Ninja",
                      clean=True, compile_commands=True)

cmake.gather_compiler_meta(env, build_dir, "CXX")
cmake.cmake_build(env, build_dir)
cmake.write_rst(env)

CTest can also be executed independently on an already configured build directory:

cmake.ctest(env, build_dir, test_alias="ctest")

Build reports include the metrics and artifacts available for the current run. See Builds for the wider build and report workflow.

CMake and Compiler Metadata

CMake metadata can be collected independently from project configuration:

cmake.gather_cmake_meta(env)

This stores the version of the CMake executable as cmake_version.

After configuration, compiler metadata can be collected for a CMake language:

cmake.gather_compiler_meta(env, build_dir, "CXX")

The language must match a language enabled by the configured CMake project, for example C or CXX.

cikit uses the CMake File API toolchains-v1 reply generated during cmake_configure() and stores:

  • compiler

  • compiler_version

  • compiler_type

compiler_type contains the compiler ID reported by CMake, for example GNU or Clang.

When compile_commands=True is used, CMake generates the compilation database in its build directory without registering it as a cikit artifact. During cmake_build(), recognized optimization and LTO options are exposed as optimization and lto metrics.

Missing, invalid, or unavailable toolchain metadata is reported as a CiToolsError. Compilation-database-derived metrics are optional when the database or recognized options are unavailable.

Build directories and parallel execution

get_build_root(env) returns PROJECT_ROOT/build. The default name used by get_build_dir() is rel; explicitly named directories allow independent build configurations.

release_dir = cmake.get_build_dir(env, name="release")
debug_dir = cmake.get_build_dir(env, name="debug")

For a configured build directory, the optional jobs parameter controls parallel execution:

cmake.cmake_build(env, build_dir, jobs=4)
cmake.ctest(env, build_dir, jobs=4)