[llvm-shlib] Fix the version naming style of libLLVM for Windows (#85710)
[llvm-project.git] / llvm / runtimes / CMakeLists.txt
blob8c48d85a4346f478f2b9133aa8cc532fdebed434
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;-DCLANG_RESOURCE_DIR=${CLANG_RESOURCE_DIR}")
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     if(NOT TARGET ${runtime_name})
395       add_custom_target(${runtime_name})
396     endif()
397     add_dependencies(${runtime_name} ${runtime_name}-${name})
398     if(NOT TARGET install-${runtime_name})
399       add_custom_target(install-${runtime_name})
400     endif()
401     add_dependencies(install-${runtime_name} install-${runtime_name}-${name})
402     if(NOT TARGET install-${runtime_name}-stripped)
403       add_custom_target(install-${runtime_name}-stripped)
404     endif()
405     add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}-stripped)
406   endforeach()
407   foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
408     add_dependencies(${component} ${component}-${name})
409     add_dependencies(install-${component} install-${component}-${name})
410     add_dependencies(install-${component}-stripped install-${component}-${name}-stripped)
411   endforeach()
412 endfunction()
414 if(runtimes)
415   # Create a runtimes target that uses this file as its top-level CMake file.
416   # The runtimes target is a configuration of all the runtime libraries
417   # together in a single CMake invocation.
418   set(extra_deps "")
419   if("openmp" IN_LIST LLVM_ENABLE_RUNTIMES)
420     foreach(dep opt llvm-link llvm-extract clang clang-offload-packager)
421       if(TARGET ${dep} AND OPENMP_ENABLE_LIBOMPTARGET)
422         list(APPEND extra_deps ${dep})
423       endif()
424     endforeach()
425   endif()
426   if("libc" IN_LIST LLVM_ENABLE_PROJECTS AND
427       (LLVM_LIBC_FULL_BUILD OR LIBC_GPU_BUILD OR LIBC_GPU_ARCHITECTURES))
428     if(LIBC_HDRGEN_EXE)
429       set(hdrgen_exe ${LIBC_HDRGEN_EXE})
430     else()
431       if(TARGET ${LIBC_TABLEGEN_EXE})
432         set(hdrgen_exe $<TARGET_FILE:${LIBC_TABLEGEN_EXE}>)
433       else()
434         set(hdrgen_exe ${LIBC_TABLEGEN_EXE})
435       endif()
436       set(hdrgen_deps ${LIBC_TABLEGEN_TARGET})
437     endif()
438     if(NOT hdrgen_exe)
439       message(FATAL_ERROR "libc-hdrgen executable missing")
440     endif()
441     set(libc_cmake_args "-DLIBC_HDRGEN_EXE=${hdrgen_exe}"
442                         "-DLLVM_LIBC_FULL_BUILD=ON")
443     list(APPEND extra_deps ${hdrgen_deps})
444     if(LIBC_GPU_BUILD OR LIBC_GPU_ARCHITECTURES)
445       foreach(dep clang-offload-packager nvptx-arch amdgpu-arch)
446         if(TARGET ${dep})
447           list(APPEND extra_deps ${dep})
448         endif()
449       endforeach()
450     endif()
451   endif()
452   if(NOT LLVM_RUNTIME_TARGETS)
453     runtime_default_target(
454       DEPENDS ${builtins_dep} ${extra_deps}
455       CMAKE_ARGS ${libc_cmake_args}
456       PREFIXES ${prefixes})
457     set(test_targets check-runtimes)
458   else()
459     if("default" IN_LIST LLVM_RUNTIME_TARGETS)
460       runtime_default_target(
461         DEPENDS ${builtins_dep} ${extra_deps}
462         CMAKE_ARGS ${libc_cmake_args}
463         PREFIXES ${prefixes})
464       list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
465     else()
466       add_custom_target(runtimes)
467       add_custom_target(runtimes-configure)
468       add_custom_target(install-runtimes)
469       add_custom_target(install-runtimes-stripped)
470       if(LLVM_INCLUDE_TESTS)
471         add_custom_target(check-runtimes)
472         add_custom_target(runtimes-test-depends)
473         set(test_targets "")
474       endif()
475       if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
476         foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
477           add_custom_target(${component})
478           add_custom_target(install-${component})
479           add_custom_target(install-${component}-stripped)
480         endforeach()
481       endif()
482     endif()
484     foreach(name ${LLVM_RUNTIME_TARGETS})
485       if(builtins_dep)
486         if (LLVM_BUILTIN_TARGETS)
487           set(builtins_dep_name "${builtins_dep}-${name}")
488         else()
489           set(builtins_dep_name ${builtins_dep})
490         endif()
491       endif()
493       check_apple_target(${name} runtime)
495       runtime_register_target(${name}
496         DEPENDS ${builtins_dep_name} ${hdrgen_deps}
497         CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${libc_cmake_args}
498         EXTRA_ARGS TARGET_TRIPLE ${name})
499     endforeach()
501     foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
502       foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
503         runtime_register_target(${name}+${multilib}
504           DEPENDS runtimes-${name}
505           CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name}
506                      -DLLVM_RUNTIMES_PREFIX=${name}/
507                      -DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
508           BASE_NAME ${name}
509           EXTRA_ARGS TARGET_TRIPLE ${name})
510       endforeach()
511     endforeach()
512   endif()
514   if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
515     # TODO: This is a hack needed because the libcxx headers are copied into the
516     # build directory during configuration. Without that step the clang in the
517     # build directory cannot find the C++ headers in certain configurations.
518     # I need to build a mechanism for runtime projects to provide CMake code
519     # that executes at LLVM configuration time to handle this case.
520     add_dependencies(clang-bootstrap-deps runtimes-configure)
521     # We need to add the runtimes as a dependency because compiler-rt can be
522     # built as part of runtimes and we need the profile runtime for PGO
523     add_dependencies(clang-bootstrap-deps runtimes)
524   endif()
526   if(LLVM_INCLUDE_TESTS)
527     set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_DEPENDS runtimes-test-depends)
529     set(RUNTIMES_TEST_DEPENDS
530         FileCheck
531         count
532         llvm-cov
533         llvm-lto
534         llvm-nm
535         llvm-objdump
536         llvm-profdata
537         llvm-size
538         llvm-xray
539         not
540         obj2yaml
541         opt
542         sancov
543         sanstats
544         llvm_gtest_main
545         llvm_gtest
546         split-file
547       )
548     foreach(target ${test_targets} ${SUB_CHECK_TARGETS})
549       add_dependencies(${target} ${RUNTIMES_TEST_DEPENDS})
550     endforeach()
552     set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_TARGETS runtimes ${RUNTIMES_TEST_DEPENDS})
553   endif()
554 endif()