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
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})
12 message(FATAL_ERROR "LLVM_ENABLE_RUNTIMES requests ${proj} but directory not found: ${proj_dir}")
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}")
19 function(get_compiler_rt_path path)
20 set(all_runtimes ${runtimes})
21 foreach(name ${LLVM_RUNTIME_TARGETS})
22 foreach(proj ${RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES})
23 set(proj_dir "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
24 if(IS_DIRECTORY ${proj_dir} AND EXISTS ${proj_dir}/CMakeLists.txt)
25 list(APPEND all_runtimes ${proj_dir})
29 list(REMOVE_DUPLICATES all_runtimes)
30 foreach(entry ${all_runtimes})
31 get_filename_component(projName ${entry} NAME)
32 if("${projName}" MATCHES "compiler-rt")
33 set(${path} ${entry} PARENT_SCOPE)
39 include(LLVMExternalProjectUtils)
41 if(NOT LLVM_BUILD_RUNTIMES)
42 set(EXTRA_ARGS EXCLUDE_FROM_ALL)
45 function(check_apple_target triple builtin_or_runtime)
47 compiler-rt for Darwin builds for all platforms and architectures using a \
48 single configuration. Specify only a single darwin triple (e.g. x86_64-apple-darwin) \
49 in your targets list (and not a triple for a specific platform such as macos). \
50 You can use variables such as COMPILER_RT_ENABLE_IOS and DARWIN_ios_ARCHS to \
51 control the specific platforms and architectures to build.")
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}")
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.")
67 elseif(component_lower MATCHES "^ios|^macos|^tvos|^watchos")
68 message(FATAL_ERROR "${error}")
73 macro(set_enable_per_target_runtime_dir)
74 # May have been set by llvm/CMakeLists.txt.
75 if (NOT DEFINED LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
76 # AIX should fold 32-bit & 64-bit arch libraries into a single archive.
77 if (LLVM_TARGET_TRIPLE MATCHES "aix")
78 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR OFF)
80 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON)
85 function(builtin_default_target compiler_rt_path)
86 cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
88 set_enable_per_target_runtime_dir()
90 llvm_ExternalProject_Add(builtins
91 ${compiler_rt_path}/lib/builtins
92 DEPENDS ${ARG_DEPENDS}
93 CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
94 -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
95 -DLLVM_DEFAULT_TARGET_TRIPLE=${LLVM_TARGET_TRIPLE}
96 -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}
97 -DLLVM_CMAKE_DIR=${CMAKE_BINARY_DIR}
98 -DCMAKE_C_COMPILER_WORKS=ON
99 -DCMAKE_ASM_COMPILER_WORKS=ON
101 ${BUILTINS_CMAKE_ARGS}
102 PASSTHROUGH_PREFIXES COMPILER_RT
106 TARGET_TRIPLE ${LLVM_TARGET_TRIPLE}
111 function(builtin_register_target compiler_rt_path name)
112 cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;EXTRA_ARGS" ${ARGN})
114 set(${name}_extra_args ${ARG_CMAKE_ARGS})
115 get_cmake_property(variable_names VARIABLES)
116 foreach(variable_name ${variable_names})
117 string(FIND "${variable_name}" "BUILTINS_${name}" out)
119 string(REPLACE "BUILTINS_${name}_" "" new_name ${variable_name})
120 if(new_name STREQUAL CACHE_FILES)
121 foreach(cache IN LISTS ${variable_name})
122 list(APPEND ${name}_extra_args -C ${cache})
125 string(REPLACE ";" "|" new_value "${${variable_name}}")
126 list(APPEND ${name}_extra_args "-D${new_name}=${new_value}")
131 llvm_ExternalProject_Add(builtins-${name}
132 ${compiler_rt_path}/lib/builtins
133 DEPENDS ${ARG_DEPENDS}
134 CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
135 -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
136 -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
137 -DLLVM_CMAKE_DIR=${CMAKE_BINARY_DIR}
138 -DCMAKE_C_COMPILER_WORKS=ON
139 -DCMAKE_ASM_COMPILER_WORKS=ON
140 -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
142 ${${name}_extra_args}
145 ${EXTRA_ARGS} ${ARG_EXTRA_ARGS})
148 # If compiler-rt is present we need to build the builtin libraries first. This
149 # is required because the other runtimes need the builtin libraries present
150 # before the just-built compiler can pass the configuration tests.
151 get_compiler_rt_path(compiler_rt_path)
153 # If the user did not specify the targets infer them from the runtimes.
154 set(builtin_targets ${LLVM_BUILTIN_TARGETS})
155 if(NOT builtin_targets)
156 if("compiler-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
157 list(APPEND builtin_targets "default")
159 foreach(name ${LLVM_RUNTIME_TARGETS})
160 if("compiler-rt" IN_LIST RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES)
161 list(APPEND builtin_targets ${name})
165 if("default" IN_LIST builtin_targets)
166 builtin_default_target(${compiler_rt_path}
167 DEPENDS clang-resource-headers)
168 list(REMOVE_ITEM builtin_targets "default")
170 add_custom_target(builtins)
171 add_custom_target(install-builtins)
172 add_custom_target(install-builtins-stripped)
173 set_target_properties(
174 builtins install-builtins install-builtins-stripped
175 PROPERTIES FOLDER "Compiler-RT"
179 foreach(target ${builtin_targets})
180 check_apple_target(${target} builtin)
182 builtin_register_target(${compiler_rt_path} ${target}
183 DEPENDS clang-resource-headers
184 CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${target}
185 EXTRA_ARGS TARGET_TRIPLE ${target})
187 add_dependencies(builtins builtins-${target})
188 add_dependencies(install-builtins install-builtins-${target})
189 add_dependencies(install-builtins-stripped install-builtins-${target}-stripped)
191 set(builtins_dep builtins)
192 # We don't need to depend on the builtins if we're building instrumented
193 # because the next stage will use the same compiler used to build this stage.
194 if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
195 add_dependencies(clang-bootstrap-deps builtins)
199 function(_get_runtime_name name out_var)
200 string(FIND ${name} "lib" idx)
201 if(idx EQUAL 0 AND NOT ${name} STREQUAL "libc")
202 string(SUBSTRING ${name} 3 -1 name)
204 set(${out_var} ${name} PARENT_SCOPE)
207 # Create a list with the names of all the runtime projects in all uppercase and
208 # with dashes turned to underscores. This gives us the CMake variable `prefixes`
209 # for all variables that will apply to runtimes.
210 foreach(entry ${runtimes})
211 get_filename_component(name ${entry} NAME)
212 string(REPLACE "-" "_" canon_name ${name})
213 string(TOUPPER ${canon_name} canon_name)
214 list(APPEND prefixes ${canon_name})
215 if (${canon_name} STREQUAL "OPENMP")
216 list(APPEND prefixes "LIBOMP" "LIBOMPTARGET")
218 # Many compiler-rt options start with SANITIZER_ and DARWIN_ rather than
219 # COMPILER_RT_, so when compiler-rt is enabled, consider both.
220 if(canon_name STREQUAL "COMPILER_RT")
221 list(APPEND prefixes SANITIZER DARWIN)
223 if(canon_name STREQUAL "LIBC")
224 list(APPEND prefixes "LLVM_LIBC")
225 list(APPEND prefixes "LIBC_")
228 _get_runtime_name(${name} name)
229 list(APPEND RUNTIME_NAMES ${name})
232 function(runtime_default_target)
233 cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;PREFIXES" ${ARGN})
235 include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
236 set(SUB_CHECK_TARGETS ${SUB_CHECK_TARGETS} PARENT_SCOPE)
237 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
239 foreach(runtime_name ${RUNTIME_NAMES})
240 list(APPEND extra_targets
242 install-${runtime_name}
243 install-${runtime_name}-stripped)
244 if(LLVM_INCLUDE_TESTS)
245 list(APPEND test_targets check-${runtime_name})
248 foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
249 if(NOT ${component} IN_LIST SUB_COMPONENTS)
250 list(APPEND extra_targets install-${component} install-${component}-stripped)
254 if(LLVM_INCLUDE_TESTS)
255 set_property(GLOBAL APPEND PROPERTY LLVM_ALL_LIT_TESTSUITES "@${LLVM_BINARY_DIR}/runtimes/runtimes-bins/lit.tests")
256 list(APPEND test_targets runtimes-test-depends check-runtimes)
259 set_enable_per_target_runtime_dir()
261 llvm_ExternalProject_Add(runtimes
262 ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
263 DEPENDS ${ARG_DEPENDS}
264 # Builtins were built separately above
265 CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
266 -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
267 -DLLVM_DEFAULT_TARGET_TRIPLE=${LLVM_TARGET_TRIPLE}
268 -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
269 -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}
270 -DLLVM_BUILD_TOOLS=${LLVM_BUILD_TOOLS}
271 -DCMAKE_C_COMPILER_WORKS=ON
272 -DCMAKE_CXX_COMPILER_WORKS=ON
273 -DCMAKE_ASM_COMPILER_WORKS=ON
275 ${RUNTIMES_CMAKE_ARGS}
277 PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
279 CUDA # For runtimes that may look for the CUDA SDK (libc, offload)
281 EXTRA_TARGETS ${extra_targets}
285 ${SUB_INSTALL_TARGETS}
287 TARGET_TRIPLE ${LLVM_TARGET_TRIPLE}
292 # runtime_register_target(name)
293 # Utility function to register external runtime target.
294 function(runtime_register_target name)
295 cmake_parse_arguments(ARG "" "BASE_NAME" "DEPENDS;CMAKE_ARGS;EXTRA_ARGS" ${ARGN})
296 include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
297 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
299 set(runtime_names ${RUNTIME_NAMES})
300 foreach(_name IN ITEMS ${ARG_BASE_NAME} ${name})
301 if(RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)
303 foreach(entry ${RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES})
304 _get_runtime_name(${entry} runtime_name)
305 list(APPEND runtime_names ${runtime_name})
310 foreach(runtime_name ${runtime_names})
311 set(${runtime_name}-${name} ${runtime_name})
312 set(install-${runtime_name}-${name} install-${runtime_name})
313 set(install-${runtime_name}-${name}-stripped install-${runtime_name}-stripped)
314 list(APPEND ${name}_extra_targets ${runtime_name}-${name} install-${runtime_name}-${name} install-${runtime_name}-${name}-stripped)
315 if(LLVM_INCLUDE_TESTS)
316 set(check-${runtime_name}-${name} check-${runtime_name} )
317 list(APPEND ${name}_test_targets check-${runtime_name}-${name})
321 foreach(component IN LISTS SUB_COMPONENTS)
322 set(${component}-${name} ${component})
323 list(APPEND ${name}_extra_targets ${component}-${name})
326 foreach(target IN LISTS SUB_INSTALL_TARGETS)
327 set(${target}-${name} ${target})
328 set(${target}-${name}-stripped ${target}-stripped)
329 list(APPEND ${name}_extra_targets ${target}-${name} ${target}-${name}-stripped)
332 foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
333 if(NOT component IN_LIST SUB_COMPONENTS)
334 set(${component}-${name} ${component})
335 set(install-${component}-${name} install-${component})
336 set(install-${component}-${name}-stripped install-${component}-stripped)
337 list(APPEND ${name}_extra_targets ${component}-${name} install-${component}-${name} install-${component}-${name}-stripped)
341 if(LLVM_INCLUDE_TESTS)
342 set_property(GLOBAL APPEND PROPERTY LLVM_ALL_LIT_TESTSUITES "@${LLVM_BINARY_DIR}/runtimes/runtimes-${name}-bins/lit.tests")
343 set(runtimes-test-depends-${name} runtimes-test-depends)
344 set(check-runtimes-${name} check-runtimes)
345 list(APPEND ${name}_test_targets runtimes-test-depends-${name} check-runtimes-${name})
346 list(APPEND test_targets ${${name}_test_targets})
348 set(component_check_targets)
349 foreach(component IN LISTS LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
350 if(NOT "check-${component}" IN_LIST SUB_CHECK_TARGETS)
351 list(APPEND component_check_targets "check-${component}")
355 foreach(target IN LISTS SUB_CHECK_TARGETS component_check_targets)
356 set(${target}-${name} ${target})
357 list(APPEND ${name}_test_targets ${target}-${name})
358 list(APPEND test_targets ${target}-${name})
360 set(test_targets "${test_targets}" PARENT_SCOPE)
363 set(${name}_extra_args ${ARG_CMAKE_ARGS})
364 string(REPLACE ";" "|" LLVM_ENABLE_RUNTIMES_PASSTHROUGH "${LLVM_ENABLE_RUNTIMES}")
365 list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH})
366 list(APPEND ${name}_extra_args -DLLVM_USE_LINKER=${LLVM_USE_LINKER})
368 get_cmake_property(variable_names VARIABLES)
369 foreach(extra_name IN ITEMS ${ARG_BASE_NAME} ${name})
370 foreach(variable_name ${variable_names})
371 string(FIND "${variable_name}" "RUNTIMES_${extra_name}_" out)
373 string(REPLACE "RUNTIMES_${extra_name}_" "" new_name ${variable_name})
374 if(new_name STREQUAL CACHE_FILES)
375 foreach(cache IN LISTS ${variable_name})
376 list(APPEND ${name}_extra_args -C ${cache})
379 string(REPLACE ";" "|" new_value "${${variable_name}}")
380 list(APPEND ${name}_extra_args "-D${new_name}=${new_value}")
384 foreach(variable_name ${${name}_extra_args})
385 string(FIND "${variable_name}" "-DRUNTIMES_${extra_name}_" out)
387 string(REPLACE "-DRUNTIMES_${extra_name}_" "" new_name ${variable_name})
388 string(REPLACE ";" "|" new_value "${new_name}")
389 list(APPEND ${name}_extra_args "-D${new_value}")
394 set_enable_per_target_runtime_dir()
396 llvm_ExternalProject_Add(runtimes-${name}
397 ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
398 DEPENDS ${ARG_DEPENDS}
399 # Builtins were built separately above
400 CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=OFF
401 -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
402 -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
403 -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}
404 -DCMAKE_C_COMPILER_WORKS=ON
405 -DCMAKE_CXX_COMPILER_WORKS=ON
406 -DCMAKE_ASM_COMPILER_WORKS=ON
407 -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
408 -DLLVM_RUNTIMES_TARGET=${name}
410 ${${name}_extra_args}
411 EXTRA_TARGETS ${${name}_extra_targets}
412 ${${name}_test_targets}
415 ${EXTRA_ARGS} ${ARG_EXTRA_ARGS})
417 add_dependencies(runtimes runtimes-${name})
418 add_dependencies(runtimes-configure runtimes-${name}-configure)
419 add_dependencies(install-runtimes install-runtimes-${name})
420 add_dependencies(install-runtimes-stripped install-runtimes-${name}-stripped)
421 if(LLVM_INCLUDE_TESTS)
422 add_dependencies(check-runtimes check-runtimes-${name})
423 add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
425 foreach(runtime_name ${runtime_names})
426 if(NOT TARGET ${runtime_name})
427 add_custom_target(${runtime_name})
428 set_target_properties(${runtime_name} PROPERTIES FOLDER "${runtime_name}")
430 add_dependencies(${runtime_name} ${runtime_name}-${name})
431 if(NOT TARGET install-${runtime_name})
432 add_custom_target(install-${runtime_name})
433 set_target_properties(install-${runtime_name} PROPERTIES FOLDER "${runtime_name}")
435 add_dependencies(install-${runtime_name} install-${runtime_name}-${name})
436 if(NOT TARGET install-${runtime_name}-stripped)
437 add_custom_target(install-${runtime_name}-stripped)
438 set_target_properties(install-${runtime_name} PROPERTIES FOLDER "${runtime_name}")
440 add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}-stripped)
442 foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
443 add_dependencies(${component} ${component}-${name})
444 add_dependencies(install-${component} install-${component}-${name})
445 add_dependencies(install-${component}-stripped install-${component}-${name}-stripped)
449 # Check if we have any runtimes to build.
451 set(build_runtimes TRUE)
453 foreach(name ${LLVM_RUNTIME_TARGETS})
454 if(RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES)
455 set(build_runtimes TRUE)
460 # Create a runtimes target that uses this file as its top-level CMake file.
461 # The runtimes target is a configuration of all the runtime libraries
462 # together in a single CMake invocation.
464 set(extra_cmake_args "")
466 if(LLVM_INCLUDE_TESTS)
467 foreach(dep FileCheck
490 list(APPEND extra_deps ${dep})
495 # Forward user-provived system configuration to runtimes for requirement introspection.
496 # CMAKE_PREFIX_PATH is the search path for CMake packages.
497 if(CMAKE_PREFIX_PATH)
498 list(APPEND extra_cmake_args "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}")
500 # CMAKE_PROGRAM_PATH is the search path for executables such as python.
501 if(CMAKE_PROGRAM_PATH)
502 list(APPEND extra_cmake_args "-DCMAKE_PROGRAM_PATH=${CMAKE_PROGRAM_PATH}")
505 if("openmp" IN_LIST LLVM_ENABLE_RUNTIMES)
506 if (${LLVM_TOOL_FLANG_BUILD})
507 message(STATUS "Configuring build of omp_lib.mod and omp_lib_kinds.mod via flang")
508 set(LIBOMP_FORTRAN_MODULES_COMPILER "${CMAKE_BINARY_DIR}/bin/flang")
509 set(LIBOMP_MODULES_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}/flang")
510 # TODO: This is a workaround until flang becomes a first-class project
511 # in llvm/CMakeList.txt. Until then, this line ensures that flang is
512 # built before "openmp" is built as a runtime project. Besides "flang"
513 # to build the compiler, we also need to add "module_files" to make sure
514 # that all .mod files are also properly build.
515 list(APPEND extra_deps "flang" "module_files")
517 foreach(dep opt llvm-link llvm-extract clang clang-offload-packager)
519 list(APPEND extra_deps ${dep})
523 if("libc" IN_LIST LLVM_ENABLE_PROJECTS AND
524 (LLVM_LIBC_FULL_BUILD OR LLVM_LIBC_GPU_BUILD))
526 set(hdrgen_exe ${LIBC_HDRGEN_EXE})
528 if(TARGET ${LIBC_TABLEGEN_EXE})
529 set(hdrgen_exe $<TARGET_FILE:${LIBC_TABLEGEN_EXE}>)
531 set(hdrgen_exe ${LIBC_TABLEGEN_EXE})
533 set(hdrgen_deps ${LIBC_TABLEGEN_TARGET})
536 message(FATAL_ERROR "libc-hdrgen executable missing")
538 list(APPEND extra_cmake_args "-DLIBC_HDRGEN_EXE=${hdrgen_exe}")
539 list(APPEND extra_deps ${hdrgen_deps})
541 if(LLVM_LIBC_GPU_BUILD)
542 list(APPEND extra_cmake_args "-DLLVM_LIBC_GPU_BUILD=ON")
543 if("libc" IN_LIST RUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES)
544 if(TARGET amdhsa-loader)
545 list(APPEND extra_cmake_args
546 "-DRUNTIMES_amdgcn-amd-amdhsa_LIBC_GPU_LOADER_EXECUTABLE=$<TARGET_FILE:amdhsa-loader>")
547 list(APPEND extra_deps amdhsa-loader)
549 list(APPEND extra_cmake_args "-DRUNTIMES_amdgcn-amd-amdhsa_LLVM_LIBC_FULL_BUILD=ON")
551 if("libc" IN_LIST RUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES)
552 if(TARGET nvptx-loader)
553 list(APPEND extra_cmake_args
554 "-DRUNTIMES_nvptx64-nvidia-cuda_LIBC_GPU_LOADER_EXECUTABLE=$<TARGET_FILE:nvptx-loader>")
555 list(APPEND extra_deps nvptx-loader)
557 list(APPEND extra_cmake_args "-DRUNTIMES_nvptx64-nvidia-cuda_LLVM_LIBC_FULL_BUILD=ON")
559 if(TARGET clang-offload-packager)
560 list(APPEND extra_deps clang-offload-packager)
562 if(TARGET clang-nvlink-wrapper)
563 list(APPEND extra_deps clang-nvlink-wrapper)
566 if(LLVM_LIBC_FULL_BUILD)
567 list(APPEND extra_cmake_args "-DLLVM_LIBC_FULL_BUILD=ON")
570 if(NOT LLVM_RUNTIME_TARGETS)
571 runtime_default_target(
572 DEPENDS ${builtins_dep} ${extra_deps}
573 CMAKE_ARGS ${extra_cmake_args}
574 PREFIXES ${prefixes})
575 set(test_targets check-runtimes)
577 if("default" IN_LIST LLVM_RUNTIME_TARGETS)
578 runtime_default_target(
579 DEPENDS ${builtins_dep} ${extra_deps}
580 CMAKE_ARGS ${extra_cmake_args}
581 PREFIXES ${prefixes})
582 list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
584 add_custom_target(runtimes)
585 add_custom_target(runtimes-configure)
586 add_custom_target(install-runtimes)
587 add_custom_target(install-runtimes-stripped)
588 set_target_properties(
589 runtimes runtimes-configure install-runtimes install-runtimes-stripped
590 PROPERTIES FOLDER "Runtimes"
592 if(LLVM_INCLUDE_TESTS)
593 add_custom_target(check-runtimes)
594 add_custom_target(runtimes-test-depends)
595 set_target_properties(
596 check-runtimes runtimes-test-depends
597 PROPERTIES FOLDER "Runtimes"
601 if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
602 foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
603 add_custom_target(${component})
604 add_custom_target(install-${component})
605 add_custom_target(install-${component}-stripped)
606 set_target_properties(
607 ${component} install-${component} install-${component}-stripped
608 PROPERTIES FOLDER "${component}"
614 foreach(name ${LLVM_RUNTIME_TARGETS})
616 if (LLVM_BUILTIN_TARGETS)
617 set(builtins_dep_name "${builtins_dep}-${name}")
619 set(builtins_dep_name ${builtins_dep})
623 check_apple_target(${name} runtime)
625 runtime_register_target(${name}
626 DEPENDS ${builtins_dep_name} ${extra_deps}
627 CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${extra_cmake_args}
628 EXTRA_ARGS TARGET_TRIPLE ${name})
631 foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
632 foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
633 runtime_register_target(${name}+${multilib}
634 DEPENDS runtimes-${name}
635 CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name}
636 -DLLVM_RUNTIMES_PREFIX=${name}/
637 -DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
640 EXTRA_ARGS TARGET_TRIPLE ${name})
645 if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
646 # TODO: This is a hack needed because the libcxx headers are copied into the
647 # build directory during configuration. Without that step the clang in the
648 # build directory cannot find the C++ headers in certain configurations.
649 # I need to build a mechanism for runtime projects to provide CMake code
650 # that executes at LLVM configuration time to handle this case.
651 add_dependencies(clang-bootstrap-deps runtimes-configure)
652 # We need to add the runtimes as a dependency because compiler-rt can be
653 # built as part of runtimes and we need the profile runtime for PGO
654 add_dependencies(clang-bootstrap-deps runtimes)
655 # The bootstrap build will attempt to configure the offload runtime
656 # before the openmp project which will error out due to failing to
657 # find libomp.so. We must add omp as a dependency before runtimes
659 if("openmp" IN_LIST LLVM_ENABLE_PROJECTS AND "offload" IN_LIST LLVM_ENABLE_RUNTIMES)
660 add_dependencies(clang-bootstrap-deps omp)
664 if(LLVM_INCLUDE_TESTS)
665 set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_DEPENDS runtimes-test-depends)
667 foreach(target ${test_targets} ${SUB_CHECK_TARGETS})
668 add_dependencies(${target} ${extra_deps})
671 set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_TARGETS runtimes ${extra_deps})