In my CI scripts, the steps are typically the same on all OSes. Usually the only difference is the CMake preset being used, so I typically end up with something like this (assuming that the configure, build, test, and package presets all have the same name):
- name: configure
run: cmake --preset $CMAKE_PRESET
- name: build
run: cmake --build --preset $CMAKE_PRESET
- name: test
run: ctest --preset $CMAKE_PRESET
- name: package
run: cpack --preset $CMAKE_PRESET
I would love a way to encode in the CMakePresets.json some logic for selecting what CMake preset to use. I have several ideas for how this could work:
- A simple map with a list of OS names matched to preset names, ie:
{
"configurePresets": [
{ "name": "msvc", ... },
{ "name": "xcode", ... },
{ "name": "gcc", ... }
],
"defaultPresets": {
"configure": {
"Windows": "msvc",
"Darwin": "xcode",
"Linux": "gcc"
}
}
}
- A list of preset names paired with conditions, and the first condition that is satisfied will be selected. The last item in the list would not have a condition object, and would be considered the fallback default - ie:
{
"defaultPresets": {
"configure": [
{
"name": "msvc",
"condition": {
"lhs": "${hostSystemName}",
"rhs": "Windows",
"type": "equals"
}
},
{
"name": "xcode",
"condition": {
"lhs": "Darwin",
"rhs": "${hostSystemName}",
"type": "equals"
}
},
{ "name": "gcc" }
]
}
}
As for command line usage, I’m thinking either:
- call cmake with the special token
default
as the preset name - call
cmake --preset
with no name specified
It would also be great if cmake --list-presets
could indicate which preset is the default for your current platform.
I wanted to post this here before making an official FR on the issue tracker, to see what the community feedback is.