brintos

brintos / llvm-project-archived public Read only

0
0
Text · 28.2 KiB · d877f0b Raw
679 lines · plain
1# TODO: This file assumes the Clang toolchain so it'd be better if it lived in2# Clang, except there already is clang/runtime directory which contains3# similar although simpler functionality. We should figure out how to merge4# the two files.5 6set(COMMON_CMAKE_ARGS "-DHAVE_LLVM_LIT=ON;-DCLANG_RESOURCE_DIR=${CLANG_RESOURCE_DIR}")7foreach(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}")17endforeach()18 19function(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})26      endif()27    endforeach()28  endforeach()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)34      return()35    endif()36  endforeach()37endfunction()38 39include(LLVMExternalProjectUtils)40 41if(NOT LLVM_BUILD_RUNTIMES)42  set(EXTRA_ARGS EXCLUDE_FROM_ALL)43endif()44 45function(check_apple_target triple builtin_or_runtime)46  set(error "\47compiler-rt for Darwin builds for all platforms and architectures using a \48single configuration. Specify only a single darwin triple (e.g. x86_64-apple-darwin) \49in your targets list (and not a triple for a specific platform such as macos). \50You can use variables such as COMPILER_RT_ENABLE_IOS and DARWIN_ios_ARCHS to \51control the specific platforms and architectures to build.")52 53  set(seen_property ${builtin_or_runtime}_darwin_triple_seen)54  string(REPLACE "-" ";" triple_components ${triple})55  foreach(component ${triple_components})56    string(TOLOWER "${component}" component_lower)57    if(component_lower MATCHES "^darwin")58      get_property(darwin_triple_seen GLOBAL PROPERTY ${seen_property})59      if(darwin_triple_seen)60        message(FATAL_ERROR "${error}")61      endif()62      set_property(GLOBAL PROPERTY ${seen_property} YES)63      if(NOT RUNTIMES_BUILD_ALLOW_DARWIN)64        message(FATAL_ERROR "\65${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.")66      endif()67    elseif(component_lower MATCHES "^ios|^macos|^tvos|^watchos")68      message(FATAL_ERROR "${error}")69    endif()70  endforeach()71endfunction()72 73macro(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    set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON)77  endif()78endmacro()79 80function(builtin_default_target compiler_rt_path)81  cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})82 83  set_enable_per_target_runtime_dir()84 85  llvm_ExternalProject_Add(builtins86                           ${compiler_rt_path}/lib/builtins87                           DEPENDS ${ARG_DEPENDS}88                           CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}89                                      -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}90                                      -DLLVM_DEFAULT_TARGET_TRIPLE=${LLVM_TARGET_TRIPLE}91                                      -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}92                                      -DLLVM_CMAKE_DIR=${CMAKE_BINARY_DIR}93                                      -DCMAKE_C_COMPILER_WORKS=ON94                                      -DCMAKE_CXX_COMPILER_WORKS=ON95                                      -DCMAKE_ASM_COMPILER_WORKS=ON96                                      ${COMMON_CMAKE_ARGS}97                                      ${BUILTINS_CMAKE_ARGS}98                           PASSTHROUGH_PREFIXES COMPILER_RT99                                                DARWIN100                                                SANITIZER101                           USE_TOOLCHAIN102                           TARGET_TRIPLE ${LLVM_TARGET_TRIPLE}103                           FOLDER "Compiler-RT"104                           ${EXTRA_ARGS})105endfunction()106 107function(builtin_register_target compiler_rt_path name)108  cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;EXTRA_ARGS" ${ARGN})109 110  set(${name}_extra_args ${ARG_CMAKE_ARGS})111  get_cmake_property(variable_names VARIABLES)112  foreach(variable_name ${variable_names})113    string(FIND "${variable_name}" "BUILTINS_${name}" out)114    if("${out}" EQUAL 0)115      string(REPLACE "BUILTINS_${name}_" "" new_name ${variable_name})116      if(new_name STREQUAL CACHE_FILES)117        foreach(cache IN LISTS ${variable_name})118          list(APPEND ${name}_extra_args -C ${cache})119        endforeach()120      else()121        string(REPLACE ";" "|" new_value "${${variable_name}}")122        list(APPEND ${name}_extra_args "-D${new_name}=${new_value}")123      endif()124    endif()125  endforeach()126 127  llvm_ExternalProject_Add(builtins-${name}128                           ${compiler_rt_path}/lib/builtins129                           DEPENDS ${ARG_DEPENDS}130                           CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}131                                      -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}132                                      -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON133                                      -DLLVM_CMAKE_DIR=${CMAKE_BINARY_DIR}134                                      -DCMAKE_C_COMPILER_WORKS=ON135                                      -DCMAKE_CXX_COMPILER_WORKS=ON136                                      -DCMAKE_ASM_COMPILER_WORKS=ON137                                      -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON138                                      ${COMMON_CMAKE_ARGS}139                                      ${${name}_extra_args}140                           USE_TOOLCHAIN141                           FOLDER "Compiler-RT"142                           ${EXTRA_ARGS} ${ARG_EXTRA_ARGS})143endfunction()144 145# If compiler-rt is present we need to build the builtin libraries first. This146# is required because the other runtimes need the builtin libraries present147# before the just-built compiler can pass the configuration tests.148get_compiler_rt_path(compiler_rt_path)149if(compiler_rt_path)150  # If the user did not specify the targets infer them from the runtimes.151  set(builtin_targets ${LLVM_BUILTIN_TARGETS})152  if(NOT builtin_targets)153    if("compiler-rt" IN_LIST LLVM_ENABLE_RUNTIMES)154      list(APPEND builtin_targets "default")155    endif()156    foreach(name ${LLVM_RUNTIME_TARGETS})157      if("compiler-rt" IN_LIST RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES)158        list(APPEND builtin_targets ${name})159      endif()160    endforeach()161  endif()162  if("default" IN_LIST builtin_targets)163    builtin_default_target(${compiler_rt_path}164      DEPENDS clang-resource-headers)165    list(REMOVE_ITEM builtin_targets "default")166  else()167    add_custom_target(builtins)168    add_custom_target(install-builtins)169    add_custom_target(install-builtins-stripped)170    set_target_properties(171      builtins install-builtins install-builtins-stripped172      PROPERTIES FOLDER "Compiler-RT"173    )174  endif()175 176  foreach(target ${builtin_targets})177    check_apple_target(${target} builtin)178 179    builtin_register_target(${compiler_rt_path} ${target}180      DEPENDS clang-resource-headers181      CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${target}182      EXTRA_ARGS TARGET_TRIPLE ${target})183 184    add_dependencies(builtins builtins-${target})185    add_dependencies(install-builtins install-builtins-${target})186    add_dependencies(install-builtins-stripped install-builtins-${target}-stripped)187  endforeach()188  set(builtins_dep builtins)189  # We don't need to depend on the builtins if we're building instrumented190  # because the next stage will use the same compiler used to build this stage.191  if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)192    add_dependencies(clang-bootstrap-deps builtins)193  endif()194endif()195 196function(_get_runtime_name name out_var)197  string(FIND ${name} "lib" idx)198  if(idx EQUAL 0 AND NOT (${name} STREQUAL "libc" OR ${name} STREQUAL "libclc"))199    string(SUBSTRING ${name} 3 -1 name)200  endif()201  set(${out_var} ${name} PARENT_SCOPE)202endfunction()203 204# Create a list with the names of all the runtime projects in all uppercase and205# with dashes turned to underscores. This gives us the CMake variable `prefixes`206# for all variables that will apply to runtimes.207foreach(entry ${runtimes})208  get_filename_component(name ${entry} NAME)209  string(REPLACE "-" "_" canon_name ${name})210  string(TOUPPER ${canon_name} canon_name)211  list(APPEND prefixes ${canon_name})212  if (${canon_name} STREQUAL "OPENMP")213    list(APPEND prefixes "LIBOMP" "LIBOMPTARGET")214  endif()215  # Many compiler-rt options start with SANITIZER_ and DARWIN_ rather than216  # COMPILER_RT_, so when compiler-rt is enabled, consider both.217  if(canon_name STREQUAL "COMPILER_RT")218    list(APPEND prefixes SANITIZER DARWIN)219  endif()220  if(canon_name STREQUAL "LIBC")221    list(APPEND prefixes "LLVM_LIBC")222    list(APPEND prefixes "LIBC_")223  endif()224 225  _get_runtime_name(${name} name)226  list(APPEND RUNTIME_NAMES ${name})227endforeach()228 229function(runtime_default_target)230  cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;PREFIXES;EXTRA_ARGS" ${ARGN})231 232  include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)233  set(SUB_CHECK_TARGETS ${SUB_CHECK_TARGETS} PARENT_SCOPE)234  set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)235 236  foreach(runtime_name ${RUNTIME_NAMES})237    list(APPEND extra_targets238      ${runtime_name}239      install-${runtime_name}240      install-${runtime_name}-stripped)241    if(LLVM_INCLUDE_TESTS)242      list(APPEND test_targets check-${runtime_name})243    endif()244  endforeach()245  foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})246    if(NOT ${component} IN_LIST SUB_COMPONENTS)247      list(APPEND extra_targets install-${component} install-${component}-stripped)248    endif()249  endforeach()250  if ("openmp" IN_LIST LLVM_ENABLE_RUNTIMES)251    # The target libomp-mod is a dependee of check-flang needed to run its252    # OpenMP tests253    list(APPEND extra_targets "libomp-mod")254  endif ()255 256  if(LLVM_INCLUDE_TESTS)257    set_property(GLOBAL APPEND PROPERTY LLVM_ALL_LIT_TESTSUITES "@${LLVM_BINARY_DIR}/runtimes/runtimes-bins/lit.tests")258    list(APPEND test_targets runtimes-test-depends check-runtimes)259  endif()260 261  set_enable_per_target_runtime_dir()262 263  llvm_ExternalProject_Add(runtimes264                           ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes265                           DEPENDS ${ARG_DEPENDS}266                           # Builtins were built separately above267                           CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off268                                      -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}269                                      -DLLVM_DEFAULT_TARGET_TRIPLE=${LLVM_TARGET_TRIPLE}270                                      -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}271                                      -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}272                                      -DLLVM_BUILD_TOOLS=${LLVM_BUILD_TOOLS}273                                      -DCMAKE_C_COMPILER_WORKS=ON274                                      -DCMAKE_CXX_COMPILER_WORKS=ON275                                      -DCMAKE_Fortran_COMPILER_WORKS=ON276                                      -DCMAKE_ASM_COMPILER_WORKS=ON277                                      ${COMMON_CMAKE_ARGS}278                                      ${RUNTIMES_CMAKE_ARGS}279                                      ${ARG_CMAKE_ARGS}280                           PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES281                                                LLVM_USE_LINKER282                                                CUDA CMAKE_CUDA # For runtimes that may look for the CUDA compiler and/or SDK (libc, offload, flang-rt)283                                                FFI # offload uses libffi284                                                FLANG_RUNTIME # Shared between Flang and Flang-RT285                                                ${ARG_PREFIXES}286                           EXTRA_TARGETS ${extra_targets}287                                         ${test_targets}288                                         ${SUB_COMPONENTS}289                                         ${SUB_CHECK_TARGETS}290                                         ${SUB_INSTALL_TARGETS}291                           USE_TOOLCHAIN292                           TARGET_TRIPLE ${LLVM_TARGET_TRIPLE}293                           FOLDER "Runtimes"294                           ${EXTRA_ARGS} ${ARG_EXTRA_ARGS})295endfunction()296 297# runtime_register_target(name)298#   Utility function to register external runtime target.299function(runtime_register_target name)300  cmake_parse_arguments(ARG "" "BASE_NAME" "DEPENDS;CMAKE_ARGS;EXTRA_ARGS" ${ARGN})301  include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)302  set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)303 304  set(runtime_names ${RUNTIME_NAMES})305  foreach(_name IN ITEMS ${ARG_BASE_NAME} ${name})306    if(RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)307      set(runtime_names)308      foreach(entry ${RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES})309        _get_runtime_name(${entry} runtime_name)310        list(APPEND runtime_names ${runtime_name})311      endforeach()312    endif()313  endforeach()314 315  foreach(runtime_name ${runtime_names})316    set(${runtime_name}-${name} ${runtime_name})317    set(install-${runtime_name}-${name} install-${runtime_name})318    set(install-${runtime_name}-${name}-stripped install-${runtime_name}-stripped)319    list(APPEND ${name}_extra_targets ${runtime_name}-${name} install-${runtime_name}-${name} install-${runtime_name}-${name}-stripped)320    if(LLVM_INCLUDE_TESTS)321      set(check-${runtime_name}-${name} check-${runtime_name} )322      list(APPEND ${name}_test_targets check-${runtime_name}-${name})323    endif()324  endforeach()325 326  foreach(component IN LISTS SUB_COMPONENTS)327    set(${component}-${name} ${component})328    list(APPEND ${name}_extra_targets ${component}-${name})329  endforeach()330 331  foreach(target IN LISTS SUB_INSTALL_TARGETS)332    set(${target}-${name} ${target})333    set(${target}-${name}-stripped ${target}-stripped)334    list(APPEND ${name}_extra_targets ${target}-${name} ${target}-${name}-stripped)335  endforeach()336 337  foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})338    if(NOT component IN_LIST SUB_COMPONENTS)339      set(${component}-${name} ${component})340      set(install-${component}-${name} install-${component})341      set(install-${component}-${name}-stripped install-${component}-stripped)342      list(APPEND ${name}_extra_targets ${component}-${name} install-${component}-${name} install-${component}-${name}-stripped)343    endif()344  endforeach()345 346  if(LLVM_INCLUDE_TESTS)347    set_property(GLOBAL APPEND PROPERTY LLVM_ALL_LIT_TESTSUITES "@${LLVM_BINARY_DIR}/runtimes/runtimes-${name}-bins/lit.tests")348    set(runtimes-test-depends-${name} runtimes-test-depends)349    set(check-runtimes-${name} check-runtimes)350    list(APPEND ${name}_test_targets runtimes-test-depends-${name} check-runtimes-${name})351    list(APPEND test_targets ${${name}_test_targets})352 353    set(component_check_targets)354    foreach(component IN LISTS LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)355      if(NOT "check-${component}" IN_LIST SUB_CHECK_TARGETS)356        list(APPEND component_check_targets "check-${component}")357      endif()358    endforeach()359 360    foreach(target IN LISTS SUB_CHECK_TARGETS component_check_targets)361      set(${target}-${name} ${target})362      list(APPEND ${name}_test_targets ${target}-${name})363      list(APPEND test_targets ${target}-${name})364    endforeach()365    set(test_targets "${test_targets}" PARENT_SCOPE)366  endif()367 368  set(${name}_extra_args ${ARG_CMAKE_ARGS})369  string(REPLACE ";" "|" LLVM_ENABLE_RUNTIMES_PASSTHROUGH "${LLVM_ENABLE_RUNTIMES}")370  list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH})371  list(APPEND ${name}_extra_args -DLLVM_USE_LINKER=${LLVM_USE_LINKER})372 373  get_cmake_property(variable_names VARIABLES)374  foreach(extra_name IN ITEMS ${ARG_BASE_NAME} ${name})375    foreach(variable_name ${variable_names})376      string(FIND "${variable_name}" "RUNTIMES_${extra_name}_" out)377      if("${out}" EQUAL 0)378        string(REPLACE "RUNTIMES_${extra_name}_" "" new_name ${variable_name})379        if(new_name STREQUAL CACHE_FILES)380          foreach(cache IN LISTS ${variable_name})381            list(APPEND ${name}_extra_args -C ${cache})382          endforeach()383        else()384          string(REPLACE ";" "|" new_value "${${variable_name}}")385          list(APPEND ${name}_extra_args "-D${new_name}=${new_value}")386        endif()387      endif()388    endforeach()389    foreach(variable_name ${${name}_extra_args})390      string(FIND "${variable_name}" "-DRUNTIMES_${extra_name}_" out)391      if("${out}" EQUAL 0)392        string(REPLACE "-DRUNTIMES_${extra_name}_" "" new_name ${variable_name})393        string(REPLACE ";" "|" new_value "${new_name}")394        list(APPEND ${name}_extra_args "-D${new_value}")395      endif()396    endforeach()397  endforeach()398 399  set_enable_per_target_runtime_dir()400 401  llvm_ExternalProject_Add(runtimes-${name}402                           ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes403                           DEPENDS ${ARG_DEPENDS}404                           # Builtins were built separately above405                           CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=OFF406                                      -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}407                                      -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}408                                      -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}409                                      -DCMAKE_C_COMPILER_WORKS=ON410                                      -DCMAKE_CXX_COMPILER_WORKS=ON411                                      -DCMAKE_Fortran_COMPILER_WORKS=ON412                                      -DCMAKE_ASM_COMPILER_WORKS=ON413                                      -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON414                                      -DLLVM_RUNTIMES_TARGET=${name}415                                      ${COMMON_CMAKE_ARGS}416                                      ${${name}_extra_args}417                           EXTRA_TARGETS ${${name}_extra_targets}418                                         ${${name}_test_targets}419                           USE_TOOLCHAIN420                           FOLDER "Runtimes"421                           ${EXTRA_ARGS} ${ARG_EXTRA_ARGS})422 423  add_dependencies(runtimes runtimes-${name})424  add_dependencies(runtimes-configure runtimes-${name}-configure)425  add_dependencies(install-runtimes install-runtimes-${name})426  add_dependencies(install-runtimes-stripped install-runtimes-${name}-stripped)427  if(LLVM_INCLUDE_TESTS)428    add_dependencies(check-runtimes check-runtimes-${name})429    add_dependencies(runtimes-test-depends runtimes-test-depends-${name})430  endif()431  foreach(runtime_name ${runtime_names})432    if(NOT TARGET ${runtime_name})433      add_custom_target(${runtime_name})434      set_target_properties(${runtime_name} PROPERTIES FOLDER "${runtime_name}")435    endif()436    add_dependencies(${runtime_name} ${runtime_name}-${name})437    if(NOT TARGET install-${runtime_name})438      add_custom_target(install-${runtime_name})439      set_target_properties(install-${runtime_name} PROPERTIES FOLDER "${runtime_name}")440    endif()441    add_dependencies(install-${runtime_name} install-${runtime_name}-${name})442    if(NOT TARGET install-${runtime_name}-stripped)443      add_custom_target(install-${runtime_name}-stripped)444      set_target_properties(install-${runtime_name} PROPERTIES FOLDER "${runtime_name}")445    endif()446    add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}-stripped)447  endforeach()448  foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})449    add_dependencies(${component} ${component}-${name})450    add_dependencies(install-${component} install-${component}-${name})451    add_dependencies(install-${component}-stripped install-${component}-${name}-stripped)452  endforeach()453endfunction()454 455# Check if we have any runtimes to build.456if(runtimes)457  set(build_runtimes TRUE)458endif()459foreach(name ${LLVM_RUNTIME_TARGETS})460  if(RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES)461    set(build_runtimes TRUE)462  endif()463endforeach()464 465if(build_runtimes)466  # Create a runtimes target that uses this file as its top-level CMake file.467  # The runtimes target is a configuration of all the runtime libraries468  # together in a single CMake invocation.469  set(extra_deps "")470  set(extra_cmake_args "")471  set(extra_args "")472 473  if(LLVM_INCLUDE_TESTS)474    foreach(dep FileCheck475                clang476                flang477                count478                lld479                lli480                llvm-cov481                llvm-lto482                llvm-jitlink483                llvm-nm484                llvm-strip485                llvm-objdump486                llvm-profdata487                llvm-readobj488                llvm-size489                llvm-symbolizer490                llvm-xray491                llvm-offload-binary492                not493                obj2yaml494                opt495                sancov496                sanstats497                llvm_gtest_main498                llvm_gtest499                split-file)500      if(TARGET ${dep})501        list(APPEND extra_deps ${dep})502      endif()503    endforeach()504    if(WIN32)505      list(APPEND extra_deps KillTheDoctor)506    endif()507  endif()508 509  # Forward user-provived system configuration to runtimes for requirement introspection.510  # CMAKE_PREFIX_PATH is the search path for CMake packages.511  if(CMAKE_PREFIX_PATH)512    list(APPEND extra_cmake_args "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}")513  endif()514  # CMAKE_PROGRAM_PATH is the search path for executables such as python.515  if(CMAKE_PROGRAM_PATH)516    list(APPEND extra_cmake_args "-DCMAKE_PROGRAM_PATH=${CMAKE_PROGRAM_PATH}")517  endif()518 519  # TODO: We need to consider passing it as '-DRUNTIMES_x86_64_LLVM_ENABLE_RUNTIMES'.520  if("libclc" IN_LIST LLVM_ENABLE_RUNTIMES)521    foreach(dep clang llvm-as llvm-link opt)522      if(TARGET ${dep})523        list(APPEND extra_deps ${dep})524      endif()525    endforeach()526  endif()527  # Tools needed by build_symbolizer.sh.528  if("compiler-rt" IN_LIST LLVM_ENABLE_RUNTIMES AND COMPILER_RT_ENABLE_INTERNAL_SYMBOLIZER)529    foreach(dep clang llvm-tblgen opt llvm-ar llvm-link)530      if(TARGET ${dep})531        list(APPEND extra_deps ${dep})532      endif()533    endforeach()534  endif()535  # Allow openmp to see the Fortran compiler536  if ("openmp" IN_LIST LLVM_ENABLE_RUNTIMES AND "flang" IN_LIST LLVM_ENABLE_PROJECTS)537    list(APPEND extra_args ENABLE_FORTRAN)538  endif()539  if("openmp" IN_LIST LLVM_ENABLE_RUNTIMES OR "offload" IN_LIST LLVM_ENABLE_RUNTIMES)540    if (${LLVM_TOOL_FLANG_BUILD})541      message(STATUS "Configuring build of omp_lib.mod and omp_lib_kinds.mod via flang")542      set(LIBOMP_FORTRAN_MODULES_COMPILER "${CMAKE_BINARY_DIR}/bin/flang")543      set(LIBOMP_MODULES_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}/flang")544      # TODO: This is a workaround until flang becomes a first-class project545      # in llvm/CMakeList.txt.  Until then, this line ensures that flang is546      # built before "openmp" is built as a runtime project.  Besides "flang"547      # to build the compiler, we also need to add "module_files" to make sure548      # that all .mod files are also properly build.549      list(APPEND extra_deps "flang" "module_files")550    endif()551    foreach(dep opt llvm-link llvm-extract clang llvm-offload-binary clang-nvlink-wrapper)552      if(TARGET ${dep})553        list(APPEND extra_deps ${dep})554      endif()555    endforeach()556  endif()557  if(LLVM_LIBC_GPU_BUILD)558    list(APPEND extra_cmake_args "-DLLVM_LIBC_GPU_BUILD=ON")559    if(TARGET llvm-offload-binary)560      list(APPEND extra_deps llvm-offload-binary)561    endif()562    if(TARGET clang-nvlink-wrapper)563      list(APPEND extra_deps clang-nvlink-wrapper)564    endif()565  endif()566  if(LLVM_LIBC_FULL_BUILD)567    list(APPEND extra_cmake_args "-DLLVM_LIBC_FULL_BUILD=ON")568  endif()569  if("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)570    list(APPEND extra_args ENABLE_FORTRAN)571  endif ()572 573  if(NOT LLVM_RUNTIME_TARGETS)574    runtime_default_target(575      DEPENDS ${builtins_dep} ${extra_deps}576      CMAKE_ARGS ${extra_cmake_args}577      PREFIXES ${prefixes}578      EXTRA_ARGS ${extra_args})579    set(test_targets check-runtimes)580  else()581    if("default" IN_LIST LLVM_RUNTIME_TARGETS)582      runtime_default_target(583        DEPENDS ${builtins_dep} ${extra_deps}584        CMAKE_ARGS ${extra_cmake_args}585        PREFIXES ${prefixes}586        EXTRA_ARGS ${extra_args})587      list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")588    else()589      add_custom_target(runtimes)590      add_custom_target(runtimes-configure)591      add_custom_target(install-runtimes)592      add_custom_target(install-runtimes-stripped)593      set_target_properties(594        runtimes runtimes-configure install-runtimes install-runtimes-stripped595        PROPERTIES FOLDER "Runtimes"596      )597      if(LLVM_INCLUDE_TESTS)598        add_custom_target(check-runtimes)599        add_custom_target(runtimes-test-depends)600        set_target_properties(601          check-runtimes runtimes-test-depends602          PROPERTIES FOLDER "Runtimes"603        )604        set(test_targets "")605      endif()606      if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)607        foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})608          add_custom_target(${component})609          add_custom_target(install-${component})610          add_custom_target(install-${component}-stripped)611          set_target_properties(612            ${component} install-${component} install-${component}-stripped613            PROPERTIES FOLDER "${component}"614          )615        endforeach()616      endif()617    endif()618 619    foreach(name ${LLVM_RUNTIME_TARGETS})620      if(builtins_dep)621        if (LLVM_BUILTIN_TARGETS)622          set(builtins_dep_name "${builtins_dep}-${name}")623        else()624          set(builtins_dep_name ${builtins_dep})625        endif()626      endif()627 628      check_apple_target(${name} runtime)629 630      runtime_register_target(${name}631        DEPENDS ${builtins_dep_name} ${extra_deps}632        CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${extra_cmake_args}633        EXTRA_ARGS TARGET_TRIPLE ${name} ${extra_args})634    endforeach()635 636    foreach(multilib ${LLVM_RUNTIME_MULTILIBS})637      foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})638        runtime_register_target(${name}+${multilib}639          DEPENDS runtimes-${name}640          CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name}641                     -DLLVM_RUNTIMES_PREFIX=${name}/642                     -DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}643                     ${extra_cmake_args}644          BASE_NAME ${name}645          EXTRA_ARGS TARGET_TRIPLE ${name} ${extra_args})646      endforeach()647    endforeach()648  endif()649 650  if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)651    # TODO: This is a hack needed because the libcxx headers are copied into the652    # build directory during configuration. Without that step the clang in the653    # build directory cannot find the C++ headers in certain configurations.654    # I need to build a mechanism for runtime projects to provide CMake code655    # that executes at LLVM configuration time to handle this case.656    add_dependencies(clang-bootstrap-deps runtimes-configure)657    # We need to add the runtimes as a dependency because compiler-rt can be658    # built as part of runtimes and we need the profile runtime for PGO659    add_dependencies(clang-bootstrap-deps runtimes)660    # The bootstrap build will attempt to configure the offload runtime661    # before the openmp project which will error out due to failing to662    # find libomp.so. We must add omp as a dependency before runtimes663    # are configured.664    if("openmp" IN_LIST LLVM_ENABLE_PROJECTS AND "offload" IN_LIST LLVM_ENABLE_RUNTIMES)665      add_dependencies(clang-bootstrap-deps omp)666    endif()667  endif()668 669  if(LLVM_INCLUDE_TESTS)670    set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_DEPENDS runtimes-test-depends)671 672    foreach(target ${test_targets} ${SUB_CHECK_TARGETS})673      add_dependencies(${target} ${extra_deps})674    endforeach()675 676    set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_TARGETS runtimes ${extra_deps})677  endif()678endif()679