Repository: conan-io/conan

Issue:
Using clang-cl with libraries compiled with Visual Studio doesn't work
Conan version: 1.18.1
OS Name: Windows 10
Version: 1903
OS build: 18362.418
Visual Studio 2019 Version 16.3.3

When using clang-cl I want to use libraries that were compiled with Visual Studio since they are binary compatible and building most libraries with clang-cl is basically impossible right now(but thats another issue).

I made a little proof of concept of what I'm trying to do [here](https://github.com/munoah/clang-cl-poc).

Since it uses conan_cmake your default profile should look something like this:
```
[settings]
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.version=16
build_type=Release
```
In Visual Studio go to Open -> CMake and select the CMakeLists.txt
Everything works as expected in the x64-Debug Configuration, however when I switch to x64-Clang-Debug I get:
```
CMake Error at out/build/x64-Clang-Debug/conanbuildinfo.cmake:642 (message):
Incorrect 'Visual Studio'.  Toolset specifies compiler as 'MSVC' but CMake detected 'Clang'
```
I can `set(CONAN_DISABLE_CHECK_COMPILER TRUE)` to disable the whole function, but disabling sanity checks is not nice.
The check that the specified toolset uses the same compiler as the project seems a bit counterproductive, clang-cl and cl are binary compatible (and i guess the check further down is the same problem, maybe someone wants to compile my code with gcc, but the libraries with clang for performance reasons)

My fix for this would be reverting https://github.com/conan-io/conan/issues/2285, but that would presumably break toolchains, but these seem to work different in vs19 anyways

Relates Issues:
https://github.com/conan-io/conan/issues/1839
https://github.com/conan-io/conan/issues/2285





Discussion:
Hi @munoah,
It seems that this question could be related to features we are currently developing to have different compilers defined that are binary compatible with each other (#5590 and #5837).

Hello,
using the profile
```
[settings]
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.version=16
build_type=Release
compiler.toolset=ClangCL
```
also results in the same error.
It seems that the cmake generator has to be extended to support all msvc toolsets. I just modified https://github.com/conan-io/conan/blob/de080af9f006f1eda660b324e21a00c316ab8e4d/conans/client/generators/cmake_common.py#L586 and replaced "clang" with "ClangCL" for my usecase and it worked just fine.

Resolving patch:
diff --git a/conans/client/generators/cmake_common.py b/conans/client/generators/cmake_common.py
--- a/conans/client/generators/cmake_common.py
+++ b/conans/client/generators/cmake_common.py
@@ -583,7 +583,9 @@ class CMakeCommonMacros:
             # If using VS, verify toolset
             if (CONAN_COMPILER STREQUAL "Visual Studio")
                 if (CONAN_SETTINGS_COMPILER_TOOLSET MATCHES "LLVM" OR
-                    CONAN_SETTINGS_COMPILER_TOOLSET MATCHES "clang")
+                    CONAN_SETTINGS_COMPILER_TOOLSET MATCHES "llvm" OR
+                    CONAN_SETTINGS_COMPILER_TOOLSET MATCHES "clang" OR
+                    CONAN_SETTINGS_COMPILER_TOOLSET MATCHES "Clang")
                     set(EXPECTED_CMAKE_CXX_COMPILER_ID "Clang")
                 elseif (CONAN_SETTINGS_COMPILER_TOOLSET MATCHES "Intel")
                     set(EXPECTED_CMAKE_CXX_COMPILER_ID "Intel")


Test patch: