Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / runtimes / CMakeLists.txt
bloba464c6c43af7b9c2bcc6ac706f0fb62895a3f052
1 # TODO: This file assumes the Clang toolchain so it'd be better if it lived in
2 # Clang, except there already is clang/runtime directory which contains
3 # similar although simpler functionality. We should figure out how to merge
4 # the two files.
6 set(COMMON_CMAKE_ARGS "-DHAVE_LLVM_LIT=ON")
7 foreach(proj ${LLVM_ENABLE_RUNTIMES})
8   set(proj_dir "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
9   if(IS_DIRECTORY ${proj_dir} AND EXISTS ${proj_dir}/CMakeLists.txt)
10     list(APPEND runtimes ${proj_dir})
11   else()
12     message(FATAL_ERROR "LLVM_ENABLE_RUNTIMES requests ${proj} but directory not found: ${proj_dir}")
13   endif()
14   string(TOUPPER "${proj}" canon_name)
15   STRING(REGEX REPLACE "-" "_" canon_name ${canon_name})
16   set(LLVM_EXTERNAL_${canon_name}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
17 endforeach()
19 function(get_compiler_rt_path path)
20   foreach(entry ${runtimes})
21     get_filename_component(projName ${entry} NAME)
22     if("${projName}" MATCHES "compiler-rt")
23       set(${path} ${entry} PARENT_SCOPE)
24       return()
25     endif()
26   endforeach()
27 endfunction()
29 include(LLVMExternalProjectUtils)
31 if(NOT LLVM_BUILD_RUNTIMES)
32   set(EXTRA_ARGS EXCLUDE_FROM_ALL)
33 endif()
35 function(check_apple_target triple builtin_or_runtime)
36   set(error "\
37 compiler-rt for Darwin builds for all platforms and architectures using a \
38 single configuration. Specify only a single darwin triple (e.g. x86_64-apple-darwin) \
39 in your targets list (and not a triple for a specific platform such as macos). \
40 You can use variables such as COMPILER_RT_ENABLE_IOS and DARWIN_ios_ARCHS to \
41 control the specific platforms and architectures to build.")
43   set(seen_property ${builtin_or_runtime}_darwin_triple_seen)
44   string(REPLACE "-" ";" triple_components ${triple})
45   foreach(component ${triple_components})
46     string(TOLOWER "${component}" component_lower)
47     if(component_lower MATCHES "^darwin")
48       get_property(darwin_triple_seen GLOBAL PROPERTY ${seen_property})
49       if(darwin_triple_seen)
50         message(FATAL_ERROR "${error}")
51       endif()
52       set_property(GLOBAL PROPERTY ${seen_property} YES)
53       if(NOT RUNTIMES_BUILD_ALLOW_DARWIN)
54         message(FATAL_ERROR "\
55 ${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.")
56       endif()
57     elseif(component_lower MATCHES "^ios|^macos|^tvos|^watchos")
58       message(FATAL_ERROR "${error}")
59     endif()
60   endforeach()
61 endfunction()
63 macro(set_enable_per_target_runtime_dir)
64   # May have been set by llvm/CMakeLists.txt.
65   if (NOT DEFINED LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
66     # AIX should fold 32-bit & 64-bit arch libraries into a single archive.
67     if (LLVM_TARGET_TRIPLE MATCHES "aix")
68       set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR OFF)
69     else()
70       set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON)
71     endif()
72   endif()
73 endmacro()
75 function(builtin_default_target compiler_rt_path)
76   cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
78   set_enable_per_target_runtime_dir()
80   llvm_ExternalProject_Add(builtins
81                            ${compiler_rt_path}/lib/builtins
82                            DEPENDS ${ARG_DEPENDS}
83                            CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
84                                       -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
85                                       -DLLVM_DEFAULT_TARGET_TRIPLE=${LLVM_TARGET_TRIPLE}
86                                       -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}
87                                       -DCMAKE_C_COMPILER_WORKS=ON
88                                       -DCMAKE_ASM_COMPILER_WORKS=ON
89                                       ${COMMON_CMAKE_ARGS}
90                                       ${BUILTINS_CMAKE_ARGS}
91                            PASSTHROUGH_PREFIXES COMPILER_RT
92                                                 DARWIN
93                                                 SANITIZER
94                            USE_TOOLCHAIN
95                            TARGET_TRIPLE ${LLVM_TARGET_TRIPLE}
96                            ${EXTRA_ARGS})
97 endfunction()
99 function(builtin_register_target compiler_rt_path name)
100   cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;EXTRA_ARGS" ${ARGN})
102   set(${name}_extra_args ${ARG_CMAKE_ARGS})
103   get_cmake_property(variable_names VARIABLES)
104   foreach(variable_name ${variable_names})
105     string(FIND "${variable_name}" "BUILTINS_${name}" out)
106     if("${out}" EQUAL 0)
107       string(REPLACE "BUILTINS_${name}_" "" new_name ${variable_name})
108       if(new_name STREQUAL CACHE_FILES)
109         foreach(cache IN LISTS ${variable_name})
110           list(APPEND ${name}_extra_args -C ${cache})
111         endforeach()
112       else()
113         string(REPLACE ";" "|" new_value "${${variable_name}}")
114         list(APPEND ${name}_extra_args "-D${new_name}=${new_value}")
115       endif()
116     endif()
117   endforeach()
119   llvm_ExternalProject_Add(builtins-${name}
120                            ${compiler_rt_path}/lib/builtins
121                            DEPENDS ${ARG_DEPENDS}
122                            CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
123                                       -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
124                                       -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
125                                       -DCMAKE_C_COMPILER_WORKS=ON
126                                       -DCMAKE_ASM_COMPILER_WORKS=ON
127                                       -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
128                                       ${COMMON_CMAKE_ARGS}
129                                       ${${name}_extra_args}
130                            USE_TOOLCHAIN
131                            ${EXTRA_ARGS} ${ARG_EXTRA_ARGS})
132 endfunction()
134 # If compiler-rt is present we need to build the builtin libraries first. This
135 # is required because the other runtimes need the builtin libraries present
136 # before the just-built compiler can pass the configuration tests.
137 get_compiler_rt_path(compiler_rt_path)
138 if(compiler_rt_path)
139   if(NOT LLVM_BUILTIN_TARGETS)
140     builtin_default_target(${compiler_rt_path}
141       DEPENDS clang-resource-headers)
142   else()
143     if("default" IN_LIST LLVM_BUILTIN_TARGETS)
144       builtin_default_target(${compiler_rt_path}
145         DEPENDS clang-resource-headers)
146       list(REMOVE_ITEM LLVM_BUILTIN_TARGETS "default")
147     else()
148       add_custom_target(builtins)
149       add_custom_target(install-builtins)
150       add_custom_target(install-builtins-stripped)
151     endif()
153     foreach(target ${LLVM_BUILTIN_TARGETS})
154       check_apple_target(${target} builtin)
156       builtin_register_target(${compiler_rt_path} ${target}
157         DEPENDS clang-resource-headers
158         CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${target}
159         EXTRA_ARGS TARGET_TRIPLE ${target})
161       add_dependencies(builtins builtins-${target})
162       add_dependencies(install-builtins install-builtins-${target})
163       add_dependencies(install-builtins-stripped install-builtins-${target}-stripped)
164     endforeach()
165   endif()
166   set(builtins_dep builtins)
167   # We don't need to depend on the builtins if we're building instrumented
168   # because the next stage will use the same compiler used to build this stage.
169   if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
170     add_dependencies(clang-bootstrap-deps builtins)
171   endif()
172 endif()
174 function(_get_runtime_name name out_var)
175   string(FIND ${name} "lib" idx)
176   if(idx EQUAL 0 AND NOT ${name} STREQUAL "libc")
177     string(SUBSTRING ${name} 3 -1 name)
178   endif()
179   set(${out_var} ${name} PARENT_SCOPE)
180 endfunction()
182 # Create a list with the names of all the runtime projects in all uppercase and
183 # with dashes turned to underscores. This gives us the CMake variable `prefixes`
184 # for all variables that will apply to runtimes.
185 foreach(entry ${runtimes})
186   get_filename_component(name ${entry} NAME)
187   string(REPLACE "-" "_" canon_name ${name})
188   string(TOUPPER ${canon_name} canon_name)
189   list(APPEND prefixes ${canon_name})
190   if (${canon_name} STREQUAL "OPENMP")
191     list(APPEND prefixes "LIBOMP" "LIBOMPTARGET")
192   endif()
193   # Many compiler-rt options start with SANITIZER_ and DARWIN_ rather than
194   # COMPILER_RT_, so when compiler-rt is enabled, consider both.
195   if(canon_name STREQUAL "COMPILER_RT")
196     list(APPEND prefixes SANITIZER DARWIN)
197   endif()
198   if(canon_name STREQUAL "LIBC")
199     list(APPEND prefixes "LLVM_LIBC")
200     list(APPEND prefixes "LIBC_")
201     # The `libc` project may require '-DCUDAToolkit_ROOT' in GPU mode.
202     if(LIBC_GPU_BUILD OR LIBC_GPU_ARCHITECTURES)
203       list(APPEND prefixes "CUDA")
204     endif()
205   endif()
207   _get_runtime_name(${name} name)
208   list(APPEND RUNTIME_NAMES ${name})
209 endforeach()
211 function(runtime_default_target)
212   cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;PREFIXES" ${ARGN})
214   include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
215   set(SUB_CHECK_TARGETS ${SUB_CHECK_TARGETS} PARENT_SCOPE)
216   set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
218   foreach(runtime_name ${RUNTIME_NAMES})
219     list(APPEND extra_targets
220       ${runtime_name}
221       install-${runtime_name}
222       install-${runtime_name}-stripped)
223     if(LLVM_INCLUDE_TESTS)
224       list(APPEND test_targets check-${runtime_name})
225     endif()
226   endforeach()
227   foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
228     if(NOT ${component} IN_LIST SUB_COMPONENTS)
229       list(APPEND extra_targets install-${component} install-${component}-stripped)
230     endif()
231   endforeach()
233   if(LLVM_INCLUDE_TESTS)
234     set_property(GLOBAL APPEND PROPERTY LLVM_ALL_LIT_TESTSUITES "@${LLVM_BINARY_DIR}/runtimes/runtimes-bins/lit.tests")
235     list(APPEND test_targets runtimes-test-depends check-runtimes)
236   endif()
238   set_enable_per_target_runtime_dir()
240   llvm_ExternalProject_Add(runtimes
241                            ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
242                            DEPENDS ${ARG_DEPENDS}
243                            # Builtins were built separately above
244                            CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
245                                       -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
246                                       -DLLVM_DEFAULT_TARGET_TRIPLE=${LLVM_TARGET_TRIPLE}
247                                       -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
248                                       -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}
249                                       -DLLVM_BUILD_TOOLS=${LLVM_BUILD_TOOLS}
250                                       -DCMAKE_C_COMPILER_WORKS=ON
251                                       -DCMAKE_CXX_COMPILER_WORKS=ON
252                                       -DCMAKE_ASM_COMPILER_WORKS=ON
253                                       ${COMMON_CMAKE_ARGS}
254                                       ${RUNTIMES_CMAKE_ARGS}
255                                       ${ARG_CMAKE_ARGS}
256                            PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
257                                                 LLVM_USE_LINKER
258                                                 ${ARG_PREFIXES}
259                            EXTRA_TARGETS ${extra_targets}
260                                          ${test_targets}
261                                          ${SUB_COMPONENTS}
262                                          ${SUB_CHECK_TARGETS}
263                                          ${SUB_INSTALL_TARGETS}
264                            USE_TOOLCHAIN
265                            TARGET_TRIPLE ${LLVM_TARGET_TRIPLE}
266                            ${EXTRA_ARGS})
267 endfunction()
269 # runtime_register_target(name)
270 #   Utility function to register external runtime target.
271 function(runtime_register_target name)
272   cmake_parse_arguments(ARG "" "BASE_NAME" "DEPENDS;CMAKE_ARGS;EXTRA_ARGS" ${ARGN})
273   include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
274   set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
276   set(runtime_names ${RUNTIME_NAMES})
277   foreach(_name IN ITEMS ${ARG_BASE_NAME} ${name})
278     if(RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)
279       set(runtime_names)
280       foreach(entry ${RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES})
281         _get_runtime_name(${entry} runtime_name)
282         list(APPEND runtime_names ${runtime_name})
283       endforeach()
284     endif()
285   endforeach()
287   foreach(runtime_name ${runtime_names})
288     set(${runtime_name}-${name} ${runtime_name})
289     set(install-${runtime_name}-${name} install-${runtime_name})
290     set(install-${runtime_name}-${name}-stripped install-${runtime_name}-stripped)
291     list(APPEND ${name}_extra_targets ${runtime_name}-${name} install-${runtime_name}-${name} install-${runtime_name}-${name}-stripped)
292     if(LLVM_INCLUDE_TESTS)
293       set(check-${runtime_name}-${name} check-${runtime_name} )
294       list(APPEND ${name}_test_targets check-${runtime_name}-${name})
295     endif()
296   endforeach()
298   foreach(component IN LISTS SUB_COMPONENTS)
299     set(${component}-${name} ${component})
300     list(APPEND ${name}_extra_targets ${component}-${name})
301   endforeach()
303   foreach(target IN LISTS SUB_INSTALL_TARGETS)
304     set(${target}-${name} ${target})
305     set(${target}-${name}-stripped ${target}-stripped)
306     list(APPEND ${name}_extra_targets ${target}-${name} ${target}-${name}-stripped)
307   endforeach()
309   foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
310     if(NOT component IN_LIST SUB_COMPONENTS)
311       set(${component}-${name} ${component})
312       set(install-${component}-${name} install-${component})
313       set(install-${component}-${name}-stripped install-${component}-stripped)
314       list(APPEND ${name}_extra_targets ${component}-${name} install-${component}-${name} install-${component}-${name}-stripped)
315     endif()
316   endforeach()
318   if(LLVM_INCLUDE_TESTS)
319     set_property(GLOBAL APPEND PROPERTY LLVM_ALL_LIT_TESTSUITES "@${LLVM_BINARY_DIR}/runtimes/runtimes-${name}-bins/lit.tests")
320     set(runtimes-test-depends-${name} runtimes-test-depends)
321     set(check-runtimes-${name} check-runtimes)
322     list(APPEND ${name}_test_targets runtimes-test-depends-${name} check-runtimes-${name})
323     list(APPEND test_targets ${${name}_test_targets})
325     set(component_check_targets)
326     foreach(component IN LISTS LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
327       if(NOT "check-${component}" IN_LIST SUB_CHECK_TARGETS)
328         list(APPEND component_check_targets "check-${component}")
329       endif()
330     endforeach()
332     foreach(target IN LISTS SUB_CHECK_TARGETS component_check_targets)
333       set(${target}-${name} ${target})
334       list(APPEND ${name}_test_targets ${target}-${name})
335       list(APPEND test_targets ${target}-${name})
336     endforeach()
337     set(test_targets "${test_targets}" PARENT_SCOPE)
338   endif()
340   set(${name}_extra_args ${ARG_CMAKE_ARGS})
341   string(REPLACE ";" "|" LLVM_ENABLE_RUNTIMES_PASSTHROUGH "${LLVM_ENABLE_RUNTIMES}")
342   list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH})
343   list(APPEND ${name}_extra_args -DLLVM_USE_LINKER=${LLVM_USE_LINKER})
345   get_cmake_property(variable_names VARIABLES)
346   foreach(extra_name IN ITEMS ${ARG_BASE_NAME} ${name})
347     foreach(variable_name ${variable_names})
348       string(FIND "${variable_name}" "RUNTIMES_${extra_name}_" out)
349       if("${out}" EQUAL 0)
350         string(REPLACE "RUNTIMES_${extra_name}_" "" new_name ${variable_name})
351         if(new_name STREQUAL CACHE_FILES)
352           foreach(cache IN LISTS ${variable_name})
353             list(APPEND ${name}_extra_args -C ${cache})
354           endforeach()
355         else()
356           string(REPLACE ";" "|" new_value "${${variable_name}}")
357           list(APPEND ${name}_extra_args "-D${new_name}=${new_value}")
358         endif()
359       endif()
360     endforeach()
361   endforeach()
363   set_enable_per_target_runtime_dir()
365   llvm_ExternalProject_Add(runtimes-${name}
366                            ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
367                            DEPENDS ${ARG_DEPENDS}
368                            # Builtins were built separately above
369                            CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=OFF
370                                       -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
371                                       -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
372                                       -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}
373                                       -DCMAKE_C_COMPILER_WORKS=ON
374                                       -DCMAKE_CXX_COMPILER_WORKS=ON
375                                       -DCMAKE_ASM_COMPILER_WORKS=ON
376                                       -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
377                                       -DLLVM_RUNTIMES_TARGET=${name}
378                                       ${COMMON_CMAKE_ARGS}
379                                       ${${name}_extra_args}
380                            EXTRA_TARGETS ${${name}_extra_targets}
381                                          ${${name}_test_targets}
382                            USE_TOOLCHAIN
383                            ${EXTRA_ARGS} ${ARG_EXTRA_ARGS})
385   add_dependencies(runtimes runtimes-${name})
386   add_dependencies(runtimes-configure runtimes-${name}-configure)
387   add_dependencies(install-runtimes install-runtimes-${name})
388   add_dependencies(install-runtimes-stripped install-runtimes-${name}-stripped)
389   if(LLVM_INCLUDE_TESTS)
390     add_dependencies(check-runtimes check-runtimes-${name})
391     add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
392   endif()
393   foreach(runtime_name ${runtime_names})
394     add_dependencies(${runtime_name} ${runtime_name}-${name})
395     add_dependencies(install-${runtime_name} install-${runtime_name}-${name})
396     add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}-stripped)
397   endforeach()
398   foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
399     add_dependencies(${component} ${component}-${name})
400     add_dependencies(install-${component} install-${component}-${name})
401     add_dependencies(install-${component}-stripped install-${component}-${name}-stripped)
402   endforeach()
403 endfunction()
405 if(runtimes)
406   # Create a runtimes target that uses this file as its top-level CMake file.
407   # The runtimes target is a configuration of all the runtime libraries
408   # together in a single CMake invocation.
409   set(extra_deps "")
410   if("openmp" IN_LIST LLVM_ENABLE_RUNTIMES)
411     foreach(dep opt llvm-link llvm-extract clang clang-offload-packager)
412       if(TARGET ${dep} AND OPENMP_ENABLE_LIBOMPTARGET)
413         list(APPEND extra_deps ${dep})
414       endif()
415     endforeach()
416   endif()
417   if("libc" IN_LIST LLVM_ENABLE_RUNTIMES AND 
418       (LLVM_LIBC_FULL_BUILD OR LIBC_GPU_BUILD OR LIBC_GPU_ARCHITECTURES))
419     if(TARGET libc-hdrgen)
420       set(libc_tools libc-hdrgen)
421       set(libc_cmake_args "-DLIBC_HDRGEN_EXE=$<TARGET_FILE:libc-hdrgen>"
422                           "-DLLVM_LIBC_FULL_BUILD=ON")
423       list(APPEND extra_deps ${libc_tools})
424     else()
425       # We want to build the libc build tools before we can build the libc
426       # itself. So, the libc project should be included in LLVM_ENABLE_PROJECTS.
427       # This should have been done in llvm/CMakeLists.txt automatically when
428       # "libc" is detected in LLVM_ENABLE_RUNTIMES.
429       message(FATAL_ERROR "libc-hdrgen target missing unexpectedly")
430     endif()
431     if(LIBC_GPU_BUILD OR LIBC_GPU_ARCHITECTURES)
432       foreach(dep clang-offload-packager nvptx-arch amdgpu-arch)
433         if(TARGET ${dep})
434           list(APPEND extra_deps ${dep})
435         endif()
436       endforeach()
437     endif()
438   endif()
439   if(NOT LLVM_RUNTIME_TARGETS)
440     runtime_default_target(
441       DEPENDS ${builtins_dep} ${extra_deps}
442       CMAKE_ARGS ${libc_cmake_args}
443       PREFIXES ${prefixes})
444     set(test_targets check-runtimes)
445   else()
446     if("default" IN_LIST LLVM_RUNTIME_TARGETS)
447       runtime_default_target(
448         DEPENDS ${builtins_dep} ${extra_deps}
449         CMAKE_ARGS ${libc_cmake_args}
450         PREFIXES ${prefixes})
451       list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
452     else()
453       add_custom_target(runtimes)
454       add_custom_target(runtimes-configure)
455       add_custom_target(install-runtimes)
456       add_custom_target(install-runtimes-stripped)
457       if(LLVM_INCLUDE_TESTS)
458         add_custom_target(check-runtimes)
459         add_custom_target(runtimes-test-depends)
460         set(test_targets "")
461       endif()
462       foreach(runtime_name ${RUNTIME_NAMES})
463         add_custom_target(${runtime_name})
464         add_custom_target(install-${runtime_name})
465         add_custom_target(install-${runtime_name}-stripped)
466       endforeach()
467       if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
468         foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
469           add_custom_target(${component})
470           add_custom_target(install-${component})
471           add_custom_target(install-${component}-stripped)
472         endforeach()
473       endif()
474     endif()
476     foreach(name ${LLVM_RUNTIME_TARGETS})
477       if(builtins_dep)
478         if (LLVM_BUILTIN_TARGETS)
479           set(builtins_dep_name "${builtins_dep}-${name}")
480         else()
481           set(builtins_dep_name ${builtins_dep})
482         endif()
483       endif()
485       check_apple_target(${name} runtime)
487       runtime_register_target(${name}
488         DEPENDS ${builtins_dep_name} ${libc_tools}
489         CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${libc_cmake_args}
490         EXTRA_ARGS TARGET_TRIPLE ${name})
491     endforeach()
493     foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
494       foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
495         runtime_register_target(${name}+${multilib}
496           DEPENDS runtimes-${name}
497           CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name}
498                      -DLLVM_RUNTIMES_PREFIX=${name}/
499                      -DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
500           BASE_NAME ${name}
501           EXTRA_ARGS TARGET_TRIPLE ${name})
502       endforeach()
503     endforeach()
504   endif()
506   if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
507     # TODO: This is a hack needed because the libcxx headers are copied into the
508     # build directory during configuration. Without that step the clang in the
509     # build directory cannot find the C++ headers in certain configurations.
510     # I need to build a mechanism for runtime projects to provide CMake code
511     # that executes at LLVM configuration time to handle this case.
512     add_dependencies(clang-bootstrap-deps runtimes-configure)
513     # We need to add the runtimes as a dependency because compiler-rt can be
514     # built as part of runtimes and we need the profile runtime for PGO
515     add_dependencies(clang-bootstrap-deps runtimes)
516   endif()
518   if(LLVM_INCLUDE_TESTS)
519     set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_DEPENDS runtimes-test-depends)
521     set(RUNTIMES_TEST_DEPENDS
522         FileCheck
523         count
524         llvm-cov
525         llvm-nm
526         llvm-objdump
527         llvm-profdata
528         llvm-size
529         llvm-xray
530         not
531         obj2yaml
532         sancov
533         sanstats
534         llvm_gtest_main
535         llvm_gtest
536         split-file
537       )
538     foreach(target ${test_targets} ${SUB_CHECK_TARGETS})
539       add_dependencies(${target} ${RUNTIMES_TEST_DEPENDS})
540     endforeach()
542     set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_TARGETS runtimes ${RUNTIMES_TEST_DEPENDS})
543   endif()
544 endif()