cmake 预设配置:预设无效

cmake preset configuration: invalid preset

尝试 CMake 预设,遇到了第一个障碍。

我的 CMakeLists.txt

旁边有这个简单的“CMakePresets.json”
{
  "version": 2,
  "configurePresets": [
    {
      "name": "simple",
      "displayName": "simple"
    }
  ],
  "buildPresets": [
    {
      "name": "dev",
      "configurePreset": "simple"
    }
  ]
}

这是我很简单的CMakeLists.txt

cmake_minimum_required(VERSION 3.21.1)

project(hello)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
# I want these supplied by the presets
# with QTDIR in the user specific presets
# as these will differ from dev person to
# dev person
# ------------------------------------
# set(CMAKE_AUTOMOC ON)
# set(CMAKE_AUTOUIC ON)
# set(CMAKE_CXX_STANDARD 17)
# set(CMAKE_CXX_STANDARD_REQUIRED ON)
# set(CMAKE_PREFIX_PATH $ENV{QTDIR})

find_package(Qt6 REQUIRED COMPONENTS Quick)

qt_add_executable(${PROJECT_NAME}
    main.cpp
)

target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Quick)

qt_add_qml_module(${PROJECT_NAME}
    URI qml
    VERSION 1.0
    QML_FILES main.qml)

然后我(在干净的设置上)运行

mkdir build
cd build
cmake .. --preset=dev

但我总是得到以下错误

CMake Error: Could not read presets from /home/.../cmake/simple: Invalid preset

如果我尝试

,我会收到相同的消息
cmake .. --list-presets

我必须错误地调用 cmake,或者我的 JSON.

有问题

谁能指出我的错误?

例如: CMakePresets.json 中的预设名称是否需要与 CMakeLists.txt 中的项目名称匹配? 请记住,CMakeLists.txt 可以构建多个目标。

在版本 3 之前,配置预设 要求 具有字段 generatorbinaryDir。来自 documentation:

generator

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). In version 3 or above, this field may be omitted to fall back to regular generator discovery procedure.

binaryDir

An optional string representing the path to the output binary directory. This field supports macro expansion. If a relative path is specified, it is calculated relative to the source directory. If binaryDir is not specified, it must be inherited from the inherits preset (unless this preset is hidden). In version 3 or above, this field may be omitted.

另见 https://discourse.cmake.org/t/cmake-invalid-preset/3538