CMake Invalid Preset

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

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": [
    ]
}

@kyle.edwards

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.

1 Like

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

1 Like

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

I assumed it was optional because of the following line in the docs

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

“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.

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

1 Like

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.