[bug] CMakeToolchain generator fails if CMakePresets.json is already present but conan_toolchain.cmake is created
See original GitHub issueEnvironment details
- Operating System+version:
Windows 10 Pro 19045.2364
- Conan version:
1.55.0
- Python version:
3.10.8
Steps to reproduce
- Pick a CMake project with an existing
CMakePresets.json
- Create a simple
conanfile.txt
like this:[requires] catch2/[>3.0] [generators] CMakeToolchain
- Run
conan install .\conanfile.txt -pr:b=default
conan_toolchain.cmake
will be generated but it’s unusable, and the error shown in the logs is displayed
Context
I’m migrating multiple CMake projects, from vcpkg to conan. Some of them are dependencies (libraries) that will be distributed as packages, internally, to easily integrate them in other projects (after all, that’s what conan and vcpkg are about). With vcpkg I simply had to include their toolchain file, but with conan it has to be generated. Nothing wrong with that, but it shouldn’t fail to do so if the presets are already present. Not to mention that the generated presets are “useless”, as they don’t add nothing specific other than the binary dir and the toolchain file itself, that I can manage to add myself.
Expected behaviour
The toolchain file is still created successfully and it’s ready to be integrated into CMake. The CMakePresets.json shall not be generated if already present.
P.S. If necessary, I might consider doing a pull request in my free time.
Logs
> conan install .\conanfile.txt -pr:b=default
Configuration (profile_host):
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=Visual Studio
compiler.runtime=MD
compiler.version=17
os=Windows
os_build=Windows
[options]
[build_requires]
[env]
Configuration (profile_build):
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=Visual Studio
compiler.runtime=MD
compiler.version=17
os=Windows
os_build=Windows
[options]
[build_requires]
[env]
Version ranges solved
Version range '>3.0' required by 'conanfile.txt' resolved to 'catch2/3.2.1' in local cache
conanfile.txt: Installing package
Requirements
catch2/3.2.1 from 'conancenter' - Cache
Packages
catch2/3.2.1:74897d1c583e671b507cd59f9d9d5677e74b413e - Cache
Installing (downloading, building) binaries...
catch2/3.2.1: Already installed!
conanfile.txt: Generator txt created conanbuildinfo.txt
conanfile.txt: Generator 'CMakeToolchain' calling 'generate()'
conanfile.txt: ERROR: Traceback (most recent call last):
File "conans\client\generators\__init__.py", line 187, in write_generators
File "conan\tools\cmake\toolchain\toolchain.py", line 200, in generate
File "conan\tools\cmake\presets.py", line 171, in write_cmake_presets
KeyError: 'buildPresets'
ERROR: Error in generator 'CMakeToolchain': 'buildPresets'
Issue Analytics
- State:
- Created 9 months ago
- Comments:17 (9 by maintainers)
I’ll check it tomorrow at work then!
It happens that is a quite challenging error to report, because the resolution is on the CMake side, and its mapping of configurations, so the installation of dependencies is managed by Conan, and Conan can do the right thing, but when CMake runs, Conan tries to be as transparent as possible, the only possibility would be the toolchain, but also the CMAKE_BUILD_TYPE directly do not exist at configure time for VS, so it can only be used inside generator expressions, so it cannot be checked at all by the toolchain.
We are investigating the possibility of a new implementation for
CMakeDeps
that might help identifying this issue, but I think in the meantime it is not worth the effort, so I am closing it.Thanks again for all the feedback!