# CMakeWorkflowPresets: How to keep it as simple as possible?

**URL:** https://discourse.cmake.org/t/cmakeworkflowpresets-how-to-keep-it-as-simple-as-possible/8735
**Category:** Usage
**Created:** [August 15, 2023, 8:56am UTC](https://discourse.cmake.org/t/cmakeworkflowpresets-how-to-keep-it-as-simple-as-possible/8735 "2023-08-15T08:56:20Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [August 15, 2023, 8:56am UTC](https://discourse.cmake.org/t/cmakeworkflowpresets-how-to-keep-it-as-simple-as-possible/8735/1 "2023-08-15T08:56:20Z")

</div>

### I try to use CMake Presets with workflows, but without too many permutations.

So I decided to have only a `debug` and a `release` workflow.  
The user should be able to control the Compiler or Toolchain used.

```bash
bash-3.2$ cmake --list-presets
CMake Error: Could not read presets from /Users/clausklein/Workspace/cpp/cpp_vcpkg_project:
Inherited preset "ninja-multi-vcpkg" is unreachable from preset's file
bash-3.2$ mv CMakeUserPresets.json .CMakeUserPresets.json
bash-3.2$ cmake --list-presets
CMake Error: Could not read presets from /Users/clausklein/Workspace/cpp/cpp_vcpkg_project:
Invalid preset: "ninja-multi-vcpkg"
bash-3.2$ cmake --list-presets
Available configure presets:

  "gcc-debug" - gcc Debug
  "gcc-release" - gcc Release
  "clang-debug" - clang Debug
  "clang-release" - clang Release
  "debug" - Debug
  "release" - Release
bash-3.2$ 

```

#### How may I inherit from a user defined `configurePreset` as long the `CMakeUserPresets.json` does not exits?

```json
{
    "version": 6,
    "cmakeMinimumRequired": {
        "major": 3,
        "minor": 25,
        "patch": 0
    },
    "configurePresets": [
        {
            "name": "user-config",
            "description": "Example for user default settings that apply to all configurations",
            "generator": "Ninja",
            "cacheVariables": {
                "CMAKE_C_COMPILER": "clang",
                "CMAKE_CXX_COMPILER": "clang++"
            }
        }
    ]
}

```

CMakePresets.json

```json
{
    "version": 6,
    "cmakeMinimumRequired": {
        "major": 3,
        "minor": 25,
        "patch": 0
    },
    "configurePresets": [
        {
            "name": "CMakeUserPresets-config",
            "description": "Example for user default settings that apply to all configurations",
            "hidden": true,
            "generator": "Ninja",
            "cacheVariables": {
                "CMAKE_C_COMPILER": "clang",
                "CMAKE_CXX_COMPILER": "clang++"
            }
        },
        {
            "name": "ninja-multi-vcpkg",
            "displayName": "Ninja Multi-Config",
            "description": "Configure with vcpkg toolchain and generate Ninja project files for all configurations",
            "inherits": "CMakeUserPresets-config",
            "generator": "Ninja Multi-Config",
            "hidden": true,
            "cacheVariables": {
                "CMAKE_TOOLCHAIN_FILE": {
                    "type": "FILEPATH",
                    "value": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake"
                },
                "VCPKG_CHAINLOAD_TOOLCHAIN_FILE": {
                    "type": "FILEPATH",
                    "value": "${sourceDir}/toolchain/WindowsToolchain/Windows.MSVC.toolchain.cmake"
                }
            }
        },
        {
            "name": "common",
            "description": "Settings for all toolchains",
            "hidden": true,
            "inherits": "ninja-multi-vcpkg",
            "binaryDir": "${sourceDir}/build/${presetName}",
            "installDir": "${sourceDir}/install/${presetName}",
            "cacheVariables": {
                "ENABLE_CPPCHECK": false,
                "ENABLE_CLANG_TIDY": false
            },
            "vendor": {
                "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
                    "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
                }
            }
        },
        {
            "name": "debug",
            "displayName": "Debug",
            "description": "Debug build type",
            "inherits": "common",
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Debug",
                "FEATURE_TESTS": true
            }
        },
        {
            "name": "release",
            "displayName": "Release",
            "description": "Release build type",
            "inherits": "common",
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "RelWithDebInfo",
                "FEATURE_DOCS": true
            }
        }
    ],
    "testPresets": [
        {
            "name": "common",
            "description": "Test CMake settings that apply to all configurations",
            "hidden": true,
            "output": {
                "outputOnFailure": true
            },
            "execution": {
                "noTestsAction": "error",
                "stopOnFailure": true
            }
        },
        {
            "name": "debug",
            "displayName": "Strict",
            "description": "Enable output and stop on failure",
            "inherits": "common",
            "configuration": "Debug",
            "configurePreset": "debug"
        },
        {
            "name": "release",
            "displayName": "Strict",
            "description": "Enable output and stop on failure",
            "inherits": "common",
            "configuration": "RelWithDebInfo",
            "configurePreset": "release"
        }
    ],
    "buildPresets": [
       {
          "name": "release",
          "configurePreset": "release"
       },
       {
          "name": "install",
          "configurePreset": "release",
          "targets": ["install"]
       },
       {
          "name": "gen-docs",
          "configurePreset": "release",
          "targets": ["doxygen-docs"]
       },
       {
          "name": "debug",
          "configurePreset": "debug"
       }
    ],
    "packagePresets": [
       {
          "name": "release",
          "configurePreset": "release",
          "generators": [
             "TGZ"
          ]
       }
    ],
    "workflowPresets": [
      {
         "description": "Developer workflow without installation",
         "name": "debug",
         "steps": [
            {
               "type": "configure",
               "name": "debug"
            },
            {
               "type": "build",
               "name": "debug"
            },
            {
               "type": "test",
               "name": "debug"
            }
         ]
      },
      {
         "description": "Release workflow without test",
         "name" : "release",
         "steps" : [
            {
               "name" : "release",
               "type" : "configure"
            },
            {
               "name" : "release",
               "type" : "build"
            },
            {
               "name" : "release",
               "type" : "package"
            }
         ]
      }
   ]
}

```

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [August 15, 2023, 12:52pm UTC](https://discourse.cmake.org/t/cmakeworkflowpresets-how-to-keep-it-as-simple-as-possible/8735/2 "2023-08-15T12:52:08Z")

</div>

### with macro expansion in `inherits` entries it would work:

```diff
diff --git a/CMakeWorkflowPresets.json b/CMakeWorkflowPresets.json
index 4383e0e..eab1d55 100644
--- a/CMakeWorkflowPresets.json
+++ b/CMakeWorkflowPresets.json
@@ -1,26 +1,52 @@
 {
- "version": 6,
+ "version": 7,
     "cmakeMinimumRequired": {
         "major": 3,
- "minor": 25,
+ "minor": 27,
         "patch": 0
     },
     "configurePresets": [
         {
- "name": "CMakeUserPresets-config",
- "description": "Example for user default settings that apply to all configurations",
+ "name": "MSVC-config",
             "hidden": true,
             "generator": "Ninja",
+ "cacheVariables": {
+ "CMAKE_C_COMPILER": "cl",
+ "CMAKE_CXX_COMPILER": "cl",
+ "CMAKE_SYSTEM_PROCESSOR": "AMD64"
+ },
+ "environment": { "VARIANT": "MSVC" }
+ },
+ {
+ "name": "gcc-config",
+ "hidden": true,
+ "inherits": "MSVC-config",
+ "cacheVariables": {
+ "CMAKE_C_COMPILER": "gcc",
+ "CMAKE_CXX_COMPILER": "g++"
+ }
+ },
+ {
+ "name": "clang-config",
+ "hidden": true,
+ "inherits": "MSVC-config",
             "cacheVariables": {
                 "CMAKE_C_COMPILER": "clang",
                 "CMAKE_CXX_COMPILER": "clang++"
- }
+ },
+ "environment": { "VARIANT": "Clang" }
         },
         {
             "name": "ninja-multi-vcpkg",
             "displayName": "Ninja Multi-Config",
- "description": "Configure with vcpkg toolchain and generate Ninja project files for all configurations",
- "inherits": "CMakeUserPresets-config",
+ "description": "Configure with vcpkg toolchain and generate Ninja Multi-Config project files for all variants",
+ "vendor": {
+ "ClausKlein.de/CMake/1.0": {
+ "description": "FIXME: We need macro expansion here!",
+ "inherits": "$penv{CC}-config"
+ }
+ },
+ "inherits": "gcc-config",
             "generator": "Ninja Multi-Config",
             "hidden": true,
             "cacheVariables": {
@@ -30,7 +56,7 @@
                 },
                 "VCPKG_CHAINLOAD_TOOLCHAIN_FILE": {
                     "type": "FILEPATH",
- "value": "${sourceDir}/toolchain/WindowsToolchain/Windows.MSVC.toolchain.cmake"
+ "value": "${sourceDir}/toolchain/WindowsToolchain/Windows.$env{VARIANT}.toolchain.cmake"
                 }
             }
         },

```

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [August 15, 2023, 2:32pm UTC](https://discourse.cmake.org/t/cmakeworkflowpresets-how-to-keep-it-as-simple-as-possible/8735/3 "2023-08-15T14:32:58Z")

</div>

bash-3.2$ jsonschema -i CMakeWorkflowPresets.json -o pretty schema.json  
===[SUCCESS]===(CMakeWorkflowPresets.json)===  
bash-3.2$ CC=clang cmake --workflow --preset debug --fresh

### CMake Error: Could not read presets from /Users/clausklein/Workspace/cpp/cpp\_vcpkg\_project:

#### Invalid preset: “ninja-multi-vcpkg”

bash-3.2$ git diff  
diff --git a/CMakeWorkflowPresets.json b/CMakeWorkflowPresets.json

```diff
index eab1d55..9baf648 100644
--- a/CMakeWorkflowPresets.json
+++ b/CMakeWorkflowPresets.json
@@ -43,10 +43,10 @@
             "vendor": {
                 "ClausKlein.de/CMake/1.0": {
                     "description": "FIXME: We need macro expansion here!",
- "inherits": "$penv{CC}-config"
+ "inherits": "clang-config"
                 }
             },
- "inherits": "gcc-config",
+ "inherits": "$penv{CC}-config",
             "generator": "Ninja Multi-Config",
             "hidden": true,
             "cacheVariables": {

```

bash-3.2$

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [August 15, 2023, 2:37pm UTC](https://discourse.cmake.org/t/cmakeworkflowpresets-how-to-keep-it-as-simple-as-possible/8735/4 "2023-08-15T14:37:17Z")

</div>

@kyle.edwards  
Would or should it be possible to apply macros to `inherits` entries?

see too [CMakePresets: why not expand macros in name or inherits fields?](https://discourse.cmake.org/t/cmakepresets-why-not-expand-macros-in-name-or-inherits-fields/8747/1)

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [August 18, 2023, 12:23pm UTC](https://discourse.cmake.org/t/cmakeworkflowpresets-how-to-keep-it-as-simple-as-possible/8735/5 "2023-08-18T12:23:47Z")

</div>

see too [Organizing CMake presets](https://dominikberner.ch/cmake-presets-best-practices/)
