• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
11file(GLOB entries *)
12foreach(entry ${entries})
13  if(IS_DIRECTORY ${entry} AND EXISTS ${entry}/CMakeLists.txt)
14    list(APPEND runtimes ${entry})
15  endif()
16endforeach()
17
18# Side-by-side subprojects layout.
19set(LLVM_ALL_RUNTIMES "libcxx;libcxxabi;libunwind;compiler-rt")
20set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
21  "Semicolon-separated list of runtimes to build (${LLVM_ALL_RUNTIMES}), or \"all\".")
22if(LLVM_ENABLE_RUNTIMES STREQUAL "all" )
23  set(LLVM_ENABLE_RUNTIMES ${LLVM_ALL_RUNTIMES})
24endif()
25foreach(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}")
35endforeach()
36
37function(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()
45endfunction()
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.
49if(${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
91  if(APPLE)
92    set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
93  endif()
94
95  set(SAFE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
96  set(SAFE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
97
98  include(CheckLibraryExists)
99  include(CheckCCompilerFlag)
100
101  check_library_exists(c fopen "" LLVM_HAS_C_LIB)
102  check_c_compiler_flag(-nodefaultlibs LLVM_HAS_NODEFAULTLIBS_FLAG)
103  if(LLVM_HAS_NODEFAULTLIBS_FLAG)
104    set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
105    if(LLVM_HAS_C_LIB)
106      list(APPEND CMAKE_REQUIRED_LIBRARIES c)
107    endif()
108  endif()
109
110  # Avoid checking whether the compiler is working.
111  set(LLVM_COMPILER_CHECKED ON)
112  # Enable warnings, otherwise -w gets added to the cflags by HandleLLVMOptions
113  # resulting in unjustified successes by check_cxx_compiler_flag.
114  set(LLVM_ENABLE_WARNINGS ON)
115
116  # Handle common options used by all runtimes.
117  include(AddLLVM)
118  include(HandleLLVMOptions)
119
120  set(CMAKE_REQUIRED_FLAGS ${SAFE_CMAKE_REQUIRED_FLAGS})
121  set(CMAKE_REQUIRED_LIBRARIES ${SAFE_CMAKE_REQUIRED_LIBRARIES})
122
123  foreach(entry ${runtimes})
124    get_filename_component(projName ${entry} NAME)
125
126    # TODO: Clean this up as part of an interface standardization
127    string(REPLACE "-" "_" canon_name ${projName})
128    string(TOUPPER ${canon_name} canon_name)
129    # The subdirectories need to treat this as standalone builds
130    set(${canon_name}_STANDALONE_BUILD On)
131
132    if(LLVM_RUNTIMES_LIBDIR_SUFFIX)
133      set(${canon_name}_LIBDIR_SUFFIX "${LLVM_RUNTIMES_LIBDIR_SUFFIX}" CACHE STRING "" FORCE)
134    endif()
135
136    # Setting a variable to let sub-projects detect which other projects
137    # will be included under here.
138    set(HAVE_${canon_name} On)
139  endforeach()
140
141  # We do this in two loops so that HAVE_* is set for each runtime before the
142  # other runtimes are added.
143  foreach(entry ${runtimes})
144    get_filename_component(projName ${entry} NAME)
145
146    # Between each sub-project we want to cache and clear the LIT properties
147    set_property(GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
148    set_property(GLOBAL PROPERTY LLVM_LIT_PARAMS)
149    set_property(GLOBAL PROPERTY LLVM_LIT_DEPENDS)
150    set_property(GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
151
152    add_subdirectory(${entry} ${projName})
153
154    get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
155    get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
156    get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
157    get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
158
159    list(APPEND RUNTIMES_LIT_TESTSUITES ${LLVM_LIT_TESTSUITES})
160    list(APPEND RUNTIMES_LIT_PARAMS ${LLVM_LIT_PARAMS})
161    list(APPEND RUNTIMES_LIT_DEPENDS ${LLVM_LIT_DEPENDS})
162    list(APPEND RUNTIMES_LIT_EXTRA_ARGS ${LLVM_LIT_EXTRA_ARGS})
163  endforeach()
164
165  if(LLVM_INCLUDE_TESTS)
166    # Add a global check rule now that all subdirectories have been traversed
167    # and we know the total set of lit testsuites.
168
169    add_lit_target(check-runtimes
170      "Running all regression tests"
171      ${RUNTIMES_LIT_TESTSUITES}
172      PARAMS ${RUNTIMES_LIT_PARAMS}
173      DEPENDS ${RUNTIMES_LIT_DEPENDS}
174      ARGS ${RUNTIMES_LIT_EXTRA_ARGS}
175      )
176    add_custom_target(runtimes-test-depends DEPENDS ${RUNTIMES_LIT_DEPENDS})
177  endif()
178
179  get_property(SUB_COMPONENTS GLOBAL PROPERTY SUB_COMPONENTS)
180  if(SUB_COMPONENTS)
181    list(REMOVE_DUPLICATES SUB_COMPONENTS)
182    foreach(component ${SUB_COMPONENTS})
183      if(NOT TARGET ${component})
184        message(SEND_ERROR "Missing target for runtime component ${component}!")
185        continue()
186      endif()
187
188      if(TARGET check-${component})
189        list(APPEND SUB_CHECK_TARGETS check-${component})
190      endif()
191
192      if(TARGET install-${component})
193        list(APPEND SUB_INSTALL_TARGETS install-${component})
194      endif()
195      if(TARGET install-${component}-stripped)
196        list(APPEND SUB_INSTALL_TARGETS install-${component}-stripped)
197      endif()
198    endforeach()
199
200    if(LLVM_RUNTIMES_TARGET)
201      configure_file(
202        ${CMAKE_CURRENT_SOURCE_DIR}/Components.cmake.in
203        ${LLVM_BINARY_DIR}/runtimes/${LLVM_RUNTIMES_TARGET}/Components.cmake)
204    else()
205      configure_file(
206        ${CMAKE_CURRENT_SOURCE_DIR}/Components.cmake.in
207        ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
208    endif()
209  endif()
210
211else() # if this is included from LLVM's CMake
212  include(LLVMExternalProjectUtils)
213
214  if(NOT LLVM_BUILD_RUNTIMES)
215    set(EXTRA_ARGS EXCLUDE_FROM_ALL)
216  endif()
217
218  function(builtin_default_target compiler_rt_path)
219    llvm_ExternalProject_Add(builtins
220                             ${compiler_rt_path}/lib/builtins
221                             CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
222                                        -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
223                                        -DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_TRIPLE}
224                                        -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
225                                        -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE}
226                                        -DCMAKE_ASM_COMPILER_TARGET=${TARGET_TRIPLE}
227                                        -DCMAKE_C_COMPILER_WORKS=ON
228                                        -DCMAKE_ASM_COMPILER_WORKS=ON
229                             PASSTHROUGH_PREFIXES COMPILER_RT
230                             USE_TOOLCHAIN
231                             ${EXTRA_ARGS})
232  endfunction()
233
234  function(builtin_register_target compiler_rt_path target)
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                             CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
254                                        -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
255                                        -DLLVM_DEFAULT_TARGET_TRIPLE=${target}
256                                        -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
257                                        -DCMAKE_C_COMPILER_TARGET=${target}
258                                        -DCMAKE_ASM_COMPILER_TARGET=${target}
259                                        -DCMAKE_C_COMPILER_WORKS=ON
260                                        -DCMAKE_ASM_COMPILER_WORKS=ON
261                                        -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
262                                        ${${target}_extra_args}
263                             TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib llvm-nm llvm-objcopy llvm-objdump llvm-strip
264                             USE_TOOLCHAIN
265                             ${EXTRA_ARGS})
266  endfunction()
267
268  # If compiler-rt is present we need to build the builtin libraries first. This
269  # is required because the other runtimes need the builtin libraries present
270  # before the just-built compiler can pass the configuration tests.
271  get_compiler_rt_path(compiler_rt_path)
272  if(compiler_rt_path)
273    if(NOT LLVM_BUILTIN_TARGETS)
274      builtin_default_target(${compiler_rt_path})
275    else()
276      if("default" IN_LIST LLVM_BUILTIN_TARGETS)
277        builtin_default_target(${compiler_rt_path})
278        list(REMOVE_ITEM LLVM_BUILTIN_TARGETS "default")
279      else()
280        add_custom_target(builtins)
281        add_custom_target(install-builtins)
282        add_custom_target(install-builtins-stripped)
283      endif()
284
285      foreach(target ${LLVM_BUILTIN_TARGETS})
286        builtin_register_target(${compiler_rt_path} ${target})
287
288        add_dependencies(builtins builtins-${target})
289        add_dependencies(install-builtins install-builtins-${target})
290        add_dependencies(install-builtins-stripped install-builtins-${target}-stripped)
291      endforeach()
292    endif()
293    set(deps builtins)
294    # We don't need to depend on the builtins if we're building instrumented
295    # because the next stage will use the same compiler used to build this stage.
296    if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
297      add_dependencies(clang-bootstrap-deps builtins)
298    endif()
299  endif()
300
301  # We create a list the names of all the runtime projects in all uppercase and
302  # with dashes turned to underscores. This gives us the CMake variable prefixes
303  # for all variables that will apply to runtimes.
304  foreach(entry ${runtimes})
305    get_filename_component(projName ${entry} NAME)
306    string(REPLACE "-" "_" canon_name ${projName})
307    string(TOUPPER ${canon_name} canon_name)
308    list(APPEND prefixes ${canon_name})
309
310    string(FIND ${projName} "lib" LIB_IDX)
311    if(LIB_IDX EQUAL 0)
312      string(SUBSTRING ${projName} 3 -1 projName)
313    endif()
314    list(APPEND runtime_names ${projName})
315  endforeach()
316
317  function(runtime_default_target)
318    cmake_parse_arguments(ARG "" "" "DEPS;PREFIXES" ${ARGN})
319
320    include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
321    set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
322
323    foreach(runtime_name ${runtime_names})
324      list(APPEND extra_targets
325        ${runtime_name}
326        install-${runtime_name}
327        install-${runtime_name}-stripped)
328      if(LLVM_INCLUDE_TESTS)
329        list(APPEND test_targets check-${runtime_name})
330      endif()
331    endforeach()
332    foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
333      if(NOT ${component} IN_LIST SUB_COMPONENTS)
334        list(APPEND extra_targets ${component} install-${component} install-${component}-stripped)
335      endif()
336    endforeach()
337
338    if(LLVM_INCLUDE_TESTS)
339      list(APPEND test_targets runtimes-test-depends check-runtimes)
340    endif()
341
342    llvm_ExternalProject_Add(runtimes
343                             ${CMAKE_CURRENT_SOURCE_DIR}
344                             DEPENDS ${ARG_DEPS}
345                             # Builtins were built separately above
346                             CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
347                                        -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
348                                        -DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR}
349                                        -DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_TRIPLE}
350                                        -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
351                                        -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE}
352                                        -DCMAKE_CXX_COMPILER_TARGET=${TARGET_TRIPLE}
353                                        -DCMAKE_ASM_COMPILER_TARGET=${TARGET_TRIPLE}
354                                        -DCMAKE_C_COMPILER_WORKS=ON
355                                        -DCMAKE_CXX_COMPILER_WORKS=ON
356                                        -DCMAKE_ASM_COMPILER_WORKS=ON
357                             PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
358                                                  ${ARG_PREFIXES}
359                             EXTRA_TARGETS ${extra_targets}
360                                           ${test_targets}
361                                           ${SUB_COMPONENTS}
362                                           ${SUB_CHECK_TARGETS}
363                                           ${SUB_INSTALL_TARGETS}
364                             USE_TOOLCHAIN
365                             ${EXTRA_ARGS})
366  endfunction()
367
368  # runtime_register_target(target)
369  #   Utility function to register external runtime target.
370  function(runtime_register_target name target)
371    cmake_parse_arguments(ARG "" "" "DEPS" ${ARGN})
372    include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
373    set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
374
375    set(${name}_deps ${ARG_DEPS})
376    if(NOT name STREQUAL target)
377      list(APPEND ${name}_deps runtimes-${target})
378    endif()
379
380    foreach(runtime_name ${runtime_names})
381      set(${runtime_name}-${name} ${runtime_name})
382      set(install-${runtime_name}-${name} install-${runtime_name})
383      set(install-${runtime_name}-${name}-stripped install-${runtime_name}-stripped)
384      list(APPEND ${name}_extra_targets ${runtime_name}-${name} install-${runtime_name}-${name} install-${runtime_name}-${name}-stripped)
385      if(LLVM_INCLUDE_TESTS)
386        set(check-${runtime_name}-${name} check-${runtime_name} )
387        list(APPEND ${name}_test_targets check-${runtime_name}-${name})
388      endif()
389    endforeach()
390
391    foreach(target_name IN LISTS SUB_COMPONENTS SUB_INSTALL_TARGETS)
392      set(${target_name}-${name} ${target_name})
393      list(APPEND ${name}_extra_targets ${target_name}-${name})
394    endforeach()
395
396    foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
397      if(NOT "${target_name}:${target_name}-${component}" IN_LIST extra_targets)
398        list(APPEND ${name}_extra_targets
399          "${target_name}:${target_name}-${component}"
400          "${target_name}:${target_name}-install-${component}")
401      endif()
402    endforeach()
403
404    if(LLVM_INCLUDE_TESTS)
405      set(runtimes-test-depends-${name} runtimes-test-depends)
406      set(check-runtimes-${name} check-runtimes)
407      list(APPEND ${name}_test_targets runtimes-test-depends-${name} check-runtimes-${name})
408      foreach(target_name IN LISTS SUB_CHECK_TARGETS)
409        set(${target_name}-${name} ${target_name})
410        list(APPEND ${name}_test_targets ${target_name}-${name})
411        list(APPEND test_targets ${target_name}-${name})
412      endforeach()
413      set(test_targets "${test_targets}" PARENT_SCOPE)
414    endif()
415
416    get_cmake_property(variableNames VARIABLES)
417    foreach(variableName ${variableNames})
418      if(variableName MATCHES "^RUNTIMES_${name}")
419        string(REPLACE "RUNTIMES_${name}_" "" new_name ${variableName})
420        list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
421      elseif(variableName MATCHES "^RUNTIMES_${target}")
422        string(REPLACE "RUNTIMES_${target}_" "" new_name ${variableName})
423        list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
424      endif()
425    endforeach()
426
427    llvm_ExternalProject_Add(runtimes-${name}
428                             ${CMAKE_CURRENT_SOURCE_DIR}
429                             DEPENDS ${${name}_deps}
430                             # Builtins were built separately above
431                             CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
432                                        -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
433                                        -DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR}
434                                        -DLLVM_DEFAULT_TARGET_TRIPLE=${target}
435                                        -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
436                                        -DCMAKE_C_COMPILER_TARGET=${target}
437                                        -DCMAKE_CXX_COMPILER_TARGET=${target}
438                                        -DCMAKE_ASM_COMPILER_TARGET=${target}
439                                        -DCMAKE_C_COMPILER_WORKS=ON
440                                        -DCMAKE_CXX_COMPILER_WORKS=ON
441                                        -DCMAKE_ASM_COMPILER_WORKS=ON
442                                        -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
443                                        -DLLVM_RUNTIMES_TARGET=${name}
444                                        ${${name}_extra_args}
445                             PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
446                             TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib llvm-nm llvm-objcopy llvm-objdump llvm-strip
447                             EXTRA_TARGETS ${${name}_extra_targets}
448                                           ${${name}_test_targets}
449                             USE_TOOLCHAIN
450                             ${EXTRA_ARGS})
451  endfunction()
452
453  if(runtimes)
454    # Create a runtimes target that uses this file as its top-level CMake file.
455    # The runtimes target is a configuration of all the runtime libraries
456    # together in a single CMake invocaiton.
457    if(NOT LLVM_RUNTIME_TARGETS)
458      runtime_default_target(
459        DEPS ${deps}
460        PREFIXES ${prefixes}
461        )
462    else()
463      if("default" IN_LIST LLVM_RUNTIME_TARGETS)
464        runtime_default_target(
465          DEPS ${deps}
466          PREFIXES ${prefixes})
467        list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
468      else()
469        add_custom_target(runtimes)
470        add_custom_target(runtimes-configure)
471        add_custom_target(install-runtimes)
472        add_custom_target(install-runtimes-stripped)
473        if(LLVM_INCLUDE_TESTS)
474          add_custom_target(check-runtimes)
475          add_custom_target(runtimes-test-depends)
476          set(test_targets "")
477        endif()
478        if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
479          foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
480            add_custom_target(${component})
481            add_custom_target(install-${component})
482          endforeach()
483        endif()
484      endif()
485
486      foreach(name ${LLVM_RUNTIME_TARGETS})
487        runtime_register_target(${name} ${name}
488          DEPS ${deps}
489          )
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            DEPS runtimes-${name}
516            CMAKE_ARGS -DLLVM_USE_SANITIZER=${sanitizer}
517                       -DLLVM_RUNTIMES_PREFIX=${name}/
518                       -DLLVM_RUNTIMES_LIBDIR_SUFFIX=/${sanitizer_name}
519            )
520          add_dependencies(runtimes runtimes-${name}-${sanitizer_name})
521          add_dependencies(runtimes-configure runtimes-${name}-${sanitizer_name}-configure)
522          add_dependencies(install-runtimes install-runtimes-${name}-${sanitizer_name})
523          add_dependencies(install-runtimes-stripped install-runtimes-${name}-${sanitizer_name}-stripped)
524        endforeach()
525      endforeach()
526    endif()
527
528    # TODO: This is a hack needed because the libcxx headers are copied into the
529    # build directory during configuration. Without that step the clang in the
530    # build directory cannot find the C++ headers in certain configurations.
531    # I need to build a mechanism for runtime projects to provide CMake code
532    # that executes at LLVM configuration time to handle this case.
533    if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
534      add_dependencies(clang-bootstrap-deps runtimes-configure)
535    endif()
536
537    if(LLVM_INCLUDE_TESTS)
538      set_property(GLOBAL APPEND PROPERTY LLVM_ADDITIONAL_TEST_DEPENDS runtimes-test-depends)
539      set_property(GLOBAL APPEND PROPERTY LLVM_ADDITIONAL_TEST_TARGETS check-runtimes)
540
541      set(RUNTIMES_TEST_DEPENDS
542          FileCheck
543          count
544          llvm-nm
545          llvm-objdump
546          llvm-xray
547          not
548          obj2yaml
549          sancov
550          sanstats
551        )
552      foreach(target ${test_targets} ${SUB_CHECK_TARGETS})
553        add_dependencies(${target} ${RUNTIMES_TEST_DEPENDS})
554      endforeach()
555    endif()
556  endif()
557endif()
558