<div dir="ltr">I'm trying to use Clang to cross-compile runtimes for Fuchsia on Windows. The problem I'm hitting is that CMake checks the existence of _MSC_VER macro, and if set it detects the compiler as "Clang with GNU-like command line" which is a special mode in which CMake treats clang as clang-cl. This breaks cross-compilation for runtimes because CMake no longer passes --target= flag even if CMAKE_*_COMPILER_TARGET is set, etc. because of this logic: <a href="https://github.com/Kitware/CMake/blob/master/Modules/Compiler/Clang.cmake#L13">https://github.com/Kitware/CMake/blob/master/Modules/Compiler/Clang.cmake#L13</a><div><br></div><div>This is IMHO a bug in CMake: it shouldn't blindly assume that Clang is clang-cl without first consulting other variables like CMAKE_*_COMPILER_TARGET or CMAKE_SYSTEM_NAME, but I'm not sure how easy or difficult would it be to change CMake, and even then we would have a problem with rolling out new CMake version everywhere.<br><div><br></div><div>So instead, I'm hoping to bypass CMake's detection and force it to treat Clang as clang (note that this is only for the purpose of cross-compilation) and to do so I need to unset _MSC_VER. Looking at the driver code, it seems like _MSC_VER is only defined if -fms-compatibility-version is set. I was hoping that setting -fno-ms-compatibility would do the trick, but it doesn't because -fms-compatibility-version is set independently of -f[no]-ms-compatibility: <a href="https://github.com/llvm/llvm-project/blob/69bf40c45fd7f6dfe11b47de42571d8bff5ef94f/clang/lib/Driver/ToolChains/Clang.cpp#L5395" target="_blank">https://github.com/llvm/llvm-project/blob/69bf40c45fd7f6dfe11b47de42571d8bff5ef94f/clang/lib/Driver/ToolChains/Clang.cpp#L5395</a>. When MSVC target is the default driver, -fms-compatibility-version is going to be set because <a href="https://github.com/llvm/llvm-project/blob/69bf40c45fd7f6dfe11b47de42571d8bff5ef94f/clang/lib/Driver/ToolChains/MSVC.cpp#L1320">https://github.com/llvm/llvm-project/blob/69bf40c45fd7f6dfe11b47de42571d8bff5ef94f/clang/lib/Driver/ToolChains/MSVC.cpp#L1320</a> returns a non-empty string, and AFAICT there's no way to disable it, which doesn't match the documentation: <a href="https://github.com/llvm/llvm-project/blob/69bf40c45fd7f6dfe11b47de42571d8bff5ef94f/clang/include/clang/Driver/Options.td#L1362" target="_blank">https://github.com/llvm/llvm-project/blob/69bf40c45fd7f6dfe11b47de42571d8bff5ef94f/clang/include/clang/Driver/Options.td#L1362</a></div><div><br></div><div>Does anyone know if this is intentional or just a bug? Would it make sense to change the driver to avoid setting -fms-compatibility-version when -fno-ms-compatibility is set?</div></div></div>