Skip to content
Latchkey

CMake Presets Command Reference

Capture build settings in CMakePresets.json so CI and local builds match.

CMake presets store configure, build, and test settings in CMakePresets.json so a single named preset reproduces a build the same way everywhere.

What it does

A preset bundles generator, cache variables, build directory, and environment under a name in CMakePresets.json. cmake --preset configures it, cmake --build --preset builds it, and ctest --preset tests it, eliminating long ad hoc flag lists.

Common flags and usage

  • cmake --preset NAME: configure using a configure preset
  • cmake --build --preset NAME: build using a build preset
  • ctest --preset NAME: run a test preset
  • cmake --list-presets: list available presets
  • CMakeUserPresets.json: local overrides not committed to the repo

Example

shell
- name: Configure, build, test via presets
  run: |
    cmake --preset ci-release
    cmake --build --preset ci-release
    ctest --preset ci-release --output-on-failure

In CI

Define a ci preset committed to the repo so the pipeline runs the exact build developers run locally with the same name. This removes drift between long --flag lists in YAML and what engineers use on their machines.

Key takeaways

  • Presets capture generator, cache vars, and build dir under one name.
  • cmake --preset, cmake --build --preset, and ctest --preset share the definition.
  • A committed ci preset keeps local and CI builds identical.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →