[CMake] Using Clang + Ninja on Windows?

Brad King brad.king at kitware.com
Thu Apr 21 11:17:52 EDT 2016


On 04/21/2016 10:15 AM, Johan Holmberg wrote:
> I chose the binaries behaving like "gcc"
> 
> I realize that Cristian Adams recommended using the "cl.exe" wrapper in
> his response, but I wanted at least to try using the "gcc-like" binaries
> first, hoping that they should work with CMake.

I think that is the problem.  See below.

> E:\work\proj\hello1\build> cmake -GNinja ..\src
> -- The C compiler identification is Clang 3.8.0
> -- The CXX compiler identification is Clang 3.8.0

>From the compiler id files you sent me I see:

    $ strings build/CMakeFiles/3.5.1/CompilerIdC/a.exe | grep INFO
    INFO:compiler[Clang]
    INFO:simulate[MSVC]
    INFO:compiler_version[00000003.00000008.00000000]
    INFO:simulate_version[00000018.00000000]
    INFO:platform[Windows]
    INFO:arch[x64]
    INFO:dialect_default[11]

    $ strings build/CMakeFiles/3.5.1/CompilerIdCXX/a.exe | grep INFO
    INFO:compiler[Clang]
    INFO:simulate[MSVC]
    INFO:platform[Windows]
    INFO:arch[x64]
    INFO:dialect_default[11]
    INFO:compiler_version[00000003.00000008.00000000]
    INFO:simulate_version[00000018.00000000]

The "INFO:simulate[MSVC]" lines mean that CMake has detected that the given
Clang compiler defines _MSC_VER and therefore acts like MSVC and not GNU
(i.e. uses the msvc ABI instead of the gnu ABI).

CMake then assumes that the compiler command line is compatible with "cl".
We have code that switches off this here:

 https://cmake.org/gitweb?p=cmake.git;a=blob;f=Modules/Platform/Windows-Clang.cmake;hb=v3.5.2
 https://cmake.org/gitweb?p=cmake.git;a=blob;f=Modules/Compiler/Clang.cmake;hb=v3.5.2

When all that was written clang-cl was still under development and our
assumption was that there is no such thing as a Clang that acts like
MSVC but is not cl-compatible on the command line.

-Brad



More information about the CMake mailing list