Description
Describe the bug
Hello,
When using CMakeToolchain.user_presets_path(...) and including the conan generated preset json in a CMakePresets, Conan seems to be generating dummy "conan-*" presets for the not installed build types. I assume this is so the inherits
inside "CMakePresets.json" will still resolve. However, the dummy buildPresets
are missing the configurePreset
attribute, and thus cmake --list-presets
and cmake --preset <>
fails with Invalid preset: "conan-*"
Note, running install for both Debug and Release fixes this issue but I would like to avoid on my CI pipeline.
Steps to reproduce, using attached conanfile.py and CMakePresets.json
OS: Mac 15.4.1 (24E263
❯ conan --version
Conan version 2.16.1
❯ cmake --version
cmake version 4.0.0
profile:
[settings]
arch=armv8
build_type=Debug
compiler=apple-clang
compiler.cppstd=gnu20
compiler.libcxx=libc++
compiler.version=16
os=Macos
Actual generated ConanPresets.json
{
"version": 4,
"vendor": {
"conan": {}
},
"configurePresets": [
{
"name": "conan-default"
},
{
"name": "conan-release"
}
],
"buildPresets": [
{
"name": "conan-release"
}
],
"include": [
"build/Debug/generators/CMakePresets.json"
]
}
Expected ConanPrests.json
{
"version": 4,
"vendor": {
"conan": {}
},
"configurePresets": [
{
"name": "conan-default"
},
{
"name": "conan-release"
}
],
"buildPresets": [
{
"name": "conan-release",
"configurePreset": "conan-release"
}
],
"include": [
"build/Debug/generators/CMakePresets.json"
]
}
configurePreset
An optional string specifying the name of a configure preset to associate with this build preset. If configurePreset is not specified, it must be inherited from the inherits preset (unless this preset is hidden). The build directory is inferred from the configure preset, so the build will take place in the same binaryDir that the configuration did.
How to reproduce it
Putting the Conanfile.py and CMakePresets.json in the same directory and running:
conan install .
cmake --list-presets
Conanfile.py:
from conan import ConanFile
from conan.tools.cmake import CMakeDeps, CMakeToolchain
from conan.tools.cmake import cmake_layout
class TestRecipe(ConanFile):
settings = "os", "compiler", "build_type", "arch"
def __init__(self, display_name="Test"):
super().__init__(display_name)
def layout(self):
cmake_layout(self)
def generate(self):
tc = CMakeToolchain(self)
tc.user_presets_path = "ConanPresets.json"
tc.generate()
make_deps = CMakeDeps(self)
make_deps.generate()
CMakePresets.json:
{
"version": 4,
"include": ["./ConanPresets.json"],
"configurePresets": [
{
"name": "default",
"displayName": "multi config",
"inherits": "conan-default"
},
{
"name": "release",
"displayName": "release single config",
"inherits": "conan-release"
},
{
"name": "debug",
"displayName": "debug single config",
"inherits": "conan-debug"
}
],
"buildPresets": [
{
"name": "multi-release",
"configurePreset": "default",
"configuration": "Release",
"inherits": "conan-release"
},
{
"name": "multi-debug",
"configurePreset": "default",
"configuration": "Debug",
"inherits": "conan-debug"
},
{
"name": "release",
"configurePreset": "release",
"configuration": "Release",
"inherits": "conan-release"
},
{
"name": "debug",
"configurePreset": "debug",
"configuration": "Debug",
"inherits": "conan-debug"
}
]
}