OSDN Git Service

Setup testing target dependencies for default runtimes
[android-x86/external-llvm.git] / runtimes / CMakeLists.txt
index 06581b3..552ab7b 100644 (file)
@@ -4,8 +4,12 @@
 # should be built with the LLVM toolchain from the build directory. This file is
 # a first step to formalizing runtime build interfaces.
 
-# In the current state this file only works with compiler-rt, other runtimes
-# will work as the runtime build interface standardizes.
+# Setting CMake minimum required version should be at the very top of the file
+# if this is the entry point.
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+  cmake_minimum_required(VERSION 3.4.3)
+  project(Runtimes C CXX ASM)
+endif()
 
 # Find all subdirectories containing CMake projects
 file(GLOB entries *)
@@ -55,12 +59,13 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
   cmake_minimum_required(VERSION 3.4.3)
   project(Runtimes C CXX ASM)
 
+  find_package(LLVM PATHS "${LLVM_BINARY_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+
   # Add the root project's CMake modules, and the LLVM build's modules to the
   # CMake module path.
   list(INSERT CMAKE_MODULE_PATH 0
     "${CMAKE_CURRENT_SOURCE_DIR}/../cmake"
     "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules"
-    "${LLVM_LIBRARY_DIR}/cmake/llvm"
   )
 
   # Some of the runtimes will conditionally use the compiler-rt sanitizers
@@ -70,16 +75,11 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
   get_compiler_rt_path(compiler_rt_path)
   if(compiler_rt_path)
     list(REMOVE_ITEM runtimes ${compiler_rt_path})
-    if(NOT LLVM_BUILD_COMPILER_RT)
+    if(NOT DEFINED LLVM_BUILD_COMPILER_RT OR LLVM_BUILD_COMPILER_RT)
       list(INSERT runtimes 0 ${compiler_rt_path})
     endif()
   endif()
 
-  # LLVMConfig.cmake contains a bunch of CMake variables from the LLVM build.
-  # This file is installed as part of LLVM distributions, so this can be used
-  # either from a build directory or an installed LLVM.
-  include(LLVMConfig)
-
   # Setting these variables will allow the sub-build to put their outputs into
   # the library and bin directories of the top-level build.
   set(LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_DIR})
@@ -87,78 +87,71 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
 
   # This variable makes sure that e.g. llvm-lit is found.
   set(LLVM_MAIN_SRC_DIR ${LLVM_BUILD_MAIN_SRC_DIR})
+  set(LLVM_CMAKE_PATH ${LLVM_MAIN_SRC_DIR}/cmake/modules)
+
+  # This variable is used by individual runtimes to locate LLVM files.
+  set(LLVM_PATH ${LLVM_BUILD_MAIN_SRC_DIR})
 
   if(APPLE)
     set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
   endif()
 
