Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: develop2
Choose a base branch
from

Conversation

valgur
Copy link
Contributor

@valgur valgur commented Sep 30, 2024

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
Copy link
Contributor Author

valgur commented Sep 30, 2024

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: conan-io/conan#17087.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant