Workflow Presets: We need support for macro expansion in inherits field

As duplicate preset names with unique conditon are not supported,
do we needs at least macro expansion in inherits fields:

    {
      "name": "dev",
      "displayName": "Ninja developer build with coverage",
      "inherits": ["dev-coverage", "dev-${hostSystemName}"]
    }

The full example CMakeUserPrests.json:

{
  "version": 6,
  "configurePresets": [
    {
      "name": "dev-common",
      "hidden": true,
      "inherits": ["dev-mode", "conan"],
      "generator": "Ninja",
      "installDir": "${sourceDir}/stagedir",
      "cacheVariables": {
        "BUILD_MCSS_DOCS": "OFF",
        "CMAKE_PREFIX_PATH": {
          "type": "path",
          "value": "${sourceDir}/stagedir"
        }
      }
    },
    {
      "name": "dev-coverage",
      "hidden": true,
      "binaryDir": "${sourceDir}/build/coverage",
      "inherits": ["coverage-unix", "dev-common"]
    },
    {
      "name": "dev-Linux",
      "binaryDir": "${sourceDir}/build/dev-linux",
      "inherits": ["dev-common", "ci-linux"],
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Debug",
        "CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
      },
      "condition": {
          "type": "equals",
          "lhs": "${hostSystemName}",
          "rhs": "Linux"
      }
    },
    {
      "name": "dev-Darwin",
      "binaryDir": "${sourceDir}/build/dev-darwin",
      "inherits": ["dev-common", "ci-darwin"],
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Debug",
        "CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
      },
      "condition": {
          "type": "equals",
          "lhs": "${hostSystemName}",
          "rhs": "Darwin"
      }
    },
    {
      "name": "dev-Windows",
      "binaryDir": "${sourceDir}/build/dev-win64",
      "inherits": ["dev-common", "ci-win64"],
      "environment": {
        "UseMultiToolTask": "true",
        "EnforceProcessCountAcrossBuilds": "true"
      },
      "condition": {
          "type": "equals",
          "lhs": "${hostSystemName}",
          "rhs": "Windows"
      }
    },
    {
      "name": "dev",
      "displayName": "Ninja developer build with coverage",
      "inherits": ["dev-coverage", "dev-${hostSystemName}"]
    }
  ],
  "buildPresets": [
    {
      "name": "dev",
      "configurePreset": "dev",
      "configuration": "Debug"
    },
    {
      "name": "all",
      "configurePreset": "dev",
      "configuration": "Debug",
      "targets": ["all", "format-fix"]
    },
    {
      "name": "check",
      "configurePreset": "dev",
      "configuration": "Debug",
      "targets": ["test", "run-exe", "install", "spell-check"]
    }
  ],
  "testPresets": [
    {
      "name": "dev",
      "configurePreset": "dev",
      "configuration": "Debug",
      "output": {
        "outputOnFailure": true
      },
      "execution": {
        "noTestsAction": "error"
      }
    }
  ],
  "workflowPresets": [
    {
      "name": "dev",
      "steps": [
        {
          "type": "configure",
          "name": "dev"
        },
        {
          "type": "build",
          "name": "all"
        },
        {
          "type": "build",
          "name": "check"
        },
        {
          "type": "test",
          "name": "dev"
        }
      ]
    }
  ]
}

Cc: @kyle.edwards

I have a lot of preset item open without a real reaction from @kyle.edwards ?

He authored much of the feature; I don’t use them and don’t have a lot of knowledge about it. I don’t know his schedule for Discourse things, but the mention should get it more onto his radar.

Starting with CMake v3.30 this workaround exists.

I have this preset files:
CMakeDarwinPresets.json

CMakeGenericPresets.json

CMakeLinuxPresets.json

CMakePresets.json

CMakeWindowsPresets.json

{
  "version": 9,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 30,
    "patch": 0
  },
  "include": [
    "CMake${hostSystemName}Presets.json"
  ],
  "configurePresets": [
    {
      "name": "dev",
      "displayName": "developer Ninja build on unix with Coverage",
      "description": "NOTE: coverage must be the first to overwrite Release build! CK",
      "inherits": [
        "ci-coverage",
        "doxygen"
      ],
      "generator": "Ninja"
    }
  ],
  "buildPresets": [
    {
      "name": "dev",
      "configurePreset": "dev",
      "configuration": "Coverage",
      "targets": [
        "all"
      ]
    }
  ],
  "testPresets": [
    {
      "name": "dev",
      "configurePreset": "dev",
      "configuration": "Coverage",
      "output": {
        "outputOnFailure": true
      }
    }
  ],
  "workflowPresets": [
    {
      "name": "dev",
      "steps": [
        {
          "type": "configure",
          "name": "dev"
        },
        {
          "type": "build",
          "name": "dev"
        },
        {
          "type": "test",
          "name": "dev"
        }
      ]
    }
  ]
}

with a CMakeDarwinPresets.json

{
  "version": 4,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 23,
    "patch": 0
  },
  "include": [
    "CMakeGenericPresets.json"
  ],
  "configurePresets": [
    {
      "name": "flags-appleclang",
      "hidden": true,
      "cacheVariables": {
        "CMAKE_CXX_FLAGS": "-fstack-protector-strong -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast"
      }
    },
    {
      "name": "ci-darwin",
      "generator": "Unix Makefiles",
      "hidden": true,
      "inherits": [
        "flags-appleclang",
        "ci-std"
      ],
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Release"
      }
    },
    {
      "name": "coverage-darwin",
      "binaryDir": "${sourceDir}/build/coverage",
      "inherits": "ci-darwin",
      "hidden": true,
      "cacheVariables": {
        "ENABLE_COVERAGE": true,
        "CMAKE_BUILD_TYPE": "Coverage",
        "CMAKE_CXX_FLAGS_COVERAGE": "-Og -g --coverage",
        "CMAKE_EXE_LINKER_FLAGS_COVERAGE": "--coverage",
        "CMAKE_SHARED_LINKER_FLAGS_COVERAGE": "--coverage"
      }
    },
    {
      "name": "ci-coverage",
      "inherits": [
        "coverage-darwin",
        "dev-mode"
      ],
      "cacheVariables": {
        "COVERAGE_HTML_COMMAND": ""
      }
    },
    {
      "name": "ci-sanitize",
      "binaryDir": "${sourceDir}/build/sanitize",
      "inherits": [
        "ci-darwin",
        "dev-mode"
      ],
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Sanitize",
        "CMAKE_CXX_FLAGS_SANITIZE": "-U_FORTIFY_SOURCE -O2 -g -fsanitize=address,undefined -fno-omit-frame-pointer -fno-common"
      }
    },
    {
      "name": "ci-Darwin",
      "inherits": [
        "ci-build",
        "ci-darwin",
        "clang-tidy",
        "dev-mode"
      ]
    },
    {
      "name": "ci-macos",
      "inherits": "ci-Darwin"
    }
  ]
}

and a CMakeGenericPresets.json

{
  "version": 3,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 21,
    "patch": 0
  },
  "configurePresets": [
    {
      "name": "cmake-pedantic",
      "hidden": true,
      "warnings": {
        "dev": true,
        "deprecated": true,
        "uninitialized": true,
        "unusedCli": true,
        "systemVars": false
      },
      "errors": {
        "dev": true,
        "deprecated": true
      }
    },
    {
      "name": "dev-mode",
      "hidden": true,
      "inherits": "cmake-pedantic",
      "installDir": "${sourceDir}/stagedir",
      "cacheVariables": {
        "CMAKE_PREFIX_PATH": {
          "type": "path",
          "value": "${sourceDir}/stagedir"
        },
        "shared_DEVELOPER_MODE": true,
        "CMAKE_EXPORT_COMPILE_COMMANDS": true,
        "BUILD_SHARED_LIBS": true,
        "BUILD_TESTING": true
      }
    },
    {
      "name": "doxygen",
      "hidden": true,
      "cacheVariables": {
        "BUILD_MCSS_DOCS": true
      }
    },
    {
      "name": "cppcheck",
      "hidden": true,
      "cacheVariables": {
        "CMAKE_CXX_CPPCHECK": "cppcheck;--inline-suppr"
      }
    },
    {
      "name": "clang-tidy",
      "hidden": true,
      "cacheVariables": {
        "CMAKE_CXX_CLANG_TIDY": "clang-tidy;--header-filter=^${sourceDir}/"
      }
    },
    {
      "name": "ci-std",
      "description": "This preset makes sure the project actually builds with at least the specified standard",
      "hidden": true,
      "cacheVariables": {
        "CMAKE_CXX_EXTENSIONS": false,
        "CMAKE_CXX_STANDARD": "20",
        "CMAKE_CXX_STANDARD_REQUIRED": true
      }
    },
    {
      "name": "ci-build",
      "binaryDir": "${sourceDir}/build",
      "hidden": true
    }
  ]
}

Thank you!!!
I’m waiting for the Ubuntu repository to update

Don’t wait! Do
pip install -U ninja cmake

Is it possible to use $env{VAR} for “name” and “displayName”. For example, I need several configurations to build different versions of SFML, which differ only in the version prefix in the source file paths and in “CMAKE_INSTALL_PREFIX”.
I tried to set “environment”: {“VER”:“2.6.0”}, but “displayName” is displayed as “SFML $env{VAR} MinGw x64: Release”.

See CMake presets issue - #6 by craig.scott