CMakePresets.json and graphviz

Does anyone know if, and how, you can set the equivalent of a “–” command line option in a CMakePresets.json preset?

1 Like

Cc: @kyle.edwards

I don’t believe that option is present, no. We could add it.

It would be great to have this.
I added to my command line so
cmake --preset=VS16-x64
and it seemed to work. It did raise a question however which does not seem to be addressed in the documentation. What happens if I set something on the command line and in a preset. So i might have
cmake -T foo …
and have
“toolset”: { “value”: “bar” }
So do I get a toolset of foo or bar.
Obviously I can answer this by trying but I think it would be good to have a section in the documentation about command line versus preset settings.

Per the cmake(1) documentation:

The presets are read before all other command line options. The options specified by the preset (variables, generator, etc.) can all be overridden by manually specifying them on the command line. For example, if the preset sets a variable called MYVAR to 1, but the user sets it to 2 with a -D argument, the value 2 is preferred.

This same user-overridable behavior applies to all other command line options too.

Thanks for the explanation and a great feature.

It would great if that explanation could be added to the page. I for one didn’t think to look in the place you pointed to but had read the cmake-presets.7.html carefully. Maybe the cmake-presets.7.html could have a link to the other page.

The cmake-presets(7) manual page is a description of the JSON format. The format has multiple frontends, including the CMake CLI, the CMake GUI, Visual Studio, and the VSCode CMake Tools extension. I don’t believe the cmake-presets(7) manual page is the appropriate place to explain the behavior of the CLI, but I’m willing to hear other opinions on this.

Not sure I agree with "The cmake-presets(7) manual page is a description of the JSON format. ". I think most people would regard it as “where to go to learn how to use presets” which does include the JSON format but as a subset.

I agree. Just a note of how --preset interacts with other command line arguments would be nice in the Introduction section. I don’t think that every JSON field needs to mention the flag it goes with, but a general note (maybe with an example) would be useful.

I have create an issue to request the --graphviz feature in presets.