CMake 3.19 CMakePresets.json user stories

I am curious, what are some of the intended use cases for CMakePresets.json that’s new for CMake 3.19. Is for Visual Studio / IDE users to avoid a lot of set() statements in CMakeLists.txt? Say one has 2 or 3 common use cases and CMakePresets.json avoids a lot of set() and/or a lot of cmake -D options?

The presets files allow you to define a commonly used set of cache options and other things that would normally only be settable on the cmake command line the first time it is run for a build. It can encapsulate selection of the generator, build directory location, various debugging options, etc.

While the Visual Studio IDE is the obvious place where these presets files will be useful, they could also be helpful for conveniently defining CI build options or just setups that developers frequently use between projects. I have just opened a few preset-related issues in gitlab for problems exposed with 3.19.0-rc1 for some of these use cases. You might choose to set up things for a variety of different generators for example (e.g. with Xcode you might use it to set some code signing options).

BTW the presets can also be selected in cmake-gui (once some bugs are fixed). That is another way that presets simplify the life of developers working with a project for the first time.

Lastly, there are two presets files. One is meant for the project to define (CMakePresets.json), the other is for user-provided presets (CMakeUserPresets.json). These represent the two main categories of use cases and target different scenarios.

1 Like