]> granicus.if.org Git - llvm/commitdiff
build: use clang-cl for runtimes when targeting Windows
authorSaleem Abdulrasool <compnerd@compnerd.org>
Fri, 17 May 2019 20:09:06 +0000 (20:09 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Fri, 17 May 2019 20:09:06 +0000 (20:09 +0000)
When targeting Windows and building a runtime (subproject) prefer to use
`clang-cl` rather than the `clang` driver.  This allows us to cross-compile
runtimes for the Windows environment from Linux.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361072 91177308-0d34-0410-b5e6-96231b3b80d8

cmake/modules/LLVMExternalProjectUtils.cmake

index 0cf6e0d4843eae1510fa4e011a01552bd3e8029c..8190896737f10dce84939578eb3e87f12579b2f6 100644 (file)
@@ -104,13 +104,28 @@ function(llvm_ExternalProject_Add name source_dir)
     endforeach()
   endforeach()
 
+  foreach(arg ${ARG_CMAKE_ARGS})
+    if(arg MATCHES "^-DCMAKE_SYSTEM_NAME=")
+      string(REGEX REPLACE "^-DCMAKE_SYSTEM_NAME=(.*)$" "\\1" _cmake_system_name "${arg}")
+    endif()
+  endforeach()
+
   if(ARG_USE_TOOLCHAIN AND NOT CMAKE_CROSSCOMPILING)
     if(CLANG_IN_TOOLCHAIN)
-      set(compiler_args -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
-                        -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
+      if(_cmake_system_name STREQUAL Windows)
+        set(compiler_args -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl
+                          -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl)
+      else()
+        set(compiler_args -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
+                          -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
+      endif()
     endif()
     if(lld IN_LIST TOOLCHAIN_TOOLS)
-      list(APPEND compiler_args -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/ld.lld)
+      if(_cmake_system_name STREQUAL Windows)
+        list(APPEND compiler_args -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link)
+      else()
+        list(APPEND compiler_args -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/ld.lld)
+      endif()
     endif()
     if(llvm-ar IN_LIST TOOLCHAIN_TOOLS)
       list(APPEND compiler_args -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar)