# CMake Invalid Preset

**URL:** https://discourse.cmake.org/t/cmake-invalid-preset/3538
**Category:** Code
**Created:** [June 9, 2021, 8:58am UTC](https://discourse.cmake.org/t/cmake-invalid-preset/3538 "2021-06-09T08:58:07Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![HackingPheasant](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hackingpheasant/32/1537_2.png) [@HackingPheasant](https://discourse.cmake.org/u/HackingPheasant)
#### Post date: [June 9, 2021, 8:58am UTC](https://discourse.cmake.org/t/cmake-invalid-preset/3538/1 "2021-06-09T08:58:07Z")

</div>

My first attempt at creating a CMakePrests.json, when trying to list my presets, I get an `invalid preset` warning.

I verified my preset validates against the scheme, so nothing obviously wrong jumps out at me, so any help to track down the issue is appreciated.

Validated Json: [Newtonsoft](https://www.jsonschemavalidator.net/s/qBO5hy21)

Output:

```
matt@thonkpad ~/src/personal/cpp_starter_template $ cmake . --list-presets
CMake Error: Could not read presets from /home/matt/src/personal/cpp_starter_template: Invalid preset
matt@thonkpad ~/src/personal/cpp_starter_template $ cmake . --trace --list-presets
Running with trace output on.
CMake Error: Could not read presets from /home/matt/src/personal/cpp_starter_template: Invalid preset
matt@thonkpad ~/src/personal/cpp_starter_template $ cmake . --debug-output --list-presets
Running with debug output on.
CMake Error: Could not read presets from /home/matt/src/personal/cpp_starter_template: Invalid preset
matt@thonkpad ~/src/personal/cpp_starter_template $ cmake --version
cmake version 3.20.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).
matt@thonkpad ~/src/personal/cpp_starter_template $ cat CMakePresets.json
{
    "version": 2,
    "cmakeMinimumRequired": {
        "major": 3,
        "minor": 20,
        "patch": 0
    },
    "configurePresets": [
        {
            "name": "base",
            "displayName": "Base",
            "description": "Base configuration",
            "hidden": true,
            "binaryDir": "${sourceDir}/build/${presetName}",
            "cacheVariables": {
                "CMAKE_EXPORT_COMPILE_COMMANDS" : "ON"
            }
        },
        {
            "inherits": "base",
            "name": "debug",
            "displayName": "Debug",
            "description": "Build as Debug",
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Debug"
            }
        },
        {
            "inherits": [
                "base",
                "debug"
            ],
            "name": "dev",
            "displayName": "Developer",
            "description": "Build as Debug, with warnings enabled.",
            "cacheVariables": {
                "ENABLE_WARNINGS": "TRUE"
            },
            "warnings": {
                "dev": true,
                "deprecated": true,
                "uninitialized": true,
                "systemVars": true
            },
            "errors": {
                "dev": true,
                "deprecated": true
            }
        },
        {
            "inherits": "base",
            "name": "release",
            "displayName": "Release",
            "description": "Build as Release",
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Release"
            }
        },
        {
            "inherits": [
                "base",
                "release"
            ],
            "name": "release-static-libs",
            "displayName": "Release (Static libs)",
            "description": "Build as Release, forcing static built libraries",
            "cacheVariables": {
                "BUILD_SHARED_LIBS": "OFF"
            }
        },
        {
            "inherits": [
                "base",
                "release"
            ],
            "name": "release-shared-libs",
            "displayName": "Release (Shared libs)",
            "description": "Build as Release, forcing shared built libraries",
            "cacheVariables": {
                "BUILD_SHARED_LIBS": "ON"
            }
        },
        {
            "inherits": "base",
            "name": "relwithdebinfo",
            "displayName": "RelWithDebInfo",
            "description": "Build as Release with Debug Info",
            "binaryDir": "${sourceDir}/build/${presetName}",
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "RelWithDebInfo"
            }
        },
        {
            "inherits": "base",
            "name": "minsizerel",
            "displayName": "MinSizeRel",
            "description": "Build as Release, optimizing for size",
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "MinSizeRel"
            }
        }
    ],
    "buildPresets": [
        {
            "name": "debug",
            "configurePreset": "debug",
            "jobs": 4
        },
        {
            "name": "dev",
            "configurePreset": "dev",
            "jobs": 4
        },
        {
            "name": "release",
            "configurePreset": "release",
            "jobs": 4
        },
        {
            "name": "release-static-libs",
            "configurePreset": "release-static-libs",
            "jobs": 4
        },
        {
            "name": "release-shared-libs",
            "configurePreset": "release-shared-libs",
            "jobs": 4
        },
        {
            "name": "relwithdebinfo",
            "configurePreset": "relwithdebinfo",
            "jobs": 4
        },
        {
            "name": "minsizerel",
            "configurePreset": "minsizerel",
            "jobs": 4
        }

    ],
    "testPresets": [
    ]
}
```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 9, 2021, 10:25am UTC](https://discourse.cmake.org/t/cmake-invalid-preset/3538/2 "2021-06-09T10:25:40Z")

</div>

@kyle.edwards

---

<div class="post-metadata">

### Author: ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)
#### Post date: [June 9, 2021, 1:22pm UTC](https://discourse.cmake.org/t/cmake-invalid-preset/3538/3 "2021-06-09T13:22:18Z")

</div>

You need to set a `generator` in your `base` preset.

`binaryDir` and `generator` will both be optional in version `3` of the preset file (upcoming in CMake 3.21), but in version `2` they are still required.

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [June 9, 2021, 8:58pm UTC](https://discourse.cmake.org/t/cmake-invalid-preset/3538/4 "2021-06-09T20:58:45Z")

</div>

FYI, the reason more specific preset error feedback isn’t given is due to the complexity of implementing this: [https://gitlab.kitware.com/cmake/cmake/-/issues/21310](https://gitlab.kitware.com/cmake/cmake/-/issues/21310)

---

<div class="post-metadata">

### Author: ![HackingPheasant](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hackingpheasant/32/1537_2.png) [@HackingPheasant](https://discourse.cmake.org/u/HackingPheasant)
#### Post date: [June 10, 2021, 8:18am UTC](https://discourse.cmake.org/t/cmake-invalid-preset/3538/5 "2021-06-10T08:18:00Z")

</div>

That does indeed solve the issue! Thanks for the help.

I assumed it was optional because of the following line in the [docs](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html#configure-preset)

> An optional string representing the generator to use for the preset.

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [June 10, 2021, 2:20pm UTC](https://discourse.cmake.org/t/cmake-invalid-preset/3538/6 "2021-06-10T14:20:17Z")

</div>

“An optional string representing the generator to use for the preset. **If `generator` is not specified, it must be inherited from the `inherits` preset (unless this preset is `hidden`).**”

Yeah that doc makes it sound optional. Until you read the second sentence. Which I agree is somewhat confusing.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 11, 2021, 11:31am UTC](https://discourse.cmake.org/t/cmake-invalid-preset/3538/7 "2021-06-11T11:31:19Z")

</div>

> [@anon45792294](#):
>
> “A string representing the generator to use for the preset. If `generator` is not specified, it must be inherited from the `inherits` preset (unless this preset is `hidden`).”

I think just removing `optional` is the way to go here.

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [June 11, 2021, 4:31pm UTC](https://discourse.cmake.org/t/cmake-invalid-preset/3538/8 "2021-06-11T16:31:19Z")

</div>

I think version 3 of presets ( CMake 3.21) is going to indeed have generator be optional without need to inherit it–CMake will default to its legacy generator preferences.
