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.
5
6# TODO: Selecting runtimes should be always performed inside the runtimes
7# build, see runtimes/CMakeLists.txt, except that we currently check whether
8# compiler-rt is being built to determine whether to first build builtins
9# or not so we need that information in this file as well.
10set(LLVM_ALL_RUNTIMES "compiler-rt;libc;libcxx;libcxxabi;libunwind;openmp")
11set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
12  "Semicolon-separated list of runtimes to build (${LLVM_ALL_RUNTIMES}), or \"all\".")
13if(LLVM_ENABLE_RUNTIMES STREQUAL "all" )
14  set(LLVM_ENABLE_RUNTIMES ${LLVM_ALL_RUNTIMES})
15endif()
16set(COMMON_CMAKE_ARGS "-DHAVE_LLVM_LIT=ON")
17foreach(proj ${LLVM_ENABLE_RUNTIMES})
18  set(proj_dir "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
19  if(IS_DIRECTORY ${proj_dir} AND EXISTS ${proj_dir}/CMakeLists.txt)
20    list(APPEND runtimes ${proj_dir})
21  else()
22    message(FATAL_ERROR "LLVM_ENABLE_RUNTIMES requests ${proj} but directory not found: ${proj_dir}")
23  endif()
24  string(TOUPPER "${proj}" canon_name)
25  STRING(REGEX REPLACE "-" "_" canon_name ${canon_name})
26  set(LLVM_EXTERNAL_${canon_name}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
27endforeach()
28
29function(get_compiler_rt_path path)
30  foreach(entry ${runtimes})
31    get_filename_component(projName ${entry} NAME)
32    if("${projName}" MATCHES "compiler-rt")
33      set(${path} ${entry} PARENT_SCOPE)
34      return()
35    endif()
36  endforeach()
37endfunction()
38
39include(LLVMExternalProjectUtils)
40
41if(NOT LLVM_BUILD_RUNTIMES)
42  set(EXTRA_ARGS EXCLUDE_FROM_ALL)
43endif()
44
45function(check_apple_target triple builtin_or_runtime)
46  set(error "\
47compiler-rt for Darwin builds for all platforms and architectures using a \
48single configuration. Specify only a single darwin triple (e.g. x86_64-apple-darwin) \
49in your targets list (and not a triple for a specific platform such as macos). \
50You can use variables such as COMPILER_RT_ENABLE_IOS and DARWIN_ios_ARCHS to \
51control the specific platforms and architectures to build.")
52
53  set(seen_property ${builtin_or_runtime}_darwin_triple_seen)
54  string(REPLACE "-" ";" triple_components ${triple})
55  foreach(component ${triple_components})
56    string(TOLOWER "${component}" component_lower)
57    if(component_lower MATCHES "^darwin")
58      get_property(darwin_triple_seen GLOBAL PROPERTY ${seen_property})
59      if(darwin_triple_seen)
60        message(FATAL_ERROR "${error}")
61      endif()
62      set_property(GLOBAL PROPERTY ${seen_property} YES)
63      if(NOT RUNTIMES_BUILD_ALLOW_DARWIN)
64        message(FATAL_ERROR "\
65${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.")
66      endif()
67    elseif(component_lower MATCHES "^ios|^macos|^tvos|^watchos")
68      message(FATAL_ERROR "${error}")
69    endif()
70  endforeach()
71endfunction()
72
73function(builtin_default_target compiler_rt_path)
74  cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
75
76  set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default ON)
77  # AIX should fold 32-bit & 64-bit arch libraries into a single archive.
78  if (LLVM_TARGET_TRIPLE MATCHES "aix")
79    set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default OFF)
80  endif()
81
82  llvm_ExternalProject_Add(builtins
83                           ${compiler_rt_path}/lib/builtins
84                           DEPENDS ${ARG_DEPENDS}
85                           CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
86                                      -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
87                                      -DLLVM_DEFAULT_TARGET_TRIPLE=${LLVM_TARGET_TRIPLE}
88                                      -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default}
89                                      -DCMAKE_C_COMPILER_WORKS=ON
90                                      -DCMAKE_ASM_COMPILER_WORKS=ON
91                                      ${COMMON_CMAKE_ARGS}
92                                      ${BUILTINS_CMAKE_ARGS}
93                           PASSTHROUGH_PREFIXES COMPILER_RT
94                                                DARWIN
95                                                SANITIZER
96                           USE_TOOLCHAIN
97                           TARGET_TRIPLE ${LLVM_TARGET_TRIPLE}
98                           ${EXTRA_ARGS})
99endfunction()
100
101function(builtin_register_target compiler_rt_path target)
102  cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
103
104  check_apple_target(${target} builtin)
105
106  get_cmake_property(variableNames VARIABLES)
107  foreach(variableName ${variableNames})
108    string(FIND "${variableName}" "BUILTINS_${target}" out)
109    if("${out}" EQUAL 0)
110      string(REPLACE "BUILTINS_${target}_" "" new_name ${variableName})
111      string(REPLACE ";" "|" new_value "${${variableName}}")
112      list(APPEND ${target}_extra_args "-D${new_name}=${new_value}")
113    endif()
114  endforeach()
115
116  llvm_ExternalProject_Add(builtins-${target}
117                           ${compiler_rt_path}/lib/builtins
118                           DEPENDS ${ARG_DEPENDS}
119                           CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
120                                      -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
121                                      -DLLVM_DEFAULT_TARGET_TRIPLE=${target}
122                                      -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
123                                      -DCMAKE_C_COMPILER_WORKS=ON
124                                      -DCMAKE_ASM_COMPILER_WORKS=ON
125                                      -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
126                                      ${COMMON_CMAKE_ARGS}
127                                      ${${target}_extra_args}
128                           USE_TOOLCHAIN
129                           TARGET_TRIPLE ${target}
130                           ${EXTRA_ARGS})
131endfunction()
132
133# If compiler-rt is present we need to build the builtin libraries first. This
134# is required because the other runtimes need the builtin libraries present
135# before the just-built compiler can pass the configuration tests.
136get_compiler_rt_path(compiler_rt_path)
137if(compiler_rt_path)
138  if(NOT LLVM_BUILTIN_TARGETS)
139    builtin_default_target(${compiler_rt_path}
140      DEPENDS clang-resource-headers)
141  else()
142    if("default" IN_LIST LLVM_BUILTIN_TARGETS)
143      builtin_default_target(${compiler_rt_path}
144        DEPENDS clang-resource-headers)
145      list(REMOVE_ITEM LLVM_BUILTIN_TARGETS "default")
146    else()
147      add_custom_target(builtins)
148      add_custom_target(install-builtins)
149      add_custom_target(install-builtins-stripped)
150    endif()
151
152    foreach(target ${LLVM_BUILTIN_TARGETS})
153      builtin_register_target(${compiler_rt_path} ${target}
154        DEPENDS clang-resource-headers)
155
156      add_dependencies(builtins builtins-${target})
157      add_dependencies(install-builtins install-builtins-${target})
158      add_dependencies(install-builtins-stripped install-builtins-${target}-stripped)
159    endforeach()
160  endif()
161  set(deps builtins)
162  # We don't need to depend on the builtins if we're building instrumented
163  # because the next stage will use the same compiler used to build this stage.
164  if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
165    add_dependencies(clang-bootstrap-deps builtins)
166  endif()
167endif()
168
169# Create a list with the names of all the runtime projects in all uppercase and
170# with dashes turned to underscores. This gives us the CMake variable `prefixes`
171# for all variables that will apply to runtimes.
172foreach(entry ${runtimes})
173  get_filename_component(projName ${entry} NAME)
174  if(projName STREQUAL "libc")
175    # For now, we will use the name "llvmlibc" for the libc project as it is
176    # not a full libc yet. Also, if we leave it as is, the "lib" prefix gets
177    # stripped below and the targets endup having the name "c", "check-c" etc.
178    set(projName "llvmlibc")
179  endif()
180  string(REPLACE "-" "_" canon_name ${projName})
181  string(TOUPPER ${canon_name} canon_name)
182  list(APPEND prefixes ${canon_name})
183  if (${canon_name} STREQUAL "OPENMP")
184    list(APPEND prefixes "LIBOMP" "LIBOMPTARGET")
185  endif()
186  # Many compiler-rt options start with SANITIZER_ and DARWIN_ rather than
187  # COMPILER_RT_, so when compiler-rt is enabled, consider both.
188  if(canon_name STREQUAL "COMPILER_RT")
189    list(APPEND prefixes SANITIZER DARWIN)
190  endif()
191
192  string(FIND ${projName} "lib" LIB_IDX)
193  if(LIB_IDX EQUAL 0)
194    string(SUBSTRING ${projName} 3 -1 projName)
195  endif()
196  list(APPEND runtime_names ${projName})
197endforeach()
198
199function(runtime_default_target)
200  cmake_parse_arguments(ARG "" "" "DEPENDS;PREFIXES" ${ARGN})
201
202  include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
203  set(SUB_CHECK_TARGETS ${SUB_CHECK_TARGETS} PARENT_SCOPE)
204  set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
205
206  foreach(runtime_name ${runtime_names})
207    list(APPEND extra_targets
208      ${runtime_name}
209      install-${runtime_name}
210      install-${runtime_name}-stripped)
211    if(LLVM_INCLUDE_TESTS)
212      list(APPEND test_targets check-${runtime_name})
213    endif()
214  endforeach()
215  foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
216    if(NOT ${component} IN_LIST SUB_COMPONENTS)
217      list(APPEND extra_targets install-${component} install-${component}-stripped)
218    endif()
219  endforeach()
220
221  if(LLVM_INCLUDE_TESTS)
222    set_property(GLOBAL APPEND PROPERTY LLVM_ALL_LIT_TESTSUITES "@${LLVM_BINARY_DIR}/runtimes/Tests.rsp")
223    list(APPEND test_targets runtimes-test-depends check-runtimes)
224  endif()
225
226  set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default ON)
227  # AIX should fold 32-bit & 64-bit arch libraries into a single archive.
228  if (LLVM_TARGET_TRIPLE MATCHES "aix")
229    set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default OFF)
230  endif()
231
232  llvm_ExternalProject_Add(runtimes
233                           ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
234                           DEPENDS ${ARG_DEPENDS}
235                           # Builtins were built separately above
236                           CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
237                                      -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
238                                      -DLLVM_DEFAULT_TARGET_TRIPLE=${LLVM_TARGET_TRIPLE}
239                                      -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
240                                      -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default}
241                                      -DLLVM_BUILD_TOOLS=${LLVM_BUILD_TOOLS}
242                                      -DCMAKE_C_COMPILER_WORKS=ON
243                                      -DCMAKE_CXX_COMPILER_WORKS=ON
244                                      -DCMAKE_ASM_COMPILER_WORKS=ON
245                                      ${COMMON_CMAKE_ARGS}
246                                      ${RUNTIMES_CMAKE_ARGS}
247                           PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
248                                                LLVM_USE_LINKER
249                                                ${ARG_PREFIXES}
250                           EXTRA_TARGETS ${extra_targets}
251                                         ${test_targets}
252                                         ${SUB_COMPONENTS}
253                                         ${SUB_CHECK_TARGETS}
254                                         ${SUB_INSTALL_TARGETS}
255                           USE_TOOLCHAIN
256                           TARGET_TRIPLE ${LLVM_TARGET_TRIPLE}
257                           ${EXTRA_ARGS})
258endfunction()
259
260# runtime_register_target(target)
261#   Utility function to register external runtime target.
262function(runtime_register_target name target)
263  cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS" ${ARGN})
264  include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
265  set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
266
267  check_apple_target(${target} runtime)
268
269  set(${name}_deps ${ARG_DEPENDS})
270  if(NOT name STREQUAL target)
271    list(APPEND ${name}_deps runtimes-${target})
272  endif()
273
274  foreach(runtime_name ${runtime_names})
275    set(${runtime_name}-${name} ${runtime_name})
276    set(install-${runtime_name}-${name} install-${runtime_name})
277    set(install-${runtime_name}-${name}-stripped install-${runtime_name}-stripped)
278    list(APPEND ${name}_extra_targets ${runtime_name}-${name} install-${runtime_name}-${name} install-${runtime_name}-${name}-stripped)
279    if(LLVM_INCLUDE_TESTS)
280      set(check-${runtime_name}-${name} check-${runtime_name} )
281      list(APPEND ${name}_test_targets check-${runtime_name}-${name})
282    endif()
283  endforeach()
284
285  foreach(target_name IN LISTS SUB_COMPONENTS SUB_INSTALL_TARGETS)
286    set(${target_name}-${name} ${target_name})
287    list(APPEND ${name}_extra_targets ${target_name}-${name})
288  endforeach()
289
290  foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
291    set(${component}-${name} ${component})
292    set(install-${component}-${name} install-${component})
293    set(install-${component}-${name}-stripped install-${component}-stripped)
294    list(APPEND ${name}_extra_targets ${component}-${name} install-${component}-${name} install-${component}-${name}-stripped)
295  endforeach()
296
297  if(LLVM_INCLUDE_TESTS)
298    set_property(GLOBAL APPEND PROPERTY LLVM_ALL_LIT_TESTSUITES "@${LLVM_BINARY_DIR}/runtimes/${name}/Tests.rsp")
299    set(runtimes-test-depends-${name} runtimes-test-depends)
300    set(check-runtimes-${name} check-runtimes)
301    list(APPEND ${name}_test_targets runtimes-test-depends-${name} check-runtimes-${name})
302    list(APPEND test_targets ${${name}_test_targets})
303    foreach(target_name IN LISTS SUB_CHECK_TARGETS)
304      set(${target_name}-${name} ${target_name})
305      list(APPEND ${name}_test_targets ${target_name}-${name})
306      list(APPEND test_targets ${target_name}-${name})
307    endforeach()
308    set(test_targets "${test_targets}" PARENT_SCOPE)
309  endif()
310
311  set(${name}_extra_args ${ARG_CMAKE_ARGS})
312  get_cmake_property(variableNames VARIABLES)
313  foreach(variableName ${variableNames})
314    string(FIND "${variableName}" "RUNTIMES_${target}_" out)
315    if("${out}" EQUAL 0)
316      string(REPLACE "RUNTIMES_${target}_" "" new_name ${variableName})
317      string(REPLACE ";" "|" new_value "${${variableName}}")
318      list(APPEND ${name}_extra_args "-D${new_name}=${new_value}")
319    endif()
320  endforeach()
321  if(NOT "${name}" STREQUAL "${target}")
322    foreach(variableName ${variableNames})
323      string(FIND "${variableName}" "RUNTIMES_${name}_" out)
324      if("${out}" EQUAL 0)
325        string(REPLACE "RUNTIMES_${name}_" "" new_name ${variableName})
326        string(REPLACE ";" "|" new_value "${${variableName}}")
327        list(APPEND ${name}_extra_args "-D${new_name}=${new_value}")
328      endif()
329    endforeach()
330  endif()
331
332  if(NOT RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES AND NOT RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES)
333    string(REPLACE ";" "|" LLVM_ENABLE_RUNTIMES_PASSTHROUGH "${LLVM_ENABLE_RUNTIMES}")
334    list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH})
335  endif()
336
337  llvm_ExternalProject_Add(runtimes-${name}
338                           ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
339                           DEPENDS ${${name}_deps}
340                           # Builtins were built separately above
341                           CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
342                                      -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
343                                      -DLLVM_DEFAULT_TARGET_TRIPLE=${target}
344                                      -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
345                                      -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
346                                      -DCMAKE_C_COMPILER_WORKS=ON
347                                      -DCMAKE_CXX_COMPILER_WORKS=ON
348                                      -DCMAKE_ASM_COMPILER_WORKS=ON
349                                      -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
350                                      -DLLVM_RUNTIMES_TARGET=${name}
351                                      ${COMMON_CMAKE_ARGS}
352                                      ${${name}_extra_args}
353                           PASSTHROUGH_PREFIXES LLVM_USE_LINKER
354                           EXTRA_TARGETS ${${name}_extra_targets}
355                                         ${${name}_test_targets}
356                           USE_TOOLCHAIN
357                           TARGET_TRIPLE ${target}
358                           ${EXTRA_ARGS})
359endfunction()
360
361if(runtimes)
362  # Create a runtimes target that uses this file as its top-level CMake file.
363  # The runtimes target is a configuration of all the runtime libraries
364  # together in a single CMake invocaiton.
365  set(extra_deps "")
366  if("openmp" IN_LIST LLVM_ENABLE_RUNTIMES)
367    if(TARGET opt)
368      list(APPEND extra_deps opt)
369    endif()
370    if(TARGET llvm-link)
371      list(APPEND extra_deps llvm-link)
372    endif()
373  endif()
374  if(NOT LLVM_RUNTIME_TARGETS)
375    runtime_default_target(
376      DEPENDS ${deps} ${extra_deps}
377      PREFIXES ${prefixes})
378    set(test_targets check-runtimes)
379  else()
380    if("default" IN_LIST LLVM_RUNTIME_TARGETS)
381      runtime_default_target(
382        DEPENDS ${deps} ${extra_deps}
383        PREFIXES ${prefixes})
384      list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
385    else()
386      add_custom_target(runtimes)
387      add_custom_target(runtimes-configure)
388      add_custom_target(install-runtimes)
389      add_custom_target(install-runtimes-stripped)
390      if(LLVM_INCLUDE_TESTS)
391        add_custom_target(check-runtimes)
392        add_custom_target(runtimes-test-depends)
393        set(test_targets "")
394      endif()
395      foreach(runtime_name ${runtime_names})
396        add_custom_target(${runtime_name})
397        add_custom_target(install-${runtime_name})
398        add_custom_target(install-${runtime_name}-stripped)
399      endforeach()
400      if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
401        foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
402          add_custom_target(${component})
403          add_custom_target(install-${component})
404          add_custom_target(install-${component}-stripped)
405        endforeach()
406      endif()
407    endif()
408
409    foreach(name ${LLVM_RUNTIME_TARGETS})
410      runtime_register_target(${name} ${name}
411        DEPENDS ${deps})
412
413      add_dependencies(runtimes runtimes-${name})
414      add_dependencies(runtimes-configure runtimes-${name}-configure)
415      add_dependencies(install-runtimes install-runtimes-${name})
416      add_dependencies(install-runtimes-stripped install-runtimes-${name}-stripped)
417      if(LLVM_INCLUDE_TESTS)
418        add_dependencies(check-runtimes check-runtimes-${name})
419        add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
420      endif()
421      foreach(runtime_name ${runtime_names})
422        add_dependencies(${runtime_name} ${runtime_name}-${name})
423        add_dependencies(install-${runtime_name} install-${runtime_name}-${name})
424        add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}-stripped)
425      endforeach()
426      foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
427        add_dependencies(${component} ${component}-${name})
428        add_dependencies(install-${component} install-${component}-${name})
429        add_dependencies(install-${component}-stripped install-${component}-${name}-stripped)
430      endforeach()
431    endforeach()
432
433    foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
434      foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
435        runtime_register_target(${name}+${multilib} ${name}
436          DEPENDS runtimes-${name}
437          CMAKE_ARGS -DLLVM_RUNTIMES_PREFIX=${name}/
438                     -DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib})
439        add_dependencies(runtimes runtimes-${name}+${multilib})
440        add_dependencies(runtimes-configure runtimes-${name}+${multilib}-configure)
441        add_dependencies(install-runtimes install-runtimes-${name}+${multilib})
442        add_dependencies(install-runtimes-stripped install-runtimes-${name}+${multilib}-stripped)
443        foreach(runtime_name ${runtime_names})
444          add_dependencies(${runtime_name} ${runtime_name}-${name}+${multilib})
445          add_dependencies(install-${runtime_name} install-${runtime_name}-${name}+${multilib})
446          add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}+${multilib}-stripped)
447        endforeach()
448        foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
449          add_dependencies(${component} ${component}-${name}+${multilib})
450          add_dependencies(install-${component} install-${component}-${name}+${multilib})
451          add_dependencies(install-${component}-stripped install-${component}-${name}+${multilib}-stripped)
452        endforeach()
453      endforeach()
454    endforeach()
455  endif()
456
457  if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
458    # TODO: This is a hack needed because the libcxx headers are copied into the
459    # build directory during configuration. Without that step the clang in the
460    # build directory cannot find the C++ headers in certain configurations.
461    # I need to build a mechanism for runtime projects to provide CMake code
462    # that executes at LLVM configuration time to handle this case.
463    add_dependencies(clang-bootstrap-deps runtimes-configure)
464    # We need to add the runtimes as a dependency because compiler-rt can be
465    # built as part of runtimes and we need the profile runtime for PGO
466    add_dependencies(clang-bootstrap-deps runtimes)
467  endif()
468
469  if(LLVM_INCLUDE_TESTS)
470    set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_DEPENDS runtimes-test-depends)
471
472    set(RUNTIMES_TEST_DEPENDS
473        FileCheck
474        count
475        llvm-nm
476        llvm-objdump
477        llvm-xray
478        not
479        obj2yaml
480        sancov
481        sanstats
482        llvm_gtest_main
483        llvm_gtest
484      )
485    foreach(target ${test_targets} ${SUB_CHECK_TARGETS})
486      add_dependencies(${target} ${RUNTIMES_TEST_DEPENDS})
487    endforeach()
488
489    set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_TARGETS runtimes ${RUNTIMES_TEST_DEPENDS})
490  endif()
491endif()
492