[question] Can CMakeToolchain tell CMake the correct compilers?
See original GitHub issueMy 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!
- I’ve read the CONTRIBUTING guide.
Issue Analytics
- State:
- Created a year ago
- Comments:11 (6 by maintainers)
Top GitHub Comments
Looks fine to me. Thanks for spending the effort!
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!