question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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'

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
famastefanocommented, Dec 20, 2022

I’ll check it tomorrow at work then!

0reactions
memshardedcommented, Dec 21, 2022

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

CMakeToolchain — conan 1.53.0 documentation
The CMakeToolchain is the toolchain generator for CMake. It will generate toolchain files that can be used in the command line invocation of...
Read more >
Need a file which stores preset build options - GitLab
Visual Studio has a file called CMakeSettings.json which serves this ... creates a true environment variable, but now I'm wondering if I ...
Read more >
Conan package manager and CMakePresets.json? Is it ...
However, using presets, might not be necessary, as CMakeToolchain will generate a conan_toolchain.cmake file that can help with the integration ...
Read more >
CMake Presets integration in Visual Studio and Visual Studio ...
CMakePresets.json was released in CMake 3.19 and 3.20 and allows users to specify common configure, build, and test options and share them ...
Read more >
conan Changelog - pyup.io
Feature: The `CMakePreset.json` now contains `toolset` and `architecture` items when using `Ninja` generator and `msvc` compiler so the IDE (Visual Studio) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found