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

Zachary Turner zturner at google.com
Sun Feb 22 23:08:44 PST 2015


Hi rnk, chandlerc, majnemer,

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

http://reviews.llvm.org/D7824

Files:
  cmake/modules/HandleLLVMOptions.cmake

Index: cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- cmake/modules/HandleLLVMOptions.cmake
+++ cmake/modules/HandleLLVMOptions.cmake
@@ -16,7 +16,7 @@
     if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
       message(FATAL_ERROR "Host GCC version must be at least 4.7!")
     endif()
-  elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+  elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT (CMAKE_CXX_SIMULATE_ID MATCHES "MSVC") )
     if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1)
       message(FATAL_ERROR "Host Clang version must be at least 3.1!")
     endif()
@@ -47,6 +47,10 @@
       message(WARNING "Host Visual Studio should at least be 2013 Update 4 (MSVC 18.0.31101)"
         "  due to miscompiles from earlier versions")
     endif()
+  elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
+    if (CMAKE_CXX_SIMULATE_VERSION VERSION_LESS 18.0)
+      message(FATAL_ERROR "Host Clang must have at least -fms-compatibility-version=18.0")
+    endif()
   endif()
 endif()

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7824.20489.patch
Type: text/x-patch
Size: 1090 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150223/7f762fd9/attachment.bin>


More information about the llvm-commits mailing list