Cmakepresets.json Example ((new)) ❲Plus ✔❳

These become -D flags passed to CMake. They override values from inherited presets. Build presets reference a configure preset by name. The jobs field controls parallel build level.

"buildPresets": [ "name": "dev-linux-gcc", "inherits": "default", "configurePreset": "dev-linux-gcc" ] When you run cmake --build --preset dev-linux-gcc , CMake automatically uses the binary directory from the corresponding configure preset. List available presets cmake --list-presets Output:

You can inherit from a hidden base, then from another preset, and finally override specific variables. Condition on build type "condition": "type": "equals", "lhs": "$envCI", "rhs": "true" cmakepresets.json example

Enter CMakePresets.json – a game-changing feature introduced in CMake 3.19 and continuously improved since. It allows you to define, version-control, and share build configurations in a single JSON file.

| Array | Purpose | |-------|---------| | "version" | Required – specifies preset file schema version. | | "configurePresets" | Defines cmake --configure options. | | "buildPresets" | Defines cmake --build options. | | "testPresets" | Defines ctest options. | | "packagePresets" | Defines cpack options (CMake 3.23+). | | "vendor" | IDE‑specific extensions (e.g., Visual Studio). | These become -D flags passed to CMake

Most users start with configurePresets and buildPresets . Below is a real‑world CMakePresets.json for a C++ project supporting Linux (GCC/Clang), Windows (MSVC), and macOS.

1. Version and Minimum CMake Version "version": 6, "cmakeMinimumRequired": "major": 3, "minor": 23, "patch": 0 The jobs field controls parallel build level

Available configure presets: "dev-linux-gcc" - Linux GCC (Debug) "dev-linux-clang" - Linux Clang (Release) "dev-windows-msvc"- Windows MSVC (Debug) "ci-linux-release"- CI Linux Release cmake --preset dev-linux-gcc This creates build/dev-linux-gcc/ and configures with GCC in Debug mode. Build using a preset cmake --build --preset dev-linux-gcc Run tests (if you define test presets) ctest --preset default Advanced Tips Use environment variables "environment": "CCACHE_DIR": "$sourceDir/.ccache"

Scroll to Top