-  set(SAFE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
-  set(SAFE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
-
   include(CheckLibraryExists)
   include(CheckCCompilerFlag)
 
-  check_library_exists(c fopen "" LLVM_HAS_C_LIB)
-  check_c_compiler_flag(-nodefaultlibs LLVM_HAS_NODEFAULTLIBS_FLAG)
-  if(LLVM_HAS_NODEFAULTLIBS_FLAG)
-    set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
-    if(LLVM_HAS_C_LIB)
-      list(APPEND CMAKE_REQUIRED_LIBRARIES c)
-    endif()
-  endif()
+  # We don't have libc++ (yet).
+  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 
   # Avoid checking whether the compiler is working.
   set(LLVM_COMPILER_CHECKED ON)
 
+  # Enable warnings, otherwise -w gets added to the cflags by HandleLLVMOptions
+  # resulting in unjustified successes by check_cxx_compiler_flag.
+  set(LLVM_ENABLE_WARNINGS ON)
+
   # Handle common options used by all runtimes.
   include(AddLLVM)
   include(HandleLLVMOptions)
+  include(FindPythonInterp)
 
-  set(CMAKE_REQUIRED_FLAGS ${SAFE_CMAKE_REQUIRED_FLAGS})
-  set(CMAKE_REQUIRED_LIBRARIES ${SAFE_CMAKE_REQUIRED_LIBRARIES})
+  # Remove the -nostdlib++ option we've added earlier.
+  string(REPLACE "-nostdlib++" "" CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
 
-  if(NOT LLVM_RUNTIMES_PREFIX)
-    set(LLVM_RUNTIMES_PREFIX "${LLVM_RUNTIMES_TARGET}/")
+  # Use libtool instead of ar if you are both on an Apple host, and targeting Apple.
+  if(CMAKE_HOST_APPLE AND APPLE)
+    include(UseLibtool)
   endif()
 
+  # This can be used to detect whether we're in the runtimes build.
+  set(RUNTIMES_BUILD ON)
+
   foreach(entry ${runtimes})
     get_filename_component(projName ${entry} NAME)
 
     # TODO: Clean this up as part of an interface standardization
     string(REPLACE "-" "_" canon_name ${projName})
     string(TOUPPER ${canon_name} canon_name)
-    # The subdirectories need to treat this as standalone builds
-    set(${canon_name}_STANDALONE_BUILD On)
 
-    if(LLVM_RUNTIMES_TARGET)
-      if(NOT "${projName}" MATCHES "compiler-rt")
-        set(${canon_name}_INSTALL_PREFIX "lib/${LLVM_RUNTIMES_PREFIX}/" CACHE STRING "" FORCE)
-      endif()
+    # The subdirectories need to treat this as standalone builds. D57992 tried
+    # to get rid of this, but the runtimes treat *_STANDALONE_BUILD=OFF as if
+    # llvm & clang are configured in the same CMake, and setup dependencies
+    # against their targets.
+    set(${canon_name}_STANDALONE_BUILD ON)
+
+    if(LLVM_RUNTIMES_LIBDIR_SUBDIR)
+      set(${canon_name}_LIBDIR_SUBDIR "${LLVM_RUNTIMES_LIBDIR_SUBDIR}" CACHE STRING "" FORCE)
     endif()
 
     # Setting a variable to let sub-projects detect which other projects
     # will be included under here.
-    set(HAVE_${canon_name} On)
+    set(HAVE_${canon_name} ON)
   endforeach()
 
-  set(SAFE_LLVM_BINARY_DIR ${LLVM_BINARY_DIR})
-  set(SAFE_LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
-  set(SAFE_LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
-
   # We do this in two loops so that HAVE_* is set for each runtime before the
   # other runtimes are added.
   foreach(entry ${runtimes})
     get_filename_component(projName ${entry} NAME)
 
-    if(LLVM_RUNTIMES_TARGET)
-      if(NOT "${projName}" MATCHES "compiler-rt")
-        set(LLVM_BINARY_DIR "${LLVM_LIBRARY_DIR}/${LLVM_RUNTIMES_PREFIX}")
-        set(LLVM_LIBDIR_SUFFIX "${LLVM_RUNTIMES_LIBDIR_SUFFIX}")
-        set(LLVM_LIBRARY_OUTPUT_INTDIR "${LLVM_LIBRARY_DIR}/${LLVM_RUNTIMES_PREFIX}lib${LLVM_RUNTIMES_LIBDIR_SUFFIX}")
-        set(LLVM_RUNTIME_OUTPUT_INTDIR "${LLVM_TOOLS_BINARY_DIR}/${LLVM_RUNTIMES_PREFIX}")
-      endif()
-    endif()
-
     # Between each sub-project we want to cache and clear the LIT properties
     set_property(GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
     set_property(GLOBAL PROPERTY LLVM_LIT_PARAMS)
@@ -176,14 +169,6 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
     list(APPEND RUNTIMES_LIT_PARAMS ${LLVM_LIT_PARAMS})
     list(APPEND RUNTIMES_LIT_DEPENDS ${LLVM_LIT_DEPENDS})
     list(APPEND RUNTIMES_LIT_EXTRA_ARGS ${LLVM_LIT_EXTRA_ARGS})
-
-    if(LLVM_RUNTIMES_TARGET)
-      if(NOT "${projName}" MATCHES "compiler-rt")
-        set(LLVM_BINARY_DIR "${SAFE_LLVM_BINARY_DIR}")
-        set(LLVM_LIBRARY_OUTPUT_INTDIR "${SAFE_LLVM_LIBRARY_OUTPUT_INTDIR}")
-        set(LLVM_RUNTIME_OUTPUT_INTDIR "${SAFE_LLVM_RUNTIME_OUTPUT_INTDIR}")
-      endif()
-    endif()
   endforeach()
 
   if(LLVM_INCLUDE_TESTS)
@@ -234,16 +219,28 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
 
 else() # if this is included from LLVM's CMake
   include(LLVMExternalProjectUtils)
+  if (LLVM_EXTERNAL_LIBCXX_SOURCE_DIR AND "libcxx" IN_LIST LLVM_ENABLE_RUNTIMES)
+    # This looks wrong, but libcxx's build actually wants the header dir to be
+    # the root build dir, not the include directory.
+    set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR})
+    set(CXX_HEADER_TARGET runtime-libcxx-headers)
+    add_subdirectory(${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR}/include ${CXX_HEADER_TARGET})
+  endif()
 
   if(NOT LLVM_BUILD_RUNTIMES)
     set(EXTRA_ARGS EXCLUDE_FROM_ALL)
   endif()
 
   function(builtin_default_target compiler_rt_path)
+    cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
+
     llvm_ExternalProject_Add(builtins
                              ${compiler_rt_path}/lib/builtins
+                             DEPENDS ${ARG_DEPENDS}
                              CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
                                         -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
+                                        -DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_TRIPLE}
+                                        -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
                                         -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE}
                                         -DCMAKE_ASM_COMPILER_TARGET=${TARGET_TRIPLE}
                                         -DCMAKE_C_COMPILER_WORKS=ON
@@ -254,6 +251,8 @@ else() # if this is included from LLVM's CMake
   endfunction()
 
   function(builtin_register_target compiler_rt_path target)
+    cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
+
     string(REPLACE "-" ";" builtin_target_list ${target})
     foreach(item ${builtin_target_list})
       string(TOLOWER "${item}" item_lower)
@@ -264,7 +263,8 @@ else() # if this is included from LLVM's CMake
 
     get_cmake_property(variableNames VARIABLES)
     foreach(variableName ${variableNames})
-      if(variableName MATCHES "^BUILTINS_${target}")
+      string(FIND "${variableName}" "BUILTINS_${target}" out)
+      if("${out}" EQUAL 0)
         string(REPLACE "BUILTINS_${target}_" "" new_name ${variableName})
         list(APPEND ${target}_extra_args "-D${new_name}=${${variableName}}")
       endif()
@@ -272,15 +272,18 @@ else() # if this is included from LLVM's CMake
 
     llvm_ExternalProject_Add(builtins-${target}
                              ${compiler_rt_path}/lib/builtins
+                             DEPENDS ${ARG_DEPENDS}
                              CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
                                         -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
+                                        -DLLVM_DEFAULT_TARGET_TRIPLE=${target}
+                                        -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
                                         -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}
-                             TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib
+                             TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib llvm-nm llvm-objcopy llvm-objdump llvm-strip
                              USE_TOOLCHAIN
                              ${EXTRA_ARGS})
   endfunction()
@@ -291,10 +294,12 @@ else() # if this is included from LLVM's CMake
   get_compiler_rt_path(compiler_rt_path)
   if(compiler_rt_path)
     if(NOT LLVM_BUILTIN_TARGETS)
-      builtin_default_target(${compiler_rt_path})
+      builtin_default_target(${compiler_rt_path}
+        DEPENDS clang-resource-headers)
     else()
       if("default" IN_LIST LLVM_BUILTIN_TARGETS)
-        builtin_default_target(${compiler_rt_path})
+        builtin_default_target(${compiler_rt_path}
+          DEPENDS clang-resource-headers)
         list(REMOVE_ITEM LLVM_BUILTIN_TARGETS "default")
       else()
         add_custom_target(builtins)
@@ -303,7 +308,8 @@ else() # if this is included from LLVM's CMake
       endif()
 
       foreach(target ${LLVM_BUILTIN_TARGETS})
-        builtin_register_target(${compiler_rt_path} ${target})
+        builtin_register_target(${compiler_rt_path} ${target}
+          DEPENDS clang-resource-headers)
 
         add_dependencies(builtins builtins-${target})
         add_dependencies(install-builtins install-builtins-${target})
@@ -334,10 +340,19 @@ else() # if this is included from LLVM's CMake
     list(APPEND runtime_names ${projName})
   endforeach()
 
+  if(LLVM_RUNTIME_BUILD_ID_LINK_TARGETS)
+    configure_file(
+      ${CMAKE_CURRENT_SOURCE_DIR}/llvm-strip-link.in
+      ${CMAKE_CURRENT_BINARY_DIR}/llvm-strip-link
+      @ONLY
+    )
+  endif()
+
   function(runtime_default_target)
-    cmake_parse_arguments(ARG "" "" "DEPS;PREFIXES" ${ARGN})
+    cmake_parse_arguments(ARG "" "" "DEPENDS;PREFIXES" ${ARGN})
 
     include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
+    set(SUB_CHECK_TARGETS ${SUB_CHECK_TARGETS} PARENT_SCOPE)
     set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
 
     foreach(runtime_name ${runtime_names})
@@ -349,6 +364,11 @@ else() # if this is included from LLVM's CMake
         list(APPEND test_targets check-${runtime_name})
       endif()
     endforeach()
+    foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
+      if(NOT ${component} IN_LIST SUB_COMPONENTS)
+        list(APPEND extra_targets ${component} install-${component} install-${component}-stripped)
+      endif()
+    endforeach()
 
     if(LLVM_INCLUDE_TESTS)
       list(APPEND test_targets runtimes-test-depends check-runtimes)
@@ -356,11 +376,13 @@ else() # if this is included from LLVM's CMake
 
     llvm_ExternalProject_Add(runtimes
                              ${CMAKE_CURRENT_SOURCE_DIR}
-                             DEPENDS ${ARG_DEPS}
+                             DEPENDS ${ARG_DEPENDS} ${CXX_HEADER_TARGET}
                              # Builtins were built separately above
                              CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
                                         -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
-                                        -DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR}
+                                        -DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_TRIPLE}
+                                        -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
+                                        -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
                                         -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE}
                                         -DCMAKE_CXX_COMPILER_TARGET=${TARGET_TRIPLE}
                                         -DCMAKE_ASM_COMPILER_TARGET=${TARGET_TRIPLE}
