I try to use CMake Presets with workflows, but without too many permutations.
So I decided to have only a debug
and a release
workflow.
The user should be able to control the Compiler or Toolchain used.
bash-3.2$ cmake --list-presets
CMake Error: Could not read presets from /Users/clausklein/Workspace/cpp/cpp_vcpkg_project:
Inherited preset "ninja-multi-vcpkg" is unreachable from preset's file
bash-3.2$ mv CMakeUserPresets.json .CMakeUserPresets.json
bash-3.2$ cmake --list-presets
CMake Error: Could not read presets from /Users/clausklein/Workspace/cpp/cpp_vcpkg_project:
Invalid preset: "ninja-multi-vcpkg"
bash-3.2$ cmake --list-presets
Available configure presets:
"gcc-debug" - gcc Debug
"gcc-release" - gcc Release
"clang-debug" - clang Debug
"clang-release" - clang Release
"debug" - Debug
"release" - Release
bash-3.2$
How may I inherit from a user defined configurePreset
as long the CMakeUserPresets.json
does not exits?
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"configurePresets": [
{
"name": "user-config",
"description": "Example for user default settings that apply to all configurations",
"generator": "Ninja",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++"
}
}
]
}
CMakePresets.json
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"configurePresets": [
{
"name": "CMakeUserPresets-config",
"description": "Example for user default settings that apply to all configurations",
"hidden": true,
"generator": "Ninja",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++"
}
},
{
"name": "ninja-multi-vcpkg",
"displayName": "Ninja Multi-Config",
"description": "Configure with vcpkg toolchain and generate Ninja project files for all configurations",
"inherits": "CMakeUserPresets-config",
"generator": "Ninja Multi-Config",
"hidden": true,
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": {
"type": "FILEPATH",
"value": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake"
},
"VCPKG_CHAINLOAD_TOOLCHAIN_FILE": {
"type": "FILEPATH",
"value": "${sourceDir}/toolchain/WindowsToolchain/Windows.MSVC.toolchain.cmake"
}
}
},
{
"name": "common",
"description": "Settings for all toolchains",
"hidden": true,
"inherits": "ninja-multi-vcpkg",
"binaryDir": "${sourceDir}/build/${presetName}",
"installDir": "${sourceDir}/install/${presetName}",
"cacheVariables": {
"ENABLE_CPPCHECK": false,
"ENABLE_CLANG_TIDY": false
},
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
}
}
},
{
"name": "debug",
"displayName": "Debug",
"description": "Debug build type",
"inherits": "common",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"FEATURE_TESTS": true
}
},
{
"name": "release",
"displayName": "Release",
"description": "Release build type",
"inherits": "common",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"FEATURE_DOCS": true
}
}
],
"testPresets": [
{
"name": "common",
"description": "Test CMake settings that apply to all configurations",
"hidden": true,
"output": {
"outputOnFailure": true
},
"execution": {
"noTestsAction": "error",
"stopOnFailure": true
}
},
{
"name": "debug",
"displayName": "Strict",
"description": "Enable output and stop on failure",
"inherits": "common",
"configuration": "Debug",
"configurePreset": "debug"
},
{
"name": "release",
"displayName": "Strict",
"description": "Enable output and stop on failure",
"inherits": "common",
"configuration": "RelWithDebInfo",
"configurePreset": "release"
}
],
"buildPresets": [
{
"name": "release",
"configurePreset": "release"
},
{
"name": "install",
"configurePreset": "release",
"targets": ["install"]
},
{
"name": "gen-docs",
"configurePreset": "release",
"targets": ["doxygen-docs"]
},
{
"name": "debug",
"configurePreset": "debug"
}
],
"packagePresets": [
{
"name": "release",
"configurePreset": "release",
"generators": [
"TGZ"
]
}
],
"workflowPresets": [
{
"description": "Developer workflow without installation",
"name": "debug",
"steps": [
{
"type": "configure",
"name": "debug"
},
{
"type": "build",
"name": "debug"
},
{
"type": "test",
"name": "debug"
}
]
},
{
"description": "Release workflow without test",
"name" : "release",
"steps" : [
{
"name" : "release",
"type" : "configure"
},
{
"name" : "release",
"type" : "build"
},
{
"name" : "release",
"type" : "package"
}
]
}
]
}