Repository: conan-io/conan-center-index

Issue:
[package] gtest: compiler.runtime not taken into account for clang-cl
### Package and Environment Details

* Package Name/Version: **gtest/1.12.1**
* Operating System+version: **Windows 11 Pro 10.0.22000**
* Compiler+version: **clang 14.0.4**
* Conan version: **conan 1.50.0**
* Python version: **Python 3.10.2**


### Conan profile

```
[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=clang
compiler.runtime=MD
compiler.version=14
build_type=Release
[options]
[conf]
[build_requires]
[env]
CC=C:\.conan\0b233d\1\bin\clang-cl.exe
CXX=C:\.conan\0b233d\1\bin\clang-cl.exe
```

`clang-cl` is packaged using own conan recipe for easy installation, but problem is the same for the official precompiled llvm binaries.

### Steps to reproduce

conanfile.txt

```
[requires]
gtest/1.12.1
[generators]
cmake
cmake_find_package
```

The exact version of gtest probably doesn't really matter, also happens with 1.11.0. 

test.cpp

```
include <gtest/gtest.h>

TEST(Foo, Bar) {
    EXPECT_EQ(1, 1);
}
```

CMakeLists.txt

```
cmake_minimum_required(VERSION 3.16.0 FATAL_ERROR)
project(GTestClang LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_BINARY_DIR})

find_package(GTest REQUIRED)

add_executable(TestExe test.cpp)
target_link_libraries(TestExe PRIVATE GTest::gtest_main)
```

### Logs

<details><summary>Click to expand log</summary>

```
C:\Work\gtest-clang\build> ninja
[2/2] Linking CXX executable bin\TestExe.exe
FAILED: bin/TestExe.exe
cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\TestExe.dir --rc=C:\PROGRA~2\WINDOW~4\10\bin\100190~1.0\x64\rc.exe --mt=C:\PROGRA~2\WINDOW~4\10\bin\100190~1.0\x64\mt.exe --manifests  -- C:\.conan\0b233d\1\bin\lld-link.exe /nologo CMakeFiles\TestExe.dir\test.cpp.obj  /out:bin\TestExe.exe /implib:lib\TestExe.lib /pdb:bin\TestExe.pdb /version:0.0 /machine:x64   /INCREMENTAL:NO  /subsystem:console -LIBPATH:C:\Users\HOISUN~1\CONAN~1\data\gtest\112~1.1\_\_\package\551AEF~1\lib "C:\Users\Hoisun Ng\.conan\data\gtest\1.12.1\_\_\package\551aef66dd92944a4a05c3692c17dfdde59967e9\lib\gmock_main.lib"  "C:\Users\Hoisun Ng\.conan\data\gtest\1.12.1\_\_\package\551aef66dd92944a4a05c3692c17dfdde59967e9\lib\gmock.lib"  "C:\Users\Hoisun Ng\.conan\data\gtest\1.12.1\_\_\package\551aef66dd92944a4a05c3692c17dfdde59967e9\lib\gtest.lib"  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command "C:\.conan\0b233d\1\bin\lld-link.exe /nologo CMakeFiles\TestExe.dir\test.cpp.obj /out:bin\TestExe.exe /implib:lib\TestExe.lib /pdb:bin\TestExe.pdb /version:0.0 /machine:x64 /INCREMENTAL:NO /subsystem:console -LIBPATH:C:\Users\HOISUN~1\CONAN~1\data\gtest\112~1.1\_\_\package\551AEF~1\lib C:\Users\Hoisun Ng\.conan\data\gtest\1.12.1\_\_\package\551aef66dd92944a4a05c3692c17dfdde59967e9\lib\gmock_main.lib C:\Users\Hoisun Ng\.conan\data\gtest\1.12.1\_\_\package\551aef66dd92944a4a05c3692c17dfdde59967e9\lib\gmock.lib C:\Users\Hoisun Ng\.conan\data\gtest\1.12.1\_\_\package\551aef66dd92944a4a05c3692c17dfdde59967e9\lib\gtest.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:bin\TestExe.exe.manifest" failed (exit code 1) with the following output:
lld-link: error: /failifmismatch: mismatch detected for 'RuntimeLibrary':
>>> CMakeFiles\TestExe.dir\test.cpp.obj has value MD_DynamicRelease
>>> gmock_main.lib(gtest-all.cc.obj) has value MT_StaticRelease
ninja: build stopped: subcommand failed.
```

</details>



Discussion:

Resolving patch:
diff --git a/recipes/gtest/all/conanfile.py b/recipes/gtest/all/conanfile.py
--- a/recipes/gtest/all/conanfile.py
+++ b/recipes/gtest/all/conanfile.py
@@ -71,6 +71,10 @@ def _minimum_compilers_version(self):
                 "apple-clang": "9.1"
             }
 
+    @property
+    def _is_clang_cl(self):
+        return self.settings.os == "Windows" and self.settings.compiler == "clang"
+
     def export_sources(self):
         self.copy("CMakeLists.txt")
         for patch in self.conan_data.get("patches", {}).get(self.version, []):
@@ -90,7 +94,7 @@ def package_id(self):
         del self.info.options.no_main
 
     def validate(self):
-        if self.options.shared and is_msvc(self) and "MT" in msvc_runtime_flag(self):
+        if self.options.shared and (is_msvc(self) or self._is_clang_cl) and "MT" in msvc_runtime_flag(self):
             raise ConanInvalidConfiguration(
                 "gtest:shared=True with compiler=\"Visual Studio\" is not "
                 "compatible with compiler.runtime=MT/MTd"
@@ -133,7 +137,7 @@ def _configure_cmake(self):
         cmake = CMake(self)
         if self.settings.build_type == "Debug":
             cmake.definitions["CUSTOM_DEBUG_POSTFIX"] = self.options.debug_postfix
-        if is_msvc(self):
+        if is_msvc(self) or self._is_clang_cl:
             cmake.definitions["gtest_force_shared_crt"] = "MD" in msvc_runtime_flag(self)
         cmake.definitions["BUILD_GMOCK"] = self.options.build_gmock
         if self.settings.os == "Windows" and self.settings.compiler == "gcc":


Test patch: