[MIParser] Set RegClassOrRegBank during instruction parsing
[llvm-complete.git] / runtimes / CMakeLists.txt
blobe212c941b6a2a56533a69a8a0c3e1fa267bd6c62
1 # This file handles building LLVM runtime sub-projects.
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.
7 # Setting CMake minimum required version should be at the very top of the file
8 # if this is the entry point.
9 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
10   cmake_minimum_required(VERSION 3.4.3)
11   project(Runtimes C CXX ASM)
12 endif()
14 # Find all subdirectories containing CMake projects
15 file(GLOB entries *)
16 foreach(entry ${entries})
17   if(IS_DIRECTORY ${entry} AND EXISTS ${entry}/CMakeLists.txt)
18     list(APPEND runtimes ${entry})
19   endif()
20 endforeach()
22 # Side-by-side subprojects layout.
23 set(LLVM_ALL_RUNTIMES "libcxx;libcxxabi;libunwind;compiler-rt")
24 set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
25   "Semicolon-separated list of runtimes to build (${LLVM_ALL_RUNTIMES}), or \"all\".")
26 if(LLVM_ENABLE_RUNTIMES STREQUAL "all" )
27   set(LLVM_ENABLE_RUNTIMES ${LLVM_ALL_RUNTIMES})
28 endif()
29 foreach(proj ${LLVM_ENABLE_RUNTIMES})
30   set(proj_dir "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
31   if(IS_DIRECTORY ${proj_dir} AND EXISTS ${proj_dir}/CMakeLists.txt)
32     list(APPEND runtimes ${proj_dir})
33   else()
34     message(FATAL_ERROR "LLVM_ENABLE_RUNTIMES requests ${proj} but directory not found: ${proj_dir}")
35   endif()
36   string(TOUPPER "${proj}" canon_name)
37   STRING(REGEX REPLACE "-" "_" canon_name ${canon_name})
38   set(LLVM_EXTERNAL_${canon_name}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
39 endforeach()
41 function(get_compiler_rt_path path)
42   foreach(entry ${runtimes})
43     get_filename_component(projName ${entry} NAME)
44     if("${projName}" MATCHES "compiler-rt")
45       set(${path} ${entry} PARENT_SCOPE)
46       return()
47     endif()
48   endforeach()
49 endfunction()
51 # If this file is acting as a top-level CMake invocation, this code path is
52 # triggered by the external project call for the runtimes target below.
53 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
55   function(runtime_register_component name)
56     set_property(GLOBAL APPEND PROPERTY SUB_COMPONENTS ${name})
57   endfunction()
59   cmake_minimum_required(VERSION 3.4.3)
60   project(Runtimes C CXX ASM)
62   find_package(LLVM PATHS "${LLVM_BINARY_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
64   # Add the root project's CMake modules, and the LLVM build's modules to the
65   # CMake module path.
66   list(INSERT CMAKE_MODULE_PATH 0
67     "${CMAKE_CURRENT_SOURCE_DIR}/../cmake"
68     "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules"
69   )
71   # Some of the runtimes will conditionally use the compiler-rt sanitizers
72   # to make this work smoothly we ensure that compiler-rt is added first in
73   # the list of sub-projects. This allows other sub-projects to have checks
74   # like `if(TARGET asan)` to enable building with asan.
75   get_compiler_rt_path(compiler_rt_path)
76   if(compiler_rt_path)
77     list(REMOVE_ITEM runtimes ${compiler_rt_path})
78     if(NOT DEFINED LLVM_BUILD_COMPILER_RT OR LLVM_BUILD_COMPILER_RT)
79       list(INSERT runtimes 0 ${compiler_rt_path})
80     endif()
81   endif()
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})
88   # This variable makes sure that e.g. llvm-lit is found.
89   set(LLVM_MAIN_SRC_DIR ${LLVM_BUILD_MAIN_SRC_DIR})
90   set(LLVM_CMAKE_PATH ${LLVM_MAIN_SRC_DIR}/cmake/modules)
92   # This variable is used by individual runtimes to locate LLVM files.
93   set(LLVM_PATH ${LLVM_BUILD_MAIN_SRC_DIR})
95   if(APPLE)
96     set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
97   endif()
99   include(CheckLibraryExists)
100   include(CheckCCompilerFlag)
102   # We don't have libc++ (yet).
103   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
105   # Avoid checking whether the compiler is working.
106   set(LLVM_COMPILER_CHECKED ON)
108   # Enable warnings, otherwise -w gets added to the cflags by HandleLLVMOptions
109   # resulting in unjustified successes by check_cxx_compiler_flag.
110   set(LLVM_ENABLE_WARNINGS ON)
112   # Handle common options used by all runtimes.
113   include(AddLLVM)
114   include(HandleLLVMOptions)
115   include(FindPythonInterp)
117   # Remove the -nostdlib++ option we've added earlier.
118   string(REPLACE "-nostdlib++" "" CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
120   # Use libtool instead of ar if you are both on an Apple host, and targeting Apple.
121   if(CMAKE_HOST_APPLE AND APPLE)
122     include(UseLibtool)
123   endif()
125   # This can be used to detect whether we're in the runtimes build.
126   set(RUNTIMES_BUILD ON)
128   foreach(entry ${runtimes})
129     get_filename_component(projName ${entry} NAME)
131     # TODO: Clean this up as part of an interface standardization
132     string(REPLACE "-" "_" canon_name ${projName})
133     string(TOUPPER ${canon_name} canon_name)
135     # The subdirectories need to treat this as standalone builds. D57992 tried
136     # to get rid of this, but the runtimes treat *_STANDALONE_BUILD=OFF as if
137     # llvm & clang are configured in the same CMake, and setup dependencies
138     # against their targets.
139     set(${canon_name}_STANDALONE_BUILD ON)
141     if(LLVM_RUNTIMES_LIBDIR_SUBDIR)
142       set(${canon_name}_LIBDIR_SUBDIR "${LLVM_RUNTIMES_LIBDIR_SUBDIR}" CACHE STRING "" FORCE)
143     endif()
145     # Setting a variable to let sub-projects detect which other projects
146     # will be included under here.
147     set(HAVE_${canon_name} ON)
148   endforeach()
150   # We do this in two loops so that HAVE_* is set for each runtime before the
151   # other runtimes are added.
152   foreach(entry ${runtimes})
153     get_filename_component(projName ${entry} NAME)
155     # Between each sub-project we want to cache and clear the LIT properties
156     set_property(GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
157     set_property(GLOBAL PROPERTY LLVM_LIT_PARAMS)
158     set_property(GLOBAL PROPERTY LLVM_LIT_DEPENDS)
159     set_property(GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
161     add_subdirectory(${entry} ${projName})
163     get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
164     get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
165     get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
166     get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
168     list(APPEND RUNTIMES_LIT_TESTSUITES ${LLVM_LIT_TESTSUITES})
169     list(APPEND RUNTIMES_LIT_PARAMS ${LLVM_LIT_PARAMS})
170     list(APPEND RUNTIMES_LIT_DEPENDS ${LLVM_LIT_DEPENDS})
171     list(APPEND RUNTIMES_LIT_EXTRA_ARGS ${LLVM_LIT_EXTRA_ARGS})
172   endforeach()
174   if(LLVM_INCLUDE_TESTS)
175     # Add a global check rule now that all subdirectories have been traversed
176     # and we know the total set of lit testsuites.
178     add_lit_target(check-runtimes
179       "Running all regression tests"
180       ${RUNTIMES_LIT_TESTSUITES}
181       PARAMS ${RUNTIMES_LIT_PARAMS}
182       DEPENDS ${RUNTIMES_LIT_DEPENDS}
183       ARGS ${RUNTIMES_LIT_EXTRA_ARGS}
184       )
185     add_custom_target(runtimes-test-depends DEPENDS ${RUNTIMES_LIT_DEPENDS})
186   endif()
188   get_property(SUB_COMPONENTS GLOBAL PROPERTY SUB_COMPONENTS)
189   if(SUB_COMPONENTS)
190     list(REMOVE_DUPLICATES SUB_COMPONENTS)
191     foreach(component ${SUB_COMPONENTS})
192       if(NOT TARGET ${component})
193         message(SEND_ERROR "Missing target for runtime component ${component}!")
194         continue()
195       endif()
197       if(TARGET check-${component})
198         list(APPEND SUB_CHECK_TARGETS check-${component})
199       endif()
201       if(TARGET install-${component})
202         list(APPEND SUB_INSTALL_TARGETS install-${component})
203       endif()
204       if(TARGET install-${component}-stripped)
205         list(APPEND SUB_INSTALL_TARGETS install-${component}-stripped)
206       endif()
207     endforeach()
209     if(LLVM_RUNTIMES_TARGET)
210       configure_file(
211         ${CMAKE_CURRENT_SOURCE_DIR}/Components.cmake.in
212         ${LLVM_BINARY_DIR}/runtimes/${LLVM_RUNTIMES_TARGET}/Components.cmake)
213     else()
214       configure_file(
215         ${CMAKE_CURRENT_SOURCE_DIR}/Components.cmake.in
216         ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
217     endif()
218   endif()
220 else() # if this is included from LLVM's CMake
221   include(LLVMExternalProjectUtils)
222   if (LLVM_EXTERNAL_LIBCXX_SOURCE_DIR AND "libcxx" IN_LIST LLVM_ENABLE_RUNTIMES)
223     # This looks wrong, but libcxx's build actually wants the header dir to be
224     # the root build dir, not the include directory.
225     set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR})
226     set(CXX_HEADER_TARGET runtime-libcxx-headers)
227     add_subdirectory(${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR}/include ${CXX_HEADER_TARGET})
228   endif()
230   if(NOT LLVM_BUILD_RUNTIMES)
231     set(EXTRA_ARGS EXCLUDE_FROM_ALL)
232   endif()
234   function(builtin_default_target compiler_rt_path)
235     cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
237     llvm_ExternalProject_Add(builtins
238                              ${compiler_rt_path}/lib/builtins
239                              DEPENDS ${ARG_DEPENDS}
240                              CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
241                                         -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
242                                         -DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_TRIPLE}
243                                         -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
244                                         -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE}
245                                         -DCMAKE_ASM_COMPILER_TARGET=${TARGET_TRIPLE}
246                                         -DCMAKE_C_COMPILER_WORKS=ON
247                                         -DCMAKE_ASM_COMPILER_WORKS=ON
248                              PASSTHROUGH_PREFIXES COMPILER_RT
249                              USE_TOOLCHAIN
250                              ${EXTRA_ARGS})
251   endfunction()
253   function(builtin_register_target compiler_rt_path target)
254     cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
256     string(REPLACE "-" ";" builtin_target_list ${target})
257     foreach(item ${builtin_target_list})
258       string(TOLOWER "${item}" item_lower)
259       if(item_lower MATCHES "darwin")
260         message(FATAL_ERROR "LLVM_BUILTIN_TARGETS isn't implemented for Darwin platform!")
261       endif()
262     endforeach()
264     get_cmake_property(variableNames VARIABLES)
265     foreach(variableName ${variableNames})
266       string(FIND "${variableName}" "BUILTINS_${target}" out)
267       if("${out}" EQUAL 0)
268         string(REPLACE "BUILTINS_${target}_" "" new_name ${variableName})
269         list(APPEND ${target}_extra_args "-D${new_name}=${${variableName}}")
270       endif()
271     endforeach()
273     llvm_ExternalProject_Add(builtins-${target}
274                              ${compiler_rt_path}/lib/builtins
275                              DEPENDS ${ARG_DEPENDS}
276                              CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
277                                         -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
278                                         -DLLVM_DEFAULT_TARGET_TRIPLE=${target}
279                                         -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
280                                         -DCMAKE_C_COMPILER_TARGET=${target}
281                                         -DCMAKE_ASM_COMPILER_TARGET=${target}
282                                         -DCMAKE_C_COMPILER_WORKS=ON
283                                         -DCMAKE_ASM_COMPILER_WORKS=ON
284                                         -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
285                                         ${${target}_extra_args}
286                              TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib llvm-nm llvm-objcopy llvm-objdump llvm-strip
287                              USE_TOOLCHAIN
288                              ${EXTRA_ARGS})
289   endfunction()
291   # If compiler-rt is present we need to build the builtin libraries first. This
292   # is required because the other runtimes need the builtin libraries present
293   # before the just-built compiler can pass the configuration tests.
294   get_compiler_rt_path(compiler_rt_path)
295   if(compiler_rt_path)
296     if(NOT LLVM_BUILTIN_TARGETS)
297       builtin_default_target(${compiler_rt_path}
298         DEPENDS clang-resource-headers)
299     else()
300       if("default" IN_LIST LLVM_BUILTIN_TARGETS)
301         builtin_default_target(${compiler_rt_path}
302           DEPENDS clang-resource-headers)
303         list(REMOVE_ITEM LLVM_BUILTIN_TARGETS "default")
304       else()
305         add_custom_target(builtins)
306         add_custom_target(install-builtins)
307         add_custom_target(install-builtins-stripped)
308       endif()
310       foreach(target ${LLVM_BUILTIN_TARGETS})
311         builtin_register_target(${compiler_rt_path} ${target}
312           DEPENDS clang-resource-headers)
314         add_dependencies(builtins builtins-${target})
315         add_dependencies(install-builtins install-builtins-${target})
316         add_dependencies(install-builtins-stripped install-builtins-${target}-stripped)
317       endforeach()
318     endif()
319     set(deps builtins)
320     # We don't need to depend on the builtins if we're building instrumented
321     # because the next stage will use the same compiler used to build this stage.
322     if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
323       add_dependencies(clang-bootstrap-deps builtins)
324     endif()
325   endif()
327   # We create a list the names of all the runtime projects in all uppercase and
328   # with dashes turned to underscores. This gives us the CMake variable prefixes
329   # for all variables that will apply to runtimes.
330   foreach(entry ${runtimes})
331     get_filename_component(projName ${entry} NAME)
332     string(REPLACE "-" "_" canon_name ${projName})
333     string(TOUPPER ${canon_name} canon_name)
334     list(APPEND prefixes ${canon_name})
336     string(FIND ${projName} "lib" LIB_IDX)
337     if(LIB_IDX EQUAL 0)
338       string(SUBSTRING ${projName} 3 -1 projName)
339     endif()
340     list(APPEND runtime_names ${projName})
341   endforeach()
343   if(LLVM_RUNTIME_BUILD_ID_LINK_TARGETS)
344     configure_file(
345       ${CMAKE_CURRENT_SOURCE_DIR}/llvm-strip-link.in
346       ${CMAKE_CURRENT_BINARY_DIR}/llvm-strip-link
347       @ONLY
348     )
349   endif()
351   function(runtime_default_target)
352     cmake_parse_arguments(ARG "" "" "DEPENDS;PREFIXES" ${ARGN})
354     include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
355     set(SUB_CHECK_TARGETS ${SUB_CHECK_TARGETS} PARENT_SCOPE)
356     set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
358     foreach(runtime_name ${runtime_names})
359       list(APPEND extra_targets
360         ${runtime_name}
361         install-${runtime_name}
362         install-${runtime_name}-stripped)
363       if(LLVM_INCLUDE_TESTS)
364         list(APPEND test_targets check-${runtime_name})
365       endif()
366     endforeach()
367     foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
368       if(NOT ${component} IN_LIST SUB_COMPONENTS)
369         list(APPEND extra_targets ${component} install-${component} install-${component}-stripped)
370       endif()
371     endforeach()
373     if(LLVM_INCLUDE_TESTS)
374       list(APPEND test_targets runtimes-test-depends check-runtimes)
375     endif()
377     llvm_ExternalProject_Add(runtimes
378                              ${CMAKE_CURRENT_SOURCE_DIR}
379                              DEPENDS ${ARG_DEPENDS} ${CXX_HEADER_TARGET}
380                              # Builtins were built separately above
381                              CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
382                                         -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
383                                         -DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_TRIPLE}
384                                         -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
385                                         -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
386                                         -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE}
387                                         -DCMAKE_CXX_COMPILER_TARGET=${TARGET_TRIPLE}
388                                         -DCMAKE_ASM_COMPILER_TARGET=${TARGET_TRIPLE}
389                                         -DCMAKE_C_COMPILER_WORKS=ON
390                                         -DCMAKE_CXX_COMPILER_WORKS=ON
391                                         -DCMAKE_ASM_COMPILER_WORKS=ON
392                              PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
393                                                   ${ARG_PREFIXES}
394                              EXTRA_TARGETS ${extra_targets}
395                                            ${test_targets}
396                                            ${SUB_COMPONENTS}
397                                            ${SUB_CHECK_TARGETS}
398                                            ${SUB_INSTALL_TARGETS}
399                              USE_TOOLCHAIN
400                              ${EXTRA_ARGS})
401   endfunction()
403   # runtime_register_target(target)
404   #   Utility function to register external runtime target.
405   function(runtime_register_target name target)
406     cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
407     include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
408     set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
410     set(${name}_deps ${ARG_DEPENDS})
411     if(NOT name STREQUAL target)
412       list(APPEND ${name}_deps runtimes-${target})
413     endif()
415     foreach(runtime_name ${runtime_names})
416       set(${runtime_name}-${name} ${runtime_name})
417       set(install-${runtime_name}-${name} install-${runtime_name})
418       set(install-${runtime_name}-${name}-stripped install-${runtime_name}-stripped)
419       list(APPEND ${name}_extra_targets ${runtime_name}-${name} install-${runtime_name}-${name} install-${runtime_name}-${name}-stripped)
420       if(LLVM_INCLUDE_TESTS)
421         set(check-${runtime_name}-${name} check-${runtime_name} )
422         list(APPEND ${name}_test_targets check-${runtime_name}-${name})
423       endif()
424     endforeach()
426     foreach(target_name IN LISTS SUB_COMPONENTS SUB_INSTALL_TARGETS)
427       set(${target_name}-${name} ${target_name})
428       list(APPEND ${name}_extra_targets ${target_name}-${name})
429     endforeach()
431     foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
432       set(${component}-${name} ${component})
433       set(install-${component}-${name} ${component})
434       list(APPEND ${name}_extra_targets ${component}-${name} install-${component}-${name})
435     endforeach()
437     if(LLVM_INCLUDE_TESTS)
438       set(runtimes-test-depends-${name} runtimes-test-depends)
439       set(check-runtimes-${name} check-runtimes)
440       list(APPEND ${name}_test_targets runtimes-test-depends-${name} check-runtimes-${name})
441       foreach(target_name IN LISTS SUB_CHECK_TARGETS)
442         set(${target_name}-${name} ${target_name})
443         list(APPEND ${name}_test_targets ${target_name}-${name})
444         list(APPEND test_targets ${target_name}-${name})
445       endforeach()
446       set(test_targets "${test_targets}" PARENT_SCOPE)
447     endif()
449     get_cmake_property(variableNames VARIABLES)
450     foreach(variableName ${variableNames})
451       string(FIND "${variableName}" "RUNTIMES_${name}_" out)
452       if("${out}" EQUAL 0)
453         string(REPLACE "RUNTIMES_${name}_" "" new_name ${variableName})
454         list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
455       endif()
456       string(FIND "${variableName}" "RUNTIMES_${target}_" out)
457       if("${out}" EQUAL 0)
458         string(REPLACE "RUNTIMES_${target}_" "" new_name ${variableName})
459         list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
460       endif()
461     endforeach()
463     if(NOT RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES)
464       string(REPLACE ";" "|" LLVM_ENABLE_RUNTIMES_PASSTHROUGH "${LLVM_ENABLE_RUNTIMES}")
465       list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH})
466     endif()
468     if(target IN_LIST LLVM_RUNTIME_BUILD_ID_LINK_TARGETS)
469       list(APPEND EXTRA_ARGS STRIP_TOOL ${CMAKE_CURRENT_BINARY_DIR}/llvm-strip-link)
470     endif()
472     llvm_ExternalProject_Add(runtimes-${name}
473                              ${CMAKE_CURRENT_SOURCE_DIR}
474                              DEPENDS ${${name}_deps} ${CXX_HEADER_TARGET}
475                              # Builtins were built separately above
476                              CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
477                                         -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
478                                         -DLLVM_DEFAULT_TARGET_TRIPLE=${target}
479                                         -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
480                                         -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
481                                         -DCMAKE_C_COMPILER_TARGET=${target}
482                                         -DCMAKE_CXX_COMPILER_TARGET=${target}
483                                         -DCMAKE_ASM_COMPILER_TARGET=${target}
484                                         -DCMAKE_C_COMPILER_WORKS=ON
485                                         -DCMAKE_CXX_COMPILER_WORKS=ON
486                                         -DCMAKE_ASM_COMPILER_WORKS=ON
487                                         -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
488                                         -DLLVM_RUNTIMES_TARGET=${name}
489                                         ${${name}_extra_args}
490                              TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib llvm-nm llvm-objcopy llvm-objdump llvm-strip
491                              EXTRA_TARGETS ${${name}_extra_targets}
492                                            ${${name}_test_targets}
493                              USE_TOOLCHAIN
494                              ${EXTRA_ARGS})
495   endfunction()
497   if(runtimes)
498     # Create a runtimes target that uses this file as its top-level CMake file.
499     # The runtimes target is a configuration of all the runtime libraries
500     # together in a single CMake invocaiton.
501     if(NOT LLVM_RUNTIME_TARGETS)
502       runtime_default_target(
503         DEPENDS ${deps}
504         PREFIXES ${prefixes})
505       set(test_targets check-runtimes)
506     else()
507       if("default" IN_LIST LLVM_RUNTIME_TARGETS)
508         runtime_default_target(
509           DEPENDS ${deps}
510           PREFIXES ${prefixes})
511         list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
512       else()
513         add_custom_target(runtimes)
514         add_custom_target(runtimes-configure)
515         add_custom_target(install-runtimes)
516         add_custom_target(install-runtimes-stripped)
517         if(LLVM_INCLUDE_TESTS)
518           add_custom_target(check-runtimes)
519           add_custom_target(runtimes-test-depends)
520           set(test_targets "")
521         endif()
522         if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
523           foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
524             add_custom_target(${component})
525             add_custom_target(install-${component})
526           endforeach()
527         endif()
528       endif()
530       foreach(name ${LLVM_RUNTIME_TARGETS})
531         runtime_register_target(${name} ${name}
532           DEPENDS ${deps})
534         add_dependencies(runtimes runtimes-${name})
535         add_dependencies(runtimes-configure runtimes-${name}-configure)
536         add_dependencies(install-runtimes install-runtimes-${name})
537         add_dependencies(install-runtimes-stripped install-runtimes-${name}-stripped)
538         if(LLVM_INCLUDE_TESTS)
539           add_dependencies(check-runtimes check-runtimes-${name})
540           add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
541         endif()
542       endforeach()
544       foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
545         foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
546           runtime_register_target(${name}+${multilib} ${name}
547             DEPENDS runtimes-${name}
548             CMAKE_ARGS -DLLVM_RUNTIMES_PREFIX=${name}/
549                        -DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib})
550           add_dependencies(runtimes runtimes-${name}+${multilib})
551           add_dependencies(runtimes-configure runtimes-${name}+${multilib}-configure)
552           add_dependencies(install-runtimes install-runtimes-${name}+${multilib})
553           add_dependencies(install-runtimes-stripped install-runtimes-${name}+${multilib}-stripped)
554         endforeach()
555       endforeach()
556     endif()
558     # TODO: This is a hack needed because the libcxx headers are copied into the
559     # build directory during configuration. Without that step the clang in the
560     # build directory cannot find the C++ headers in certain configurations.
561     # I need to build a mechanism for runtime projects to provide CMake code
562     # that executes at LLVM configuration time to handle this case.
563     if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
564       add_dependencies(clang-bootstrap-deps runtimes-configure)
565     endif()
567     if(LLVM_INCLUDE_TESTS)
568       set_property(GLOBAL APPEND PROPERTY LLVM_ADDITIONAL_TEST_DEPENDS runtimes-test-depends)
569       set_property(GLOBAL APPEND PROPERTY LLVM_ADDITIONAL_TEST_TARGETS check-runtimes)
571       set(RUNTIMES_TEST_DEPENDS
572           FileCheck
573           count
574           llvm-nm
575           llvm-objdump
576           llvm-xray
577           not
578           obj2yaml
579           sancov
580           sanstats
581           gtest_main
582           gtest
583         )
584       foreach(target ${test_targets} ${SUB_CHECK_TARGETS})
585         add_dependencies(${target} ${RUNTIMES_TEST_DEPENDS})
586       endforeach()
587     endif()
588   endif()
589 endif()