"version": 6, "cmakeMinimumRequired": "major": 3, "minor": 23, "patch": 0 , "configurePresets": [ "name": "default", "hidden": true, "generator": "Ninja", "binaryDir": "$sourceDir/build/$presetName", "cacheVariables": "CMAKE_CXX_STANDARD": "20", "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" , "name": "dev-linux-gcc", "inherits": "default", "displayName": "Linux GCC (Debug)", "description": "Debug build using GCC on Linux", "condition": "type": "equals", "lhs": "$hostSystemName", "rhs": "Linux" , "cacheVariables": "CMAKE_CXX_COMPILER": "g++", "CMAKE_BUILD_TYPE": "Debug" , "name": "dev-linux-clang", "inherits": "default", "displayName": "Linux Clang (Release)", "description": "Release build using Clang on Linux", "condition": "type": "equals", "lhs": "$hostSystemName", "rhs": "Linux" , "cacheVariables": "CMAKE_CXX_COMPILER": "clang++", "CMAKE_BUILD_TYPE": "Release" , "name": "dev-windows-msvc", "inherits": "default", "displayName": "Windows MSVC (Debug)", "description": "Debug build using MSVC on Windows", "condition": "type": "equals", "lhs": "$hostSystemName", "rhs": "Windows" , "generator": "Visual Studio 17 2022", "architecture": "value": "x64", "strategy": "set" , "cacheVariables": "CMAKE_BUILD_TYPE": "Debug" , "name": "ci-linux-release", "inherits": "dev-linux-gcc", "displayName": "CI Linux Release", "description": "Release build for CI pipelines", "cacheVariables": "CMAKE_BUILD_TYPE": "Release", "CMAKE_CXX_FLAGS": "-Wall -Wextra -Werror" ], "buildPresets": [ "name": "default", "hidden": true, "configurePreset": "default", "jobs": 4, "targets": ["all"] , "name": "dev-linux-gcc", "inherits": "default", "configurePreset": "dev-linux-gcc" , "name": "dev-linux-clang", "inherits": "default", "configurePreset": "dev-linux-clang" , "name": "dev-windows-msvc", "inherits": "default", "configurePreset": "dev-windows-msvc", "configuration": "Debug" , "name": "ci-linux-release", "inherits": "default", "configurePreset": "ci-linux-release" ]
Managing CMake configurations across different environments (debug, release, Windows, Linux, macOS, CI/CD) can quickly become messy. Command-line variables and toolchain files are powerful, but they’re hard to share and standardize. cmakepresets.json example
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" Build using a preset cmake --build --preset dev-linux-gcc
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. then from another preset
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"
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.