@@ -381,58 +403,76 @@ else() # if this is included from LLVM's CMake
   # runtime_register_target(target)
   #   Utility function to register external runtime target.
   function(runtime_register_target name target)
-    cmake_parse_arguments(ARG "" "" "DEPS" ${ARGN})
+    cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
     include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
     set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
 
-    set(${name}_deps ${ARG_DEPS})
+    set(${name}_deps ${ARG_DEPENDS})
     if(NOT name STREQUAL target)
       list(APPEND ${name}_deps runtimes-${target})
     endif()
 
     foreach(runtime_name ${runtime_names})
-      list(APPEND ${name}_extra_targets
-        "${runtime_name}:${runtime_name}-${name}"
-        "install-${runtime_name}:install-${runtime_name}-${name}"
-        "install-${runtime_name}-stripped:install-${runtime_name}-${name}-stripped")
+      set(${runtime_name}-${name} ${runtime_name})
+      set(install-${runtime_name}-${name} install-${runtime_name})
+      set(install-${runtime_name}-${name}-stripped install-${runtime_name}-stripped)
+      list(APPEND ${name}_extra_targets ${runtime_name}-${name} install-${runtime_name}-${name} install-${runtime_name}-${name}-stripped)
       if(LLVM_INCLUDE_TESTS)
