presets: Allow extending/overriding of existing presets
Suppose I have some common
and msvs
configurePresets
in CMakePresets.json. Their content is irrelevant (msvs
inherits common
) but they have some reasonable defaults with all the build and test presets written around them.
Now I'm a user of that project and I want to change some details. For example, the project defaults to MSVS 2019 and I use 2022, I also happen to know where Boost on my system located etc.
So I'd want to do the following in my CMakeUserPresets.json:
{
"version": 3,
"configurePresets": [
{
"name": "common",
"cacheVariables": {
"Boost_DIR": "Path/To/Boost/Config"
},
"vendor": {
"jetbrains.com/clion": {
"toolchain": "Visual Studio"
}
}
},
{
"name": "msvs",
"generator": "Visual Studio 17 2022"
}
]
}
And that's it, no additional build or test presets, no nothing. So I then go to the console, type cmake --preset msvs
and it correctly finds Boost and generate me a MSVS 2022 solution file.
Some might say that it is feasible with inheritance and it is but even for such a simple configuration it requires too much typing. With more presets it would be simply unapproachable. Besides I don't want to generate new presets, I use the same msvs
preset that everyone else, just customized it a little bit to adjust it to my local needs. And in my opinion CMakeUserPresets.json is exactly the place for such customizations.
Note that I'm not proposing any particular syntax, just a general idea. Maybe the extending preset should have the "extending"
attribute, maybe it should have something like: "extends": ["one", "two", "three"]
or maybe leave it as is and just merge all the presets with the same name with "later setting wins" as always.