Cmakepresets.json Example
,
"name": "common", "hidden": true, "binaryDir": "$sourceDir/build/$presetName", "generator": "Ninja", "cacheVariables": "MY_PROJECT_ENABLE_EXAMPLES": "OFF"
For years, CMake has been the de facto standard for building C++ projects. However, the user experience regarding the discovery and configuration of build options has historically been fragmented. Developers often had to memorize specific command-line flags or maintain separate scripts (e.g., Bash, PowerShell, Python) to invoke CMake with the correct parameters for Debug versus Release builds, sanitizers, or cross-compilation toolchains. cmakepresets.json example
"name": "dev-build", "displayName": "Build All", "configurePreset": "dev-default", "configuration": "Debug", "targets": ["all"] ,
This moves the complexity of "how to build" from YAML scripts into the CMake ecosystem where it belongs. CMakePresets
cmake --preset=dev-default cmake --build --preset=dev-build ctest --preset=dev-test
"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" "displayName": "Build All"
The example above works out of the box on Linux, Windows, and macOS. Copy it into your project, adjust compiler names and flags, and enjoy consistent builds everywhere.
CMakePresets.json was introduced to solve this by allowing project maintainers to encode common configurations directly within the project source tree. This file acts as a manifest of build "presets," which can be easily discovered by IDEs (such as Visual Studio, VS Code, and CLion) and command-line tools.
"name": "dev-linux-gcc", "inherits": "default", "configurePreset": "dev-linux-gcc"
,
