I am looking for a good example of CMakePresets.json file used for building with Visual Studio. Can anybody please share theirs?
P.S. I did search online, but, only found some toy preset files and not any corresponding to serious software projects.
Not sure if that’s what you are looking for, but here is one I’ve written and which works with multi-config generators like VS. This presets file includes another one in the parent directory which contains more stuff, but in most situation you’d probably want to only have one.
Thanks! Do the build presets appear as choices for you in Visual Studio GUI? For me, they don’t.
I just now placed your CMakePresets.json in my folder and I still don’t see any drop-down list or anything like that on the Visual Studio 2022 GUI that would let me select the build preset to use.
I don’t usually open the created Visual Studio projects (the logs are usually enough in my use-cases), and I tend to set the build type and/or build config on the command-line or with environment variable, so I can’t give a definite answer. However, I’ve just found this SO answer that seems to refer to what you’re talking about. Let me know whether that answers your question.
What I had already tried was something similar to what is suggested in that stack overflow response, i.e. I had added some buildPresets and I had also set the “configuration” field of those buildPresets. I would have now expected the buildPresets to show up as a drop-down list (or something similar) on the GUI. But, they don’t.
Maybe there’s a misunderstanding. With Visual Studio you have two distinct choices:
- Let CMake create a solution. This generator offers configurations like Release and Debug in the IDE, nothing more.
- Open the preset json file from the IDE. This let’s you choose from the presets that are usually done with ninja single configuration generator.
I am not explicitly asking Visual Studio to create a solution. As suggested on Visual Studio’s web page, I am using the “Open a local folder” option and choosing the folder containing the root CMakeLists.txt file and CMakePresets.json file.
This has been working fine when I had only “configurePresets” in the presets file (no buildPresets). That is, the different configure presets used to show up as a drop down list in the GUI.
Then, I felt a need to add buildPresets to the file. When I did that, neither the configurePresets nor the buildPresets show up in the GUI.
CMakePresets.json file has an error somewhere. From a command line, try running
cmake --list-presets=all. If that works, then I’d be filing a bug with the Visual Studio folks.
Indeed, there was an error in the presets file. The configuration preset referenced in a buildPreset didn’t exist because of a name mismatch due to a typo.
Weirdly, Visual Studio was not showing any message about there being an error. But, running the “cmake --list-presets=all” command you suggested indicated the error.