cmake-conan
cmake-conan copied to clipboard
conan_cmake_run() does not use the current 'os' setting when not using a profile
SUMMARY:
Contrary to the comment at the top of conan.cmake
# It will take CMake current settings (os, compiler, compiler version, architecture)
# and translate them to conan settings for installing and retrieving dependencies.
calling conan_cmake_run() without a profile does not use CMake's current os setting. This leads to a cross compile build failing because dependencies are compiled for the wrong OS.
STEPS TO REPRODUCE:
- Add a dependency on
boost/1.72.0 - cross-compile the project on Linux or OSX for Windows using a
x86_64-w64-mingw32cross compiler - in
CMakeLists.txtrun conan with
conan_cmake_run(
REQUIRES boost/1.72.0
BASIC_SETUP
KEEP_RPATHS
BUILD missing
)
EXPECTED RESULT:
- Build works
ACTUAL RESULT:
- The output of
conan_cmake_run()contains the lineos=Linux(expected:os=Windows) - The generated boost libraries are all in file format elf64-x86-64 (expected: pe-x86-64)
- The linker fails with a segmentation fault
DETAILS AND RESOLUTION:
conan_cmake_settings() correctly checks CMAKE_SYSTEM_NAME and sets CONAN_SYSTEM_NAME and _CONAN_SETTING_OS accordingly but never translates this setting into a command line argument because
if(NOT _SETTINGS OR ARGUMENTS_PROFILE_AUTO STREQUAL "ALL")
set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version
compiler.runtime compiler.libcxx compiler.toolset)
endif()
does not add os to ARGUMENTS_PROFILE_AUTO.
This leads to building dependencies with an incorrect os setting when cross compiling which makes the build fail.
Changing this line to
if(NOT _SETTINGS OR ARGUMENTS_PROFILE_AUTO STREQUAL "ALL")
set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version
compiler.runtime compiler.libcxx compiler.toolset os)
endif()
(adding os at the end of the third line) fixes the issue.
Hi @mheyse, I think that this phrase was not thought having cross-compilation in mind. If you are doing cross-compilation I would suggest that you use a different profile for that because it's probably not going to automatically be resolved otherwise. Anyway, we are now introducing a new cross-compiling model for Conan 1.24 to use different profiles for build and host.