Avoid duplication of CMake config command line

We have to build for a lot of different OSes with lots of options (Rel/Dbg, SonarQube On/Off, Coverage On/Off…). The scripts to get the config command line are duplicated to:

  • yml (Azure-DevOps Build definition)
  • VS Code Settings (cmake-kits.json etc)
  • VS 2019 Settings (CMakeSettings.json)
  • bat/sh scripts

It is nearly impossible to keep those up to date. I also do not know how to make them look at “a single source of truth”.
This is a painful process and often result on “works on my machine” problems. How can I improve this?

You want CMakePresets.json.

1 Like

This is a nice but very new feature (v1 = 3.19), (v2 = 3.20), I doubt that this is supported everywhere I need it :frowning: Is there a list of supporting IDEs?

CMake itself supports it of course, as do Visual Studio and Visual Studio Code/VSCode. I know the JetBrains team was working on it for CLion, but it doesn’t look like they’ve finished it yet. In any case, you can always use the cmake command line tool to generate the build tree from a preset.

That being said, it looks like your use cases (VS, VSCode, CI, and local command line) are all fully supported. CI can be done by running cmake with a --preset argument.

Yes, this was just something I personally wanted to know :). Thank you for sharing thisinformation.

Btw: the links:

btw: Is this a type-o?


I cannot find penv anywhere else in the documentation and google results are inconclusive.

That’s definitely a typo.


Similar to $env{}, except that the value only comes from the parent environment, and never from the environment field. This allows you to prepend or append values to existing environment variables. For example, setting PATH to /path/to/ninja/bin:$penv{PATH} will prepend /path/to/ninja/bin to the PATH environment variable. This is needed because $env{} does not allow circular references.



Guess I was blind :see_no_evil::flushed:

@Kris_Malfettone I spoke way too soon.

Thanks for teaching me something new.