Feature requests for presets

I love CMake. The new presets feature is really powerful, and super helpful, but I still use a small Makefile wrapping commonly used cmake commands and doing a couple of configuration things that as of now aren’t possible with just native CMake code.

There are a couple of features I think could be added to CMake presets that would almost entirely mitigate the need for any external “wrapping” scripts or tools:

  1. Conditional values – short-circuiting sets of possible values for environment variables, and possibly other fields. I’m imagining something like this:
"configurePresets": [
    {
      "name": "base",
      "hidden": true,
      "generator": [
        {
          "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Darwin" },
          "value": "Xcode"
        },
        {
          "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Windows" },
          "value": "Visual Studio 16 2019"
        }
        {
          "condition": "default",
          "value": "Ninja"
        }
      ]
    }
]

If this would only be possible for setting environment variables, then I would also love the generator field to allow macro expansion, because my personal use case of this feature would be setting the generator, like is shown above.

  1. Command presets – saved sets of calls to either cmake -E or cmake -P, for example:
"commandPresets": [
    {
      "name": "myScript",
      "type": "script",
      "script": "${sourceDir}/scripts/myScript.cmake",
      "environmentVariables": {
        "input1": "someData"
      },
      "workingDirectory": "${sourceDir}"
    },
    {
      "name": "myCommand",
      "type": "command",
      "command": "make_directory",
      "arguments": "${sourceDir}/Builds"
    }
  ]
  1. It would be really helpful to have a presets macro that expands to the number of processors/cores on the current machine, I would use it like so:
"buildPresets": [
    {
      "name": "base",
      "hidden": true,
      "jobs": "${numCores}"
    }
  ]
  1. Options in build and configure presets for writing the output to a file (similar to what’s available for test presets, akin to calling cmake ... | tee myLog.log)

Thanks for your consideration! :slightly_smiling_face:

We already have a “condition”:“…” field that can be used to filter out available presets upon cmake --[list-]prests invocation. I think it can help one to specify generator.

Presets are quite complex enough for new complicated features like that I would say.

Cc: @kyle.edwards