conan: [bug] CMakeToolchain generator fails if CMakePresets.json is already present but conan_toolchain.cmake is created

Environment details

  • Operating System+version: Windows 10 Pro 19045.2364
  • Conan version: 1.55.0
  • Python version: 3.10.8

Steps to reproduce

  1. Pick a CMake project with an existing CMakePresets.json
  2. Create a simple conanfile.txt like this:
    [requires]
    catch2/[>3.0]
    
    [generators]
    CMakeToolchain
    
  3. Run conan install .\conanfile.txt -pr:b=default
  4. 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'

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

I’ll check it tomorrow at work then!