Reputation: 451
Trying out CMake presets, falling at one of the very first hurdles.
I have this simple "CMakePresets.json" alongside my CMakeLists.txt
{
"version": 2,
"configurePresets": [
{
"name": "simple",
"displayName": "simple"
}
],
"buildPresets": [
{
"name": "dev",
"configurePreset": "simple"
}
]
}
This is my very 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)
I then (on a clean setup) run
mkdir build
cd build
cmake .. --preset=dev
But I always get the following error
CMake Error: Could not read presets from /home/.../cmake/simple: Invalid preset
I get the same message if I try
cmake .. --list-presets
I either must be invoking cmake
incorrectly, or there is something wrong with my JSON.
Can someone point out my mistake?
For instance: Does the preset name from the CMakePresets.json need to match the project name in the CMakeLists.txt? Keeping in mind that a CMakeLists.txt can build multiple targets.
Upvotes: 0
Views: 10737
Reputation: 65870
Before version 3
a configure preset requires to have fields generator
and binaryDir
. From the documentation:
generator
An optional string representing the generator to use for the preset. If
generator
is not specified, it must be inherited from theinherits
preset (unless this preset ishidden
). 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 theinherits
preset (unless this preset ishidden
). In version 3 or above, this field may be omitted.
See also https://discourse.cmake.org/t/cmake-invalid-preset/3538.
Upvotes: 3