brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.6 KiB · e1ab73d Raw
132 lines · plain
1#===-- unittests/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 9# Target that depends on all unittests10add_custom_target(FlangRTUnitTests)11set_target_properties(FlangRTUnitTests PROPERTIES FOLDER "Flang-RT/Meta")12 13# LLVM uses a modified version of GTest that uses LLVMSupport for console14# output. We are using the pre-compiled GTest library from the LLVM build,15# if available. Otherwise, do nothing.16 17if (CMAKE_CROSSCOMPILING)18  # TODO: It is possible that LLVM_GTEST_RUN_UNDER defines an emulator or19  #       ssh remote command invocation; for this case provide an option to20  #       enable unittests.21  message(STATUS "Flang-RT unittests disabled because we are cross-compiling")22  return ()23endif ()24 25# Make the targets default_gtest and default_gtest_main available.26build_gtest()27 28add_dependencies(flang-rt-test-depends29  FlangRTUnitTests30  flang_rt.runtime.unittest31)32 33if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)34  add_compile_options("-Wno-suggest-override")35endif()36 37 38function(add_flangrt_unittest_offload_properties target)39  # Set CUDA_RESOLVE_DEVICE_SYMBOLS.40  if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")41    set_target_properties(${target}42      PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON43      )44  endif()45  # Enable OpenMP offload during linking. We may need to replace46  # LINK_OPTIONS with COMPILE_OPTIONS when there are OpenMP offload47  # unittests.48  #49  # FIXME: replace 'native' in --offload-arch option with the list50  #        of targets that Fortran Runtime was built for.51  if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "OpenMP")52    set_target_properties(${target}53      PROPERTIES LINK_OPTIONS54      "-fopenmp;--offload-arch=native"55      )56  endif()57endfunction()58 59# flang-rt on Windows requires compiler-rt for some symbols. For binaries built60# with flang this dependency is added by the flang driver, but since the unit61# tests are built with clang we need to add the dependency manually.62function(add_flangrt_dependent_libs target)63  if (MSVC AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")64    if (FLANG_RT_BUILTINS_LIBRARY)65      target_compile_options(${target} PRIVATE "$<$<COMPILE_LANGUAGE:CXX,C>:-Xclang>" "$<$<COMPILE_LANGUAGE:CXX,C>:--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}>")66    endif ()67  endif ()68  if (MSVC AND CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")69    if (FLANG_RT_BUILTINS_LIBRARY)70      target_compile_options(${target} PRIVATE "$<$<COMPILE_LANGUAGE:Fortran>:-Xflang>" "$<$<COMPILE_LANGUAGE:Fortran>:--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}>")71    else ()72      message(WARNING "Did not find libclang_rt.builtins.lib.73        LLVM may emit builtins that are not implemented in msvcrt/ucrt and74        instead falls back to builtins from Compiler-RT. Linking with ${tgtname}75        may result in a linker error.")76    endif ()77  elseif (APPLE)78    # Clang on Darwin enables non-POSIX extensions by default.79    # This causes some macros to leak, such as HUGE from <math.h>, which80    # causes some conflicts with Flang symbols (but not with Flang-RT, for81    # now).82    # It also causes some Flang-RT extensions to be disabled, such as fdate,83    # that checks for _POSIX_C_SOURCE.84    # Setting _POSIX_C_SOURCE avoids these issues.85    target_compile_options(${target} PRIVATE "-D_POSIX_C_SOURCE=200809")86  endif ()87endfunction()88 89 90function(add_flangrt_unittest test_dirname)91  cmake_parse_arguments(ARG92    ""93    ""94    "LINK_LIBS"95    ${ARGN})96 97  add_unittest(FlangRTUnitTests ${test_dirname} ${ARG_UNPARSED_ARGUMENTS})98 99  target_link_libraries(${test_dirname} PRIVATE ${ARG_LINK_LIBS})100  add_flangrt_unittest_offload_properties(${test_dirname})101  add_flangrt_dependent_libs(${test_dirname})102endfunction()103 104function(add_flangrt_nongtest_unittest test_name)105  cmake_parse_arguments(ARG106    "SLOW_TEST"107    ""108    "LINK_LIBS"109    ${ARGN})110 111  if(ARG_SLOW_TEST)112      set(suffix .slow)113  else()114      set(suffix .test)115  endif()116 117  add_executable(${test_name}${suffix} EXCLUDE_FROM_ALL ${ARG_UNPARSED_ARGUMENTS})118  set_target_properties(${test_name}${suffix} PROPERTIES FOLDER "Flang-RT/Tests/Unit")119 120  target_link_libraries(${test_name}${suffix} PRIVATE NonGTestTesting ${ARG_LINK_LIBS})121  add_flangrt_dependent_libs(${test_name}${suffix})122 123  if(NOT ARG_SLOW_TEST)124    add_dependencies(FlangRTUnitTests ${test_name}${suffix})125  endif()126 127  add_flangrt_unittest_offload_properties(${test_name}${suffix})128endfunction()129 130add_subdirectory(Evaluate)131add_subdirectory(Runtime)132