CMake -C vs --preset

What is the different between the -C (“Pre-load a script to populate the cache.”) and --preset (CMakePresets.json)?

It looks like cmake-presets has more options beyond just adjusting the cache like the -C option.

Should newer projects that support a version of CMake supporting CMakePresets.json choose the preset route?

It might be interesting to know which file (-C or --preset cache options) will take precedence too.

The -C argument script is read in as a CMake script. I think only cache variables “survive” (local variables disappear), but there is support for if and such things. I think if --preset works for you, use it (the cases I’ve run into, a cache script was easier to manage, but I wouldn’t count my usage patterns on this end “normal”[1]).


[1] Just as an example, vim is my cache editor…

Thanks for the input. On my project we are already leverage a VS Code CMake Tools extension, which added the ability to have cmake-kits.

It looks like CMakePresets has obsoleted this kit functionality (and the extension supports presets too). In my situation, I just wanted to avoid having to add the CACHE variable I care about to N number of kits. Presets support this because I could’ve inherited from a default preset. However, we don’t have the time to switch over to CMakePresets right now. So I’ll likely keep leveraging our “kits” and use the default cache file for my particular need.