cmake-conan icon indicating copy to clipboard operation
cmake-conan copied to clipboard

Set compiler.runtime for ClangCL and other "cl-like" compilers

Open valgur opened this issue 1 year ago • 1 comments

Motivation

Building with cmake -S . -B build/Release -G "Visual Studio 17 2022" -T ClangCL -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug> (i.e. not the default -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$CONFIG:Debug:Debug>DLL) fails to set compiler.runtime=static` in the detected profile and linking against Conan libraries fails with

lld-link : error : /failifmismatch: mismatch detected for 'RuntimeLibrary': 
  >>> xyz.obj has value MTd_StaticDebug
  >>> gtest.lib(gtest-all.obj) has value MDd_DynamicDebug

Details

This PR simply extends the runtime type detection to all "cl-like" compilers by replacing the if(_compiler MATCHES MSVC) check with if(MSVC) for the relevant part.

The detected profile before
Saving detected profile to C:\Users\runneradmin\.conan2\profiles\default
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.version=194
os=Windows

-- CMake-Conan: cmake_system_name=Windows
-- CMake-Conan: cmake_system_processor=x86_64
-- CMake-Conan: CMake compiler=Clang
-- CMake-Conan: CMake compiler version=17.0.3
-- CMake-Conan: [settings] compiler=clang
-- CMake-Conan: [settings] compiler.version=17
-- CMake-Conan: Creating profile build/Release/conan_host_profile
-- CMake-Conan: Profile: 
[settings]
arch=x86_64
os=Windows
compiler=clang
compiler.version=17
compiler.cppstd=17
[conf]
tools.cmake.cmaketoolchain:generator=Visual Studio 17 2022
tools.build:compiler_executables={"cpp":"C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/Llvm/x64/bin/clang-cl.exe"}

-- CMake-Conan: Installing both Debug and Release
-- CMake-Conan: conan install . -of=build/Release/conan --profile:host=default;--profile:host=build/Release/conan_host_profile;--profile:build=default;-s;build_type=Release;--build=missing

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=17
compiler.version=17
os=Windows
[conf]
tools.build:compiler_executables={'cpp': 'C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/Llvm/x64/bin/clang-cl.exe'}
tools.cmake.cmaketoolchain:generator=Visual Studio 17 2022

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows
After
Saving detected profile to C:\Users\runneradmin\.conan2\profiles\default
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.version=194
os=Windows

-- CMake-Conan: cmake_system_name=Windows
-- CMake-Conan: cmake_system_processor=x86_64
-- CMake-Conan: CMake compiler=Clang
-- CMake-Conan: CMake compiler version=17.0.3
-- CMake-Conan: CMake compiler.runtime=static
-- CMake-Conan: [settings] compiler=clang
-- CMake-Conan: [settings] compiler.version=17
-- CMake-Conan: [settings] compiler.runtime=static
-- CMake-Conan: Creating profile build/Release/conan_host_profile
-- CMake-Conan: Profile: 
[settings]
arch=x86_64
os=Windows
compiler=clang
compiler.version=17
compiler.runtime=static
compiler.cppstd=17
[conf]
tools.cmake.cmaketoolchain:generator=Visual Studio 17 2022
tools.build:compiler_executables={"cpp":"C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/Llvm/x64/bin/clang-cl.exe"}

-- CMake-Conan: Installing both Debug and Release
-- CMake-Conan: conan install . -of=build/Release/conan --profile:host=default;--profile:host=build/Release/conan_host_profile;--profile:build=default;-s;build_type=Release;--build=missing

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=17
compiler.runtime=static
compiler.runtime_type=Release
compiler.version=17
os=Windows
[conf]
tools.build:compiler_executables={'cpp': 'C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/Llvm/x64/bin/clang-cl.exe'}
tools.cmake.cmaketoolchain:generator=Visual Studio 17 2022

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows

Diff

@@ -12,8 +12,10 @@
 -- CMake-Conan: cmake_system_processor=x86_64
 -- CMake-Conan: CMake compiler=Clang
 -- CMake-Conan: CMake compiler version=17.0.3
+-- CMake-Conan: CMake compiler.runtime=static
 -- CMake-Conan: [settings] compiler=clang
 -- CMake-Conan: [settings] compiler.version=17
+-- CMake-Conan: [settings] compiler.runtime=static
 -- CMake-Conan: Creating profile build/Release/conan_host_profile
 -- CMake-Conan: Profile: 
 [settings]
@@ -21,6 +23,7 @@
 os=Windows
 compiler=clang
 compiler.version=17
+compiler.runtime=static
 compiler.cppstd=17
 [conf]
 tools.cmake.cmaketoolchain:generator=Visual Studio 17 2022
@@ -36,6 +39,8 @@
 build_type=Release
 compiler=clang
 compiler.cppstd=17
+compiler.runtime=static
+compiler.runtime_type=Release
 compiler.version=17
 os=Windows
 [conf]

valgur avatar Sep 30 '24 17:09 valgur

The CI failed due to a macOS version newer than settings.yml is aware of being used in the CI. I opened a PR to update the version lists in Conan: https://github.com/conan-io/conan/pull/17087.

valgur avatar Sep 30 '24 18:09 valgur