brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.2 KiB · e8f70bd Raw
286 lines · plain
1#===-- lib/runtime/CMakeLists.txt ------------------------------------------===#2#3# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4# See https://llvm.org/LICENSE.txt for license information.5# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6#7#===------------------------------------------------------------------------===#8 9include(AddFlangRTOffload)10# function checks11find_package(Backtrace)12set(HAVE_BACKTRACE ${Backtrace_FOUND})13set(BACKTRACE_HEADER ${Backtrace_HEADER})14 15# List of files that are buildable for all devices.16set(supported_sources17  ${FLANG_SOURCE_DIR}/lib/Decimal/binary-to-decimal.cpp18  ${FLANG_SOURCE_DIR}/lib/Decimal/decimal-to-binary.cpp19  ISO_Fortran_binding.cpp20  allocator-registry.cpp21  allocatable.cpp22  array-constructor.cpp23  assign.cpp24  buffer.cpp25  character.cpp26  connection.cpp27  copy.cpp28  derived-api.cpp29  derived.cpp30  descriptor-io.cpp31  descriptor.cpp32  dot-product.cpp33  edit-input.cpp34  edit-output.cpp35  environment.cpp36  external-unit.cpp37  extrema.cpp38  file.cpp39  findloc.cpp40  format.cpp41  inquiry.cpp42  internal-unit.cpp43  io-api.cpp44  io-api-minimal.cpp45  io-error.cpp46  io-stmt.cpp47  iostat.cpp48  matmul-transpose.cpp49  matmul.cpp50  memory.cpp51  misc-intrinsic.cpp52  namelist.cpp53  non-tbp-dio.cpp54  numeric.cpp55  pointer.cpp56  product.cpp57  pseudo-unit.cpp58  ragged.cpp59  reduction.cpp60  stat.cpp61  stop.cpp62  sum.cpp63  support.cpp64  terminator.cpp65  tools.cpp66  transformational.cpp67  type-code.cpp68  type-info.cpp69  unit.cpp70  utf.cpp71  work-queue.cpp72)73 74# List of source not used for GPU offloading.75set(host_sources76  ${FLANG_SOURCE_DIR}/module/iso_fortran_env_impl.f9077  command.cpp78  complex-powi.cpp79  complex-reduction.c80  exceptions.cpp81  execute.cpp82  extensions.cpp83  main.cpp84  random.cpp85  reduce.cpp86  reduction.cpp87  stop.cpp88  temporary-stack.cpp89  time-intrinsic.cpp90  unit-map.cpp91)92 93# Sources that can be compiled directly for the GPU.94set(gpu_sources95  ${FLANG_SOURCE_DIR}/lib/Decimal/binary-to-decimal.cpp96  ${FLANG_SOURCE_DIR}/lib/Decimal/decimal-to-binary.cpp97  ISO_Fortran_binding.cpp98  allocator-registry.cpp99  allocatable.cpp100  array-constructor.cpp101  assign.cpp102  buffer.cpp103  character.cpp104  connection.cpp105  copy.cpp106  derived-api.cpp107  derived.cpp108  dot-product.cpp109  edit-output.cpp110  extrema.cpp111  findloc.cpp112  format.cpp113  inquiry.cpp114  internal-unit.cpp115  io-error.cpp116  iostat.cpp117  matmul-transpose.cpp118  matmul.cpp119  memory.cpp120  misc-intrinsic.cpp121  non-tbp-dio.cpp122  numeric.cpp123  pointer.cpp124  product.cpp125  ragged.cpp126  stat.cpp127  sum.cpp128  support.cpp129  terminator.cpp130  tools.cpp131  transformational.cpp132  type-code.cpp133  type-info.cpp134  utf.cpp135  work-queue.cpp136  complex-powi.cpp137  reduce.cpp138  reduction.cpp139  temporary-stack.cpp140)141 142file(GLOB_RECURSE public_headers143  "${FLANG_RT_SOURCE_DIR}/include/flang_rt/*.h"144  "${FLANG_SOURCE_DIR}/include/flang/Common/*.h"145  )146 147file(GLOB_RECURSE private_headers148  "${FLANG_RT_SOURCE_DIR}/lib/flang_rt/*.h"149  "${FLANG_SOURCE_DIR}/lib/Common/*.h"150  )151 152 153# Import changes from flang_rt.quadmath154get_target_property(f128_sources155  FortranFloat128MathILib INTERFACE_SOURCES156  )157if (f128_sources)158  # The interface may define special macros for Float128Math files,159  # so we need to propagate them.160  get_target_property(f128_defs161    FortranFloat128MathILib INTERFACE_COMPILE_DEFINITIONS162    )163  set_property(SOURCE ${f128_sources}164    APPEND PROPERTY COMPILE_DEFINITIONS165    ${f128_defs}166    )167  get_target_property(f128_include_dirs168    FortranFloat128MathILib INTERFACE_INCLUDE_DIRECTORIES169    )170  set_property(SOURCE ${f128_sources}171    APPEND PROPERTY INCLUDE_DIRECTORIES172    ${f128_include_dirs}173    )174else ()175  set(f128_sources "")176endif ()177 178if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn|^nvptx")179  set(sources ${gpu_sources})180elseif(FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")181  set(sources ${supported_sources})182else ()183  set(sources ${supported_sources} ${host_sources} ${f128_sources})184endif ()185 186 187if (NOT WIN32)188  add_flangrt_library(flang_rt.runtime STATIC SHARED189    ${sources}190    LINK_LIBRARIES ${Backtrace_LIBRARY}191    INSTALL_WITH_TOOLCHAIN192    ADDITIONAL_HEADERS ${public_headers} ${private_headers}193  )194 195  enable_cuda_compilation(flang_rt.runtime "${supported_sources}")196  enable_omp_offload_compilation(flang_rt.runtime "${supported_sources}")197 198  # Select a default runtime, which is used for unit and regression tests.199  get_target_property(default_target flang_rt.runtime.default ALIASED_TARGET)200  add_library(flang_rt.runtime.unittest ALIAS "${default_target}")201else()202  # Target for building all versions of the runtime203  add_custom_target(flang_rt.runtime)204  set_target_properties(flang_rt.runtime PROPERTIES FOLDER "Flang-RT/Meta")205 206  function (add_win_flangrt_runtime libtype suffix msvc_lib)207    set(name "flang_rt.runtime.${suffix}")208    add_flangrt_library(${name} ${libtype}209        ${sources}210        ${ARGN}211        LINK_LIBRARIES ${Backtrace_LIBRARY}212        ADDITIONAL_HEADERS ${public_headers} ${private_headers}213      )214 215    if (msvc_lib)216      set_target_properties(${name}217          PROPERTIES218            MSVC_RUNTIME_LIBRARY "${msvc_lib}"219        )220    endif ()221 222    # Setting an unique Fortran_MODULE_DIRECTORY is required for each variant to223    # write a different .mod file.224    set_target_properties(${name}225        PROPERTIES226          Fortran_MODULE_DIRECTORY "module.${suffix}"227      )228 229    enable_cuda_compilation(${name} "${supported_sources}")230    enable_omp_offload_compilation(${name} "${supported_sources}")231    add_dependencies(flang_rt.runtime ${name})232  endfunction ()233 234  # Variants of the static flang_rt for different versions of the msvc runtime.235  #236  # The dynamic/dynamic_dbg variants are not DLLs themselves, only require237  # linking to msvcrt(d).dll.238  # FIXME: Generating actual runtime DLLs is currently not possible. There are239  # two roadblocks:240  #241  #  * Flang emits /DEFAULTLIB:flang_rt.dynamic.lib into242  #    iso_fortran_env_impl.f90.obj. Because that file is itself part of243  #    flang_rt.dynamic, this results in a recursive dependency when invoking244  #    the linker.245  #246  #  * The externally-visible functions must either be annotated with247  #    __declspec(dllexport), or listed in an exports file. A possible workaround248  #    is CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS which would also export the internal249  #    C++ symbols and still requires global data symbols to be annotated250  #    manually.251  add_win_flangrt_runtime(STATIC static      MultiThreaded         INSTALL_WITH_TOOLCHAIN)252  add_win_flangrt_runtime(STATIC static_dbg  MultiThreadedDebug    INSTALL_WITH_TOOLCHAIN)253  add_win_flangrt_runtime(STATIC dynamic     MultiThreadedDLL      INSTALL_WITH_TOOLCHAIN)254  add_win_flangrt_runtime(STATIC dynamic_dbg MultiThreadedDebugDLL INSTALL_WITH_TOOLCHAIN)255 256  # Unittests link against LLVMSupport. If CMAKE_MSVC_RUNTIME_LIBRARY is set,257  # that will have been used for LLVMSupport so it must also be used here.258  # Otherwise this will use CMake's default runtime library selection, which259  # is either MultiThreadedDLL or MultiThreadedDebugDLL depending on the configuration.260  # They have to match or linking will fail.261  if (GENERATOR_IS_MULTI_CONFIG)262    # We cannot select an ALIAS library because it may be different263    # per configuration. Fallback to CMake's default.264    add_win_flangrt_runtime(STATIC unittest "" EXCLUDE_FROM_ALL)265  else ()266    # Check if CMAKE_MSVC_RUNTIME_LIBRARY was set.267    if (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreaded")268        add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.static)269    elseif (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDLL")270        add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic)271    elseif (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDebug")272        add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.static_dbg)273    elseif (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDebugDLL")274        add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic_dbg)275    else()276      # Default based on the build type.277      string(TOLOWER ${CMAKE_BUILD_TYPE} build_type)278      if (build_type STREQUAL "debug")279          add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic_dbg)280      else ()281          add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic)282      endif ()283    endif()284  endif ()285endif()286