-        list(APPEND ${name}_test_targets "check-${runtime_name}:check-${runtime_name}-${name}")
+        set(check-${runtime_name}-${name} check-${runtime_name} )
+        list(APPEND ${name}_test_targets check-${runtime_name}-${name})
       endif()
     endforeach()
 
     foreach(target_name IN LISTS SUB_COMPONENTS SUB_INSTALL_TARGETS)
-      list(APPEND ${name}_extra_targets "${target_name}:${target_name}-${name}")
+      set(${target_name}-${name} ${target_name})
+      list(APPEND ${name}_extra_targets ${target_name}-${name})
+    endforeach()
+
+    foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
+      set(${component}-${name} ${component})
+      set(install-${component}-${name} ${component})
+      list(APPEND ${name}_extra_targets ${component}-${name} install-${component}-${name})
     endforeach()
 
     if(LLVM_INCLUDE_TESTS)
-      list(APPEND ${name}_test_targets
-        "runtimes-test-depends:runtimes-test-depends-${name}"
-        "check-runtimes:check-runtimes-${name}")
+      set(runtimes-test-depends-${name} runtimes-test-depends)
+      set(check-runtimes-${name} check-runtimes)
+      list(APPEND ${name}_test_targets runtimes-test-depends-${name} check-runtimes-${name})
       foreach(target_name IN LISTS SUB_CHECK_TARGETS)
-        list(APPEND ${name}_test_targets "${target_name}:${target_name}-${name}")
-        list(APPEND test_targets "${target_name}-${name}")
+        set(${target_name}-${name} ${target_name})
+        list(APPEND ${name}_test_targets ${target_name}-${name})
+        list(APPEND test_targets ${target_name}-${name})
       endforeach()
       set(test_targets "${test_targets}" PARENT_SCOPE)
     endif()
 
     get_cmake_property(variableNames VARIABLES)
     foreach(variableName ${variableNames})
-      if(variableName MATCHES "^RUNTIMES_${name}")
+      string(FIND "${variableName}" "RUNTIMES_${name}_" out)
+      if("${out}" EQUAL 0)
         string(REPLACE "RUNTIMES_${name}_" "" new_name ${variableName})
         list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
-      elseif(variableName MATCHES "^RUNTIMES_${target}")
+      endif()
+      string(FIND "${variableName}" "RUNTIMES_${target}_" out)
+      if("${out}" EQUAL 0)
         string(REPLACE "RUNTIMES_${target}_" "" new_name ${variableName})
         list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
       endif()
     endforeach()
 
+    if(target IN_LIST LLVM_RUNTIME_BUILD_ID_LINK_TARGETS)
+      list(APPEND EXTRA_ARGS STRIP_TOOL ${CMAKE_CURRENT_BINARY_DIR}/llvm-strip-link)
+    endif()
+
     llvm_ExternalProject_Add(runtimes-${name}
                              ${CMAKE_CURRENT_SOURCE_DIR}
-                             DEPENDS ${${name}_deps}
+                             DEPENDS ${${name}_deps} ${CXX_HEADER_TARGET}
                              # Builtins were built separately above
                              CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
                                         -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
-                                        -DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR}
+                                        -DLLVM_DEFAULT_TARGET_TRIPLE=${target}
+                                        -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
+                                        -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
                                         -DCMAKE_C_COMPILER_TARGET=${target}
                                         -DCMAKE_CXX_COMPILER_TARGET=${target}
                                         -DCMAKE_ASM_COMPILER_TARGET=${target}
@@ -443,7 +483,7 @@ else() # if this is included from LLVM's CMake
                                         -DLLVM_RUNTIMES_TARGET=${name}
                                         ${${name}_extra_args}
                              PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
-                             TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib
+                             TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib llvm-nm llvm-objcopy llvm-objdump llvm-strip
                              EXTRA_TARGETS ${${name}_extra_targets}
                                            ${${name}_test_targets}
                              USE_TOOLCHAIN
@@ -456,13 +496,13 @@ else() # if this is included from LLVM's CMake
     # together in a single CMake invocaiton.
     if(NOT LLVM_RUNTIME_TARGETS)
       runtime_default_target(
-        DEPS ${deps}
-        PREFIXES ${prefixes}
-        )
+        DEPENDS ${deps}
+        PREFIXES ${prefixes})
+      set(test_targets check-runtimes)
     else()
       if("default" IN_LIST LLVM_RUNTIME_TARGETS)
         runtime_default_target(
-          DEPS ${deps}
+          DEPENDS ${deps}
           PREFIXES ${prefixes})
         list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
       else()
@@ -475,20 +515,17 @@ else() # if this is included from LLVM's CMake
           add_custom_target(runtimes-test-depends)
           set(test_targets "")
         endif()
+        if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
+          foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
+            add_custom_target(${component})
+            add_custom_target(install-${component})
+          endforeach()
+        endif()
       endif()
 
       foreach(name ${LLVM_RUNTIME_TARGETS})
-        set(target ${name})
-        string(REPLACE ":" ";" target_list ${target})
-        list(GET target_list 0 name)
-        list(LENGTH target_list target_list_len)
-        if(${target_list_len} GREATER 1)
-          list(GET target_list 1 target)
-        endif()
-
-        runtime_register_target(${name} ${target}
-          DEPS ${deps}
-          )
+        runtime_register_target(${name} ${name}
+          DEPENDS ${deps})
 
         add_dependencies(runtimes runtimes-${name})
         add_dependencies(runtimes-configure runtimes-${name}-configure)
@@ -499,6 +536,19 @@ else() # if this is included from LLVM's CMake
           add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
         endif()
       endforeach()
+
+      foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
+        foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
+          runtime_register_target(${name}+${multilib} ${name}
+            DEPENDS runtimes-${name}
+            CMAKE_ARGS -DLLVM_RUNTIMES_PREFIX=${name}/
+                       -DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib})
+          add_dependencies(runtimes runtimes-${name}+${multilib})
+          add_dependencies(runtimes-configure runtimes-${name}+${multilib}-configure)
+          add_dependencies(install-runtimes install-runtimes-${name}+${multilib})
+          add_dependencies(install-runtimes-stripped install-runtimes-${name}+${multilib}-stripped)
+        endforeach()
+      endforeach()
     endif()
 
     # TODO: This is a hack needed because the libcxx headers are copied into the
@@ -524,6 +574,8 @@ else() # if this is included from LLVM's CMake
           obj2yaml
           sancov
           sanstats
+          gtest_main
+          gtest
         )
       foreach(target ${test_targets} ${SUB_CHECK_TARGETS})
         add_dependencies(${target} ${RUNTIMES_TEST_DEPENDS})