My CMakePresets.json
:
{
"version": 3,
"configurePresets": [
{
"name": "base",
"hidden": true,
"generator": "Ninja",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-cl",
"CMAKE_CXX_COMPILER": "clang-cl",
"CMAKE_C_FLAGS": "-fuse-ld=lld /EHsc",
"CMAKE_CXX_FLAGS": "-fuse-ld=lld /EHsc"
},
"condition": {
"type":"inList",
"string": "${hostSystemName}",
"list": ["Linux", "Windows"]
}
},
{
"name": "x64-debug",
"displayName": "x64 Debug",
"inherits": "base",
"binaryDir": "${sourceDir}/build/x64/Debug",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
}
],
"buildPresets": [
{
"name": "x64-debug",
"configurePreset": "x64-debug"
}
]
}
My CMakeUserPresets.json
:
{
"version": 3,
"configurePresets": [
{
"name": "x64-debug-special",
"inherits": "x64-debug",
"cacheVariables": {
"CMAKE_C_FLAGS": "/winsdkdir /path",
"CMAKE_CXX_FLAGS": "/winsdkdir /path"
}
}
],
"buildPresets": [
{
"name": "x64-debug-special",
"configurePreset": "x64-debug-special"
}
]
}
When I run cmake --debug-output --preset x64-debug-special
, the CMAKE_C_FLAGS
and CMAKE_CXX_FLAGS
aren’t the combined flags from base
and x64-debug-special
as I expect following from the documentation:
Cache variables are inherited through the
inherits
field, and the preset’s variables will be the union of its owncacheVariables
and thecacheVariables
from all its parents. If multiple presets in this union define the same variable, the standard rules ofinherits
are applied. Setting a variable tonull
causes it to not be set, even if a value was inherited from another preset.
$ cmake --debug-output --preset x64-debug-special
Running with debug output on.
Preset CMake variables:
CMAKE_BUILD_TYPE="Debug"
CMAKE_CXX_COMPILER="clang-cl"
CMAKE_CXX_FLAGS="/winsdkdir /path"
CMAKE_C_COMPILER="clang-cl"
CMAKE_C_FLAGS="/winsdkdir /path"
If I remove cacheVariables
from the x64-debug-special
preset, I can see that the x64-debug
config preset’s cacheVariables
are inherited.