I was thinking of adding cache variables in the CMakeUserPreset.json file for some project specific configuration. But I don’t want to have to override all of the presets defined in my CMakePresets.json file. Instead, I’d want to extend the base preset that all other non-user presets inherit from. But I can’t do that, as it errors about there being a duplicate preset. And there seems to not be a way to define global cache variables?
Below is sort of what I mean. In the user preset, I tried with and without inherits and hidden, but none of those worked.
CMakePresets.json
{
"version": 4,
"configurePresets": [
{
"name": "all",
"binaryDir": "some-folder",
"hidden": true,
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"`,
//...
}
},
{
"name": "ninja",
"inherits": "all",
"generator": "Ninja Multi-Config"
},
{
"name": "vs",
"inherits": "all",
"generator": "Visual Studio 18 2026"
}
]
}
CMakeUserPresets.json
{
"version": 4,
"configurePresets": [
{
"name": "all",
//"inherits": "all",
"hidden": true,
"cacheVariables": {
"PROJECT_1": "../project-1",
"PROJECT_2": "../project-2"
}
}
]
}```