cmake-conan
cmake-conan copied to clipboard
Cannot `conan_cmake_run` with a non-default compiler
In my case, my default compiler is GCC, and I am trying to build my project by using clang.
Conan executing: conan install . -g cmake -s build_type=Release -s os=Linux -s compiler=clang -s compiler.version=8.0 -s compiler.libcxx=libstdc++11 --build=missing
CMake Error at build/Clang64-Release/conan.cmake:335 (message):
Conan install failed='1'
Call Stack (most recent call first):
build/Clang64-Release/conan.cmake:413 (conan_cmake_install)
CMakeLists.txt:241 (conan_cmake_run)
Creating a conanfile.txt and invoking the command conan install . -g cmake -s build_type=Release -s os=Linux -s compiler=clang -s compiler.version=8.0 -s compiler.libcxx=libstdc++11 --build=missing manually, I got
CMake Error at conanbuildinfo.cmake:415 (message):
Incorrect 'clang', is not the one detected by CMake: 'GNU'
If I add CC=clang in front of the command than I can install manually, but I still don't know how to solve the problem by cmake-conan.
Same issue for me when using clang
I found a workaround for this:
set(CONAN_DISABLE_CHECK_COMPILER 1)
before conan_cmake_run.
Not the best solution, but seems to work.
For some reason conan_cmake_run specifies settings for the compiler but does not configure the environment for conan to find the correct compiler executable. Adding 'ENV CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER}' as an argument to conan_cmake_run makes sure that the correct executable gets used.
I wrote the following to pass the right ENV:
set(ENV_FOR_C CC)
set(ENV_FOR_CXX CXX)
set(ENV_FOR_Fortran FC)
foreach(language ${languages})
list(APPEND ENV "${ENV_FOR_${language}}=${CMAKE_${language}_COMPILER}")
endforeach()
conan_cmake_run(
CONANFILE conanfile.txt
BASIC_SETUP CMAKE_TARGETS BUILD missing
ENV CONAN_CMAKE_PROGRAM="${CMAKE_COMMAND}" ${ENV}
)
Why isn't it enabled by default? Or at least as an option?