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] toolchain file: CMAKE_GENERATOR_PLATFORM regression in 1.36.0?

See original GitHub issue

Environment Details (include every applicable attribute)

  • Operating System+version: Windows 10
  • Compiler+version: Visual Studio 2019 + Ninja generator
  • Conan version: 1.36.0
  • Python version: 3.9.1

Steps to reproduce (Include if Applicable)

  • add a basic toolchain file in conanfile.py:

    from conans import ConanFile, tools
    from conan.tools.cmake import CMakeToolchain
    
    
    class TestConan(ConanFile):
    ...
        def generate(self):
            tc = CMakeToolchain(self)
            tc.generate()
    ...
    
  • install some external libraries with this conanfile:

      mkdir build
      cd build
      conan install .. -g cmake_find_package -g cmake_find_package_multi
    
  • call CMake on a basic top CMakeLists with this toochain file and Ninja generator: cmake .. -DCMAKE_TOOLCHAIN_FILE=<path to toolchaine file> -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Release -G Ninja

Logs (Executed commands with output) (Include/Attach if Applicable)

[cmake] Not searching for unused variables given on the command line.
[cmake] Using Conan toolchain through d:/projects/test/build/msvc2019_x64_x64_Release/conan_generators/conan_toolchain.cmake.
[cmake] CMake Error at CMakeLists.txt:2 (project):
[cmake]   Generator
[cmake] 
[cmake]     Ninja
[cmake] 
[cmake]   does not support platform specification, but platform
[cmake] 
[cmake]     x64
[cmake] 
[cmake]   was specified.
[cmake] 
[cmake] 
[cmake] CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
[cmake] CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
[cmake] -- Configuring incomplete, errors occurred!

This issue was fixed in 1.33.0 I think: https://github.com/conan-io/conan/issues/7485. At least It was working in conan 1.35

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
memshardedcommented, Apr 28, 2021

I understand, but it seems odd to have to hardcode generator in its conanfile based on a build system detail of consumers, it should work for all generator handled by CMake. It means that I can’t use toochain feature in an agnostic CMakeLists, and it forces all consumers to use Ninja. Maybe I miss the main use case of toolchain file.

Yes, I agree! This is the UX part that is missing at the moment. The key idea is that the generator needs to be know at install time, so it might be something like this:

$ conan install .. -c tools.cmake.cmaketoolchain:generator=Ninja
$ cmake .. -DCMAKE_TOOLCHAIN_FILE=<path to toolchaine file> ... -G Ninja

We still need to implement this, so at the moment the only way to define it is via the constructor of CMakeToolchain. We will try hard to provide this in next 1.37. The main problem is that there are few things that depend on the generator in the toolchain and generate() step:

  • The definition (or not) of the vcvars environment
  • Definition (or not) of the platform
  • Definition (or not) of the toolset, the compiler, and compiler version

So we needed to start introducing some changes, like the conanbuild.json file, which is kind of a CMake presets (but for 3.15), that contains some information like the CMake generator or the CMake toolchain file name, and generating the conanvcvars.bat file from CMakeToolchain.generate().

0reactions
memshardedcommented, May 27, 2021

https://github.com/conan-io/conan/pull/8899/files added Conan configuration for CMakeToolchain selection of CMake generator, which seems to be resolving this issue. This will be in 1.37.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[feature] [toolchain.cmake] Set platform and toolset only if ...
Use case: Using MSVC with Ninja as CMake Generator. It doesn't support PLATFORM and TOOLSET variables and errors out on them.
Read more >
cmake-toolchains(7) — CMake 3.25.1 Documentation
Introduction¶. CMake uses a toolchain of utilities to compile, link libraries and create archives, and other tasks to drive the build.
Read more >
Changelog — conan 1.36.0 documentation
It can be used as a CMake toolchain to perform a transparent CMake usage, without include any line of cmake code related to...
Read more >
CMake 3.21.0-rc2 is ready for testing - Kitware Inc.
The “Visual Studio 17 2022” generator was added. This is ... “cmake(1)” gained the “–toolchain <path/to/file>” command-line
Read more >
man page cmake-modules section 7
The module will accept files and libraries as well as separate ... <platform> Pass a generator-specific platform name to the CMake command ...
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