This is an archive of the discontinued LLVM Phabricator instance.

Make clang-cl able to self host on Windows ✿ヾ╲(。◕‿◕。)╱✿
ClosedPublic

Authored by zturner on Feb 22 2015, 11:08 PM.

Details

Summary

CMake 3.x adds the notion of "simulated compilers" [1, 2]. CMAKE_CXX_COMPILER_ID will still report the actual compiler you're using, but it will set additional variables CMAKE_CXX_SIMULATE_ID and CMAKE_CXX_SIMULATE_VERSION. So, for example, if you set CC and CXX to clang-cl and run CMake while MSVC in your path (for example you've run vcvarsall), then CMAKE_CXX_SIMULATE_ID will get set to "MSVC", and CMAKE_CXX_SIMULATE_VERSION will get set to the value of -fms-compatibility-version.

With this patch and one more patch on the clang side to get -fms-compatibility-version to default to 18.00 instead of 17.00, I was able to compile with clang-cl with the following CMake invocation:

set CC=clang-cl.exe
set CXX=clang-cl.exe
cmake -G Ninja ..\..\llvm

I need to test this more exhaustively, and with CMake 2.8. I know CMake 2.8 doesn't support this, but I want to make sure it doesn't completely break the build. I also haven't completed a full build and run the test suite. But I was able to get ninja to [100/3000] with no major blowups before I stopped due to clang being so slow (I had installed a debug build). So this is promising, and I want to throw it up for discussion.

[1] http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=51ab85c3
[2] http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3d8356d4

Diff Detail

Event Timeline

zturner updated this revision to Diff 20489.Feb 22 2015, 11:08 PM
zturner retitled this revision from to Make clang-cl able to self host on Windows ✿ヾ╲(。◕‿◕。)╱✿.
zturner updated this object.
zturner edited the test plan for this revision. (Show Details)
zturner added reviewers: rnk, chandlerc, majnemer.
zturner added a subscriber: Unknown Object (MLST).
hans added a subscriber: hans.Feb 23 2015, 8:19 AM

Thanks for looking into this!

With this patch and one more patch on the clang side to get -fms-compatibility-version to default to 18.00 instead of 17.00,

Yes, I think we should just bump the compatibility version now.

rnk accepted this revision.Feb 23 2015, 9:53 AM
rnk edited edge metadata.

Nice! Looks good. Can we tweak the libstdc++ check instead, though? I think it makes more sense to come into the Clang branch in case we add more stuff there in the future.

-    if(NOT LLVM_ENABLE_LIBCXX)
+    if (CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
+      ...
+    elseif(NOT LLVM_ENABLE_LIBCXX)
This revision is now accepted and ready to land.Feb 23 2015, 9:53 AM
This revision was automatically updated to reflect the committed changes.