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.

[question] Can CMakeToolchain tell CMake the correct compilers?

See original GitHub issue

My understanding of the new CMakeToolchain’s purpose was that it can also be used to guarantee that CMake uses the correct compiler versions. However, that doesn’t seem to be the case?

See the examples below. As I understand so far, the user is responsible for selecting the correct compiler when using CMake? Is there a way to force CMake to use the correct compiler that has been defined in the conan profile or is that not in scope of the CMakeToolchain generator?

Linux example

I have a gcc10 profile (with CC/CXX environment variables). As you can see, CMake uses the (default) GCC 11 compiler instead of GCC 10, which has been defined in the conan profile.

$ cat ~/.conan/profiles/gcc10
[settings]
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=10
compiler.libcxx=libstdc++11
[options]
[build_requires]
[env]
CC=gcc-10
CXX=g++-10

$ conan install -s build_type=Debug -pr gcc10 .
$ cmake --preset debug ../..
Preset CMake variables:

  CMAKE_BUILD_TYPE="Debug"
  CMAKE_POLICY_DEFAULT_CMP0091="NEW"
  CMAKE_TOOLCHAIN_FILE:FILEPATH="/home/fschoenm/devel/project/build/generators/conan_toolchain.cmake"

-- Using Conan toolchain: /home/fschoenm/devel/project/build/generators/conan_toolchain.cmake
-- The CXX compiler identification is GNU 11.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
    ...

Windows example

Same issue here: CMake doesn’t know about the compiler specified in the conan toolchain. In my IDE (e.g. CLion) the compiler that was selected in the IDE is used instead of the one specified in the conan install call.

> conan install . -pr msvc193 -s build_type=Debug
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=msvc
compiler.cppstd=20
compiler.runtime=dynamic
compiler.runtime_type=Debug
compiler.version=193
os=Windows
os_build=Windows
[options]
[build_requires]
[env]
[conf]
tools.cmake.cmaketoolchain.presets:max_schema_version=3
tools.cmake.cmaketoolchain:generator=Ninja

...

> cmake --preset debug
Preset CMake variables:

  CMAKE_BUILD_TYPE="Debug"
  CMAKE_POLICY_DEFAULT_CMP0091="NEW"
  CMAKE_TOOLCHAIN_FILE="C:\devel\project\cmake-build\generators\conan_toolchain.cmake"

-- Using Conan toolchain: C:/devel/project/cmake-build/generators/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 20 with extensions OFF
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:20 (project):
  The CMAKE_CXX_COMPILER:

    cl

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fschoenmcommented, Nov 24, 2022

Looks fine to me. Thanks for spending the effort!

0reactions
memshardedcommented, Nov 24, 2022

Hi @fschoenm

We have added in https://github.com/conan-io/conan/pull/12556, for 1.55 the possibility to explicitly tell the compilers to CMake (not only CMake, but also other build systems as well), via a new tools.build:compiler_executables configuration.

I think this PR will solve this request, could you please have a look and confirm? Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to specify the compiler with CMake
After CMake detects what compilers to use, it saves them in the CMakeCache.txt file so that it can still generate proper build systems...
Read more >
Cross Compiling With CMake
In order to use CMake for cross-compiling, a CMake file that describes the target platform has to be created, called the “toolchain file,”...
Read more >
Integrated Development Environment e² studio
Compiler Package for RX Family (CC-RX) using CMake on a Windows host PC. Contents. 1. Overview . ... 4.1 CMake Toolchain file for...
Read more >
CMake Integration
To use a header-only library you can use find_path() which will correctly work on ... add the path to the vcpkg toolchain file...
Read more >
CMake Part 2 - Release and Debug builds - Sticky Bits
Build Customisation. With the toolchain correctly configured we will update the project configuration (CMakeLists.txt) to refactor the compiler ...
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