瀏覽代碼

[CMake] Multi-target builtins build

This change enables building builtins for multiple different targets
using LLVM runtimes directory.

To specify the builtin targets to be built, use the LLVM_BUILTIN_TARGETS
variable, where the value is the list of targets.  To pass a per target
variable to the builtin build, you can set BUILTINS_<target>_<variable>
where <variable> will be passed to the builtin build for <target>.

Differential Revision: https://reviews.llvm.org/D26652

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289491 91177308-0d34-0410-b5e6-96231b3b80d8
Petr Hosek 8 年之前
父節點
當前提交
a923c5a134
共有 2 個文件被更改,包括 43 次插入6 次删除
  1. 9 0
      cmake/modules/LLVMExternalProjectUtils.cmake
  2. 34 6
      runtimes/CMakeLists.txt

+ 9 - 0
cmake/modules/LLVMExternalProjectUtils.cmake

@@ -45,6 +45,9 @@ function(llvm_ExternalProject_Add name source_dir)
   canonicalize_tool_name(${name} nameCanon)
   if(NOT ARG_TOOLCHAIN_TOOLS)
     set(ARG_TOOLCHAIN_TOOLS clang lld)
+    if(NOT APPLE AND NOT WIN32)
+      list(APPEND ARG_TOOLCHAIN_TOOLS llvm-ar llvm-ranlib)
+    endif()
   endif()
   foreach(tool ${ARG_TOOLCHAIN_TOOLS})
     if(TARGET ${tool})
@@ -104,6 +107,12 @@ function(llvm_ExternalProject_Add name source_dir)
       set(compiler_args -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
                         -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
     endif()
+    if(llvm-ar IN_LIST TOOLCHAIN_TOOLS)
+      list(APPEND compiler_args -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar)
+    endif()
+    if(llvm-ranlib IN_LIST TOOLCHAIN_TOOLS)
+      list(APPEND compiler_args -DCMAKE_RANLIB=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib)
+    endif()
     list(APPEND ARG_DEPENDS ${TOOLCHAIN_TOOLS})
   endif()
 

+ 34 - 6
runtimes/CMakeLists.txt

@@ -139,12 +139,40 @@ else() # if this is included from LLVM's CMake
   # is required because the other runtimes need the builtin libraries present
   # before the just-built compiler can pass the configuration tests.
   if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt)
-    llvm_ExternalProject_Add(builtins
-                             ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt/lib/builtins
-                             CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
-                                        -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
-                             PASSTHROUGH_PREFIXES COMPILER_RT
-                             USE_TOOLCHAIN)
+    if(APPLE OR NOT LLVM_BUILTIN_TARGETS)
+      llvm_ExternalProject_Add(builtins
+                               ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt/lib/builtins
+                               CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
+                                          -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
+                                          -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE}
+                                          -DCMAKE_ASM_COMPILER_TARGET=${TARGET_TRIPLE}
+                               PASSTHROUGH_PREFIXES COMPILER_RT
+                               USE_TOOLCHAIN)
+    else()
+      get_cmake_property(variableNames VARIABLES)
+      add_custom_target(builtins)
+      foreach(target ${LLVM_BUILTIN_TARGETS})
+        foreach(variableName ${variableNames})
+          if(variableName MATCHES "^BUILTINS_${target}")
+            string(REPLACE "BUILTINS_${target}_" "" new_name ${variableName})
+            list(APPEND ${target}_extra_args "-D${new_name}=${${variableName}}")
+          endif()
+        endforeach()
+        llvm_ExternalProject_Add(builtins-${target}
+                               ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt/lib/builtins
+                               CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
+                                          -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
+                                          -DCMAKE_C_COMPILER_TARGET=${target}
+                                          -DCMAKE_ASM_COMPILER_TARGET=${target}
+                                          -DCMAKE_C_COMPILER_WORKS=On
+                                          -DCMAKE_ASM_COMPILER_WORKS=On
+                                          -DCOMPILER_RT_DEFAULT_TARGET_ONLY=On
+                                          ${${target}_extra_args}
+                               PASSTHROUGH_PREFIXES COMPILER_RT
+                               USE_TOOLCHAIN)
+        add_dependencies(builtins builtins-${target})
+      endforeach()
+    endif()
     set(deps builtins)
     # We don't need to depend on the builtins if we're building instrumented
     # because the next stage will use the same compiler used to build this stage.