OSDN Git Service

[GlobalISel][AArch64] Legalize vector G_SELECT
[android-x86/external-llvm.git] / runtimes / CMakeLists.txt
1 # This file handles building LLVM runtime sub-projects.
2
3 # Runtimes are different from tools or other drop-in projects because runtimes
4 # should be built with the LLVM toolchain from the build directory. This file is
5 # a first step to formalizing runtime build interfaces.
6
7 # In the current state this file only works with compiler-rt, other runtimes
8 # will work as the runtime build interface standardizes.
9
10 # Find all subdirectories containing CMake projects
11 file(GLOB entries *)
12 foreach(entry ${entries})
13   if(IS_DIRECTORY ${entry} AND EXISTS ${entry}/CMakeLists.txt)
14     list(APPEND runtimes ${entry})
15   endif()
16 endforeach()
17
18 # Side-by-side subprojects layout.
19 set(LLVM_ALL_RUNTIMES "libcxx;libcxxabi;libunwind;compiler-rt")
20 set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
21   "Semicolon-separated list of runtimes to build (${LLVM_ALL_RUNTIMES}), or \"all\".")
22 if(LLVM_ENABLE_RUNTIMES STREQUAL "all" )
23   set(LLVM_ENABLE_RUNTIMES ${LLVM_ALL_RUNTIMES})
24 endif()
25 foreach(proj ${LLVM_ENABLE_RUNTIMES})
26   set(proj_dir "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
27   if(IS_DIRECTORY ${proj_dir} AND EXISTS ${proj_dir}/CMakeLists.txt)
28     list(APPEND runtimes ${proj_dir})
29   else()
30     message(FATAL_ERROR "LLVM_ENABLE_RUNTIMES requests ${proj} but directory not found: ${proj_dir}")
31   endif()
32   string(TOUPPER "${proj}" canon_name)
33   STRING(REGEX REPLACE "-" "_" canon_name ${canon_name})
34   set(LLVM_EXTERNAL_${canon_name}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
35 endforeach()
36
37 function(get_compiler_rt_path path)
38   foreach(entry ${runtimes})
39     get_filename_component(projName ${entry} NAME)
40     if("${projName}" MATCHES "compiler-rt")
41       set(${path} ${entry} PARENT_SCOPE)
42       return()
43     endif()
44   endforeach()
45 endfunction()
46
47 # If this file is acting as a top-level CMake invocation, this code path is
48 # triggered by the external project call for the runtimes target below.
49 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
50
51   function(runtime_register_component name)
52     set_property(GLOBAL APPEND PROPERTY SUB_COMPONENTS ${name})
53   endfunction()
54
55   cmake_minimum_required(VERSION 3.4.3)
56   project(Runtimes C CXX ASM)
57
58   # Add the root project's CMake modules, and the LLVM build's modules to the
59   # CMake module path.
60   list(INSERT CMAKE_MODULE_PATH 0
61     "${CMAKE_CURRENT_SOURCE_DIR}/../cmake"
62     "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules"
63     "${LLVM_LIBRARY_DIR}/cmake/llvm"
64   )
65
66   # Some of the runtimes will conditionally use the compiler-rt sanitizers
67   # to make this work smoothly we ensure that compiler-rt is added first in
68   # the list of sub-projects. This allows other sub-projects to have checks
69   # like `if(TARGET asan)` to enable building with asan.
70   get_compiler_rt_path(compiler_rt_path)
71   if(compiler_rt_path)
72     list(REMOVE_ITEM runtimes ${compiler_rt_path})
73     if(NOT LLVM_BUILD_COMPILER_RT)
74       list(INSERT runtimes 0 ${compiler_rt_path})
75     endif()
76   endif()
77
78   # LLVMConfig.cmake contains a bunch of CMake variables from the LLVM build.
79   # This file is installed as part of LLVM distributions, so this can be used
80   # either from a build directory or an installed LLVM.
81   include(LLVMConfig)
82
83   # Setting these variables will allow the sub-build to put their outputs into
84   # the library and bin directories of the top-level build.
85   set(LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_DIR})
86   set(LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_TOOLS_BINARY_DIR})
87
88   # This variable makes sure that e.g. llvm-lit is found.
89   set(LLVM_MAIN_SRC_DIR ${LLVM_BUILD_MAIN_SRC_DIR})
90   set(LLVM_CMAKE_PATH ${LLVM_MAIN_SRC_DIR}/cmake/modules)
91
92   if(APPLE)
93     set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
94   endif()
95
96   include(CheckLibraryExists)
97   include(CheckCCompilerFlag)
98
99   # We don't have libc++ (yet).
100   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
101
102   # Avoid checking whether the compiler is working.
103   set(LLVM_COMPILER_CHECKED ON)
104
105   # Enable warnings, otherwise -w gets added to the cflags by HandleLLVMOptions
106   # resulting in unjustified successes by check_cxx_compiler_flag.
107   set(LLVM_ENABLE_WARNINGS ON)
108
109   # Handle common options used by all runtimes.
110   include(AddLLVM)
111   include(HandleLLVMOptions)
112   include(FindPythonInterp)
113
114   # Remove the -nostdlib++ option we've added earlier.
115   string(REPLACE "-nostdlib++" "" CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
116
117   # This can be used to detect whether we're in the runtimes build.
118   set(RUNTIMES_BUILD ON)
119
120   foreach(entry ${runtimes})
121     get_filename_component(projName ${entry} NAME)
122
123     # TODO: Clean this up as part of an interface standardization
124     string(REPLACE "-" "_" canon_name ${projName})
125     string(TOUPPER ${canon_name} canon_name)
126
127     if(LLVM_RUNTIMES_LIBDIR_SUFFIX)
128       set(${canon_name}_LIBDIR_SUFFIX "${LLVM_RUNTIMES_LIBDIR_SUFFIX}" CACHE STRING "" FORCE)
129     endif()
130
131     # Setting a variable to let sub-projects detect which other projects
132     # will be included under here.
133     set(HAVE_${canon_name} ON)
134   endforeach()
135
136   # We do this in two loops so that HAVE_* is set for each runtime before the
137   # other runtimes are added.
138   foreach(entry ${runtimes})
139     get_filename_component(projName ${entry} NAME)
140
141     # Between each sub-project we want to cache and clear the LIT properties
142     set_property(GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
143     set_property(GLOBAL PROPERTY LLVM_LIT_PARAMS)
144     set_property(GLOBAL PROPERTY LLVM_LIT_DEPENDS)
145     set_property(GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
146
147     add_subdirectory(${entry} ${projName})
148
149     get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
150     get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
151     get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
152     get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
153
154     list(APPEND RUNTIMES_LIT_TESTSUITES ${LLVM_LIT_TESTSUITES})
155     list(APPEND RUNTIMES_LIT_PARAMS ${LLVM_LIT_PARAMS})
156     list(APPEND RUNTIMES_LIT_DEPENDS ${LLVM_LIT_DEPENDS})
157     list(APPEND RUNTIMES_LIT_EXTRA_ARGS ${LLVM_LIT_EXTRA_ARGS})
158   endforeach()
159
160   if(LLVM_INCLUDE_TESTS)
161     # Add a global check rule now that all subdirectories have been traversed
162     # and we know the total set of lit testsuites.
163
164     add_lit_target(check-runtimes
165       "Running all regression tests"
166       ${RUNTIMES_LIT_TESTSUITES}
167       PARAMS ${RUNTIMES_LIT_PARAMS}
168       DEPENDS ${RUNTIMES_LIT_DEPENDS}
169       ARGS ${RUNTIMES_LIT_EXTRA_ARGS}
170       )
171     add_custom_target(runtimes-test-depends DEPENDS ${RUNTIMES_LIT_DEPENDS})
172   endif()
173
174   get_property(SUB_COMPONENTS GLOBAL PROPERTY SUB_COMPONENTS)
175   if(SUB_COMPONENTS)
176     list(REMOVE_DUPLICATES SUB_COMPONENTS)
177     foreach(component ${SUB_COMPONENTS})
178       if(NOT TARGET ${component})
179         message(SEND_ERROR "Missing target for runtime component ${component}!")
180         continue()
181       endif()
182
183       if(TARGET check-${component})
184         list(APPEND SUB_CHECK_TARGETS check-${component})
185       endif()
186
187       if(TARGET install-${component})
188         list(APPEND SUB_INSTALL_TARGETS install-${component})
189       endif()
190       if(TARGET install-${component}-stripped)
191         list(APPEND SUB_INSTALL_TARGETS install-${component}-stripped)
192       endif()
193     endforeach()
194
195     if(LLVM_RUNTIMES_TARGET)
196       configure_file(
197         ${CMAKE_CURRENT_SOURCE_DIR}/Components.cmake.in
198         ${LLVM_BINARY_DIR}/runtimes/${LLVM_RUNTIMES_TARGET}/Components.cmake)
199     else()
200       configure_file(
201         ${CMAKE_CURRENT_SOURCE_DIR}/Components.cmake.in
202         ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
203     endif()
204   endif()
205
206 else() # if this is included from LLVM's CMake
207   include(LLVMExternalProjectUtils)
208
209   if(NOT LLVM_BUILD_RUNTIMES)
210     set(EXTRA_ARGS EXCLUDE_FROM_ALL)
211   endif()
212
213   function(builtin_default_target compiler_rt_path)
214     cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
215
216     llvm_ExternalProject_Add(builtins
217                              ${compiler_rt_path}/lib/builtins
218                              DEPENDS ${ARG_DEPENDS}
219                              CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
220                                         -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
221                                         -DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_TRIPLE}
222                                         -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
223                                         -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE}
224                                         -DCMAKE_ASM_COMPILER_TARGET=${TARGET_TRIPLE}
225                                         -DCMAKE_C_COMPILER_WORKS=ON
226                                         -DCMAKE_ASM_COMPILER_WORKS=ON
227                              PASSTHROUGH_PREFIXES COMPILER_RT
228                              USE_TOOLCHAIN
229                              ${EXTRA_ARGS})
230   endfunction()
231
232   function(builtin_register_target compiler_rt_path target)
233     cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
234
235     string(REPLACE "-" ";" builtin_target_list ${target})
236     foreach(item ${builtin_target_list})
237       string(TOLOWER "${item}" item_lower)
238       if(item_lower MATCHES "darwin")
239         message(FATAL_ERROR "LLVM_BUILTIN_TARGETS isn't implemented for Darwin platform!")
240       endif()
241     endforeach()
242
243     get_cmake_property(variableNames VARIABLES)
244     foreach(variableName ${variableNames})
245       if(variableName MATCHES "^BUILTINS_${target}")
246         string(REPLACE "BUILTINS_${target}_" "" new_name ${variableName})
247         list(APPEND ${target}_extra_args "-D${new_name}=${${variableName}}")
248       endif()
249     endforeach()
250
251     llvm_ExternalProject_Add(builtins-${target}
252                              ${compiler_rt_path}/lib/builtins
253                              DEPENDS ${ARG_DEPENDS}
254                              CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
255                                         -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
256                                         -DLLVM_DEFAULT_TARGET_TRIPLE=${target}
257                                         -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
258                                         -DCMAKE_C_COMPILER_TARGET=${target}
259                                         -DCMAKE_ASM_COMPILER_TARGET=${target}
260                                         -DCMAKE_C_COMPILER_WORKS=ON
261                                         -DCMAKE_ASM_COMPILER_WORKS=ON
262                                         -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
263                                         ${${target}_extra_args}
264                              TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib llvm-nm llvm-objcopy llvm-objdump llvm-strip
265                              USE_TOOLCHAIN
266                              ${EXTRA_ARGS})
267   endfunction()
268
269   # If compiler-rt is present we need to build the builtin libraries first. This
270   # is required because the other runtimes need the builtin libraries present
271   # before the just-built compiler can pass the configuration tests.
272   get_compiler_rt_path(compiler_rt_path)
273   if(compiler_rt_path)
274     if(NOT LLVM_BUILTIN_TARGETS)
275       builtin_default_target(${compiler_rt_path}
276         DEPENDS clang-headers)
277     else()
278       if("default" IN_LIST LLVM_BUILTIN_TARGETS)
279         builtin_default_target(${compiler_rt_path}
280           DEPENDS clang-headers)
281         list(REMOVE_ITEM LLVM_BUILTIN_TARGETS "default")
282       else()
283         add_custom_target(builtins)
284         add_custom_target(install-builtins)
285         add_custom_target(install-builtins-stripped)
286       endif()
287
288       foreach(target ${LLVM_BUILTIN_TARGETS})
289         builtin_register_target(${compiler_rt_path} ${target}
290           DEPENDS clang-headers)
291
292         add_dependencies(builtins builtins-${target})
293         add_dependencies(install-builtins install-builtins-${target})
294         add_dependencies(install-builtins-stripped install-builtins-${target}-stripped)
295       endforeach()
296     endif()
297     set(deps builtins)
298     # We don't need to depend on the builtins if we're building instrumented
299     # because the next stage will use the same compiler used to build this stage.
300     if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
301       add_dependencies(clang-bootstrap-deps builtins)
302     endif()
303   endif()
304
305   # We create a list the names of all the runtime projects in all uppercase and
306   # with dashes turned to underscores. This gives us the CMake variable prefixes
307   # for all variables that will apply to runtimes.
308   foreach(entry ${runtimes})
309     get_filename_component(projName ${entry} NAME)
310     string(REPLACE "-" "_" canon_name ${projName})
311     string(TOUPPER ${canon_name} canon_name)
312     list(APPEND prefixes ${canon_name})
313
314     string(FIND ${projName} "lib" LIB_IDX)
315     if(LIB_IDX EQUAL 0)
316       string(SUBSTRING ${projName} 3 -1 projName)
317     endif()
318     list(APPEND runtime_names ${projName})
319   endforeach()
320
321   function(runtime_default_target)
322     cmake_parse_arguments(ARG "" "" "DEPENDS;PREFIXES" ${ARGN})
323
324     include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
325     set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
326
327     foreach(runtime_name ${runtime_names})
328       list(APPEND extra_targets
329         ${runtime_name}
330         install-${runtime_name}
331         install-${runtime_name}-stripped)
332       if(LLVM_INCLUDE_TESTS)
333         list(APPEND test_targets check-${runtime_name})
334       endif()
335     endforeach()
336     foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
337       if(NOT ${component} IN_LIST SUB_COMPONENTS)
338         list(APPEND extra_targets ${component} install-${component} install-${component}-stripped)
339       endif()
340     endforeach()
341
342     if(LLVM_INCLUDE_TESTS)
343       list(APPEND test_targets runtimes-test-depends check-runtimes)
344     endif()
345
346     llvm_ExternalProject_Add(runtimes
347                              ${CMAKE_CURRENT_SOURCE_DIR}
348                              DEPENDS ${ARG_DEPENDS}
349                              # Builtins were built separately above
350                              CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
351                                         -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
352                                         -DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR}
353                                         -DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_TRIPLE}
354                                         -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
355                                         -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE}
356                                         -DCMAKE_CXX_COMPILER_TARGET=${TARGET_TRIPLE}
357                                         -DCMAKE_ASM_COMPILER_TARGET=${TARGET_TRIPLE}
358                                         -DCMAKE_C_COMPILER_WORKS=ON
359                                         -DCMAKE_CXX_COMPILER_WORKS=ON
360                                         -DCMAKE_ASM_COMPILER_WORKS=ON
361                              PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
362                                                   ${ARG_PREFIXES}
363                              EXTRA_TARGETS ${extra_targets}
364                                            ${test_targets}
365                                            ${SUB_COMPONENTS}
366                                            ${SUB_CHECK_TARGETS}
367                                            ${SUB_INSTALL_TARGETS}
368                              USE_TOOLCHAIN
369                              ${EXTRA_ARGS})
370   endfunction()
371
372   # runtime_register_target(target)
373   #   Utility function to register external runtime target.
374   function(runtime_register_target name target)
375     cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
376     include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
377     set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
378
379     set(${name}_deps ${ARG_DEPENDS})
380     if(NOT name STREQUAL target)
381       list(APPEND ${name}_deps runtimes-${target})
382     endif()
383
384     foreach(runtime_name ${runtime_names})
385       set(${runtime_name}-${name} ${runtime_name})
386       set(install-${runtime_name}-${name} install-${runtime_name})
387       set(install-${runtime_name}-${name}-stripped install-${runtime_name}-stripped)
388       list(APPEND ${name}_extra_targets ${runtime_name}-${name} install-${runtime_name}-${name} install-${runtime_name}-${name}-stripped)
389       if(LLVM_INCLUDE_TESTS)
390         set(check-${runtime_name}-${name} check-${runtime_name} )
391         list(APPEND ${name}_test_targets check-${runtime_name}-${name})
392       endif()
393     endforeach()
394
395     foreach(target_name IN LISTS SUB_COMPONENTS SUB_INSTALL_TARGETS)
396       set(${target_name}-${name} ${target_name})
397       list(APPEND ${name}_extra_targets ${target_name}-${name})
398     endforeach()
399
400     foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
401       set(${component}-${name} ${component})
402       set(install-${component}-${name} ${component})
403       list(APPEND ${name}_extra_targets ${component}-${name} install-${component}-${name})
404     endforeach()
405
406     if(LLVM_INCLUDE_TESTS)
407       set(runtimes-test-depends-${name} runtimes-test-depends)
408       set(check-runtimes-${name} check-runtimes)
409       list(APPEND ${name}_test_targets runtimes-test-depends-${name} check-runtimes-${name})
410       foreach(target_name IN LISTS SUB_CHECK_TARGETS)
411         set(${target_name}-${name} ${target_name})
412         list(APPEND ${name}_test_targets ${target_name}-${name})
413         list(APPEND test_targets ${target_name}-${name})
414       endforeach()
415       set(test_targets "${test_targets}" PARENT_SCOPE)
416     endif()
417
418     get_cmake_property(variableNames VARIABLES)
419     foreach(variableName ${variableNames})
420       if(variableName MATCHES "^RUNTIMES_${name}")
421         string(REPLACE "RUNTIMES_${name}_" "" new_name ${variableName})
422         list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
423       elseif(variableName MATCHES "^RUNTIMES_${target}")
424         string(REPLACE "RUNTIMES_${target}_" "" new_name ${variableName})
425         list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
426       endif()
427     endforeach()
428
429     llvm_ExternalProject_Add(runtimes-${name}
430                              ${CMAKE_CURRENT_SOURCE_DIR}
431                              DEPENDS ${${name}_deps}
432                              # Builtins were built separately above
433                              CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
434                                         -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
435                                         -DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR}
436                                         -DLLVM_DEFAULT_TARGET_TRIPLE=${target}
437                                         -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
438                                         -DCMAKE_C_COMPILER_TARGET=${target}
439                                         -DCMAKE_CXX_COMPILER_TARGET=${target}
440                                         -DCMAKE_ASM_COMPILER_TARGET=${target}
441                                         -DCMAKE_C_COMPILER_WORKS=ON
442                                         -DCMAKE_CXX_COMPILER_WORKS=ON
443                                         -DCMAKE_ASM_COMPILER_WORKS=ON
444                                         -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
445                                         -DLLVM_RUNTIMES_TARGET=${name}
446                                         ${${name}_extra_args}
447                              PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
448                              TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib llvm-nm llvm-objcopy llvm-objdump llvm-strip
449                              EXTRA_TARGETS ${${name}_extra_targets}
450                                            ${${name}_test_targets}
451                              USE_TOOLCHAIN
452                              ${EXTRA_ARGS})
453   endfunction()
454
455   if(runtimes)
456     # Create a runtimes target that uses this file as its top-level CMake file.
457     # The runtimes target is a configuration of all the runtime libraries
458     # together in a single CMake invocaiton.
459     if(NOT LLVM_RUNTIME_TARGETS)
460       runtime_default_target(
461         DEPENDS ${deps}
462         PREFIXES ${prefixes})
463     else()
464       if("default" IN_LIST LLVM_RUNTIME_TARGETS)
465         runtime_default_target(
466           DEPENDS ${deps}
467           PREFIXES ${prefixes})
468         list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
469       else()
470         add_custom_target(runtimes)
471         add_custom_target(runtimes-configure)
472         add_custom_target(install-runtimes)
473         add_custom_target(install-runtimes-stripped)
474         if(LLVM_INCLUDE_TESTS)
475           add_custom_target(check-runtimes)
476           add_custom_target(runtimes-test-depends)
477           set(test_targets "")
478         endif()
479         if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
480           foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
481             add_custom_target(${component})
482             add_custom_target(install-${component})
483           endforeach()
484         endif()
485       endif()
486
487       foreach(name ${LLVM_RUNTIME_TARGETS})
488         runtime_register_target(${name} ${name}
489           DEPENDS ${deps})
490
491         add_dependencies(runtimes runtimes-${name})
492         add_dependencies(runtimes-configure runtimes-${name}-configure)
493         add_dependencies(install-runtimes install-runtimes-${name})
494         add_dependencies(install-runtimes-stripped install-runtimes-${name}-stripped)
495         if(LLVM_INCLUDE_TESTS)
496           add_dependencies(check-runtimes check-runtimes-${name})
497           add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
498         endif()
499       endforeach()
500
501       foreach(sanitizer ${LLVM_RUNTIME_SANITIZERS})
502         if (sanitizer STREQUAL "Address")
503           set(sanitizer_name "asan")
504         elseif (sanitizer STREQUAL "Memory")
505           set(sanitizer_name "msan")
506         elseif (sanitizer STREQUAL "Thread")
507           set(sanitizer_name "tsan")
508         elseif (sanitizer STREQUAL "Undefined")
509           set(sanitizer_name "ubsan")
510         else()
511           message(FATAL_ERROR "Unsupported value of LLVM_RUNTIME_TARGET_SANITIZERS: ${sanitizers}")
512         endif()
513         foreach(name ${LLVM_RUNTIME_SANITIZER_${sanitizer}_TARGETS})
514           runtime_register_target(${name}-${sanitizer_name} ${name}
515             DEPENDS runtimes-${name}
516             CMAKE_ARGS -DLLVM_USE_SANITIZER=${sanitizer}
517                        -DLLVM_RUNTIMES_PREFIX=${name}/
518                        -DLLVM_RUNTIMES_LIBDIR_SUFFIX=/${sanitizer_name})
519           add_dependencies(runtimes runtimes-${name}-${sanitizer_name})
520           add_dependencies(runtimes-configure runtimes-${name}-${sanitizer_name}-configure)
521           add_dependencies(install-runtimes install-runtimes-${name}-${sanitizer_name})
522           add_dependencies(install-runtimes-stripped install-runtimes-${name}-${sanitizer_name}-stripped)
523         endforeach()
524       endforeach()
525     endif()
526
527     # TODO: This is a hack needed because the libcxx headers are copied into the
528     # build directory during configuration. Without that step the clang in the
529     # build directory cannot find the C++ headers in certain configurations.
530     # I need to build a mechanism for runtime projects to provide CMake code
531     # that executes at LLVM configuration time to handle this case.
532     if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
533       add_dependencies(clang-bootstrap-deps runtimes-configure)
534     endif()
535
536     if(LLVM_INCLUDE_TESTS)
537       set_property(GLOBAL APPEND PROPERTY LLVM_ADDITIONAL_TEST_DEPENDS runtimes-test-depends)
538       set_property(GLOBAL APPEND PROPERTY LLVM_ADDITIONAL_TEST_TARGETS check-runtimes)
539
540       set(RUNTIMES_TEST_DEPENDS
541           FileCheck
542           count
543           llvm-nm
544           llvm-objdump
545           llvm-xray
546           not
547           obj2yaml
548           sancov
549           sanstats
550         )
551       foreach(target ${test_targets} ${SUB_CHECK_TARGETS})
552         add_dependencies(${target} ${RUNTIMES_TEST_DEPENDS})
553       endforeach()
554     endif()
555   endif()
556 endif()