
The Offload and Flang-RT had the ability to compile GTest themselves. But in bootstrapping builds, LLVM_LIBRARY_OUTPUT_INTDIR points to the same location as the stage1 build. If both are building GTest, they everwrite each others `libllvm_gtest.a` and `libllvm_test_main.a` which causes #143134. This PR removes the ability for the Offload/Flang-RT runtimes to build their own GTest and instead relies on the stage1 build of GTest. This was already the case with LLVM_INSTALL_GTEST=ON configurations. For LLVM_INSTALL_GTEST=OFF configurations, we now also export gtest into the buildtree configuration. Ultimately, this reduces combinatorial explosion of configurations in which unittests could be built (LLVM_INSTALL_GTEST=ON, GTest built by Offload, GTest built by Flang-RT, GTest built by Offload and also used by Flang-RT). GTest and therefore Offload/Runtime unittests will not be available if the runtimes are configured against an LLVM install tree. Since llvm-lit isn't available in the install tree either, it doesn't matter. Note that compiler-rt and libc also use GTest in non-default configrations. libc also depends on LLVM's GTest build (and would error-out if unavailable), but compiler-rt builds it completely different. Fixes #143134
112 lines
3.4 KiB
CMake
112 lines
3.4 KiB
CMake
#===-- unittests/CMakeLists.txt --------------------------------------------===#
|
|
#
|
|
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
# See https://llvm.org/LICENSE.txt for license information.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
#
|
|
#===------------------------------------------------------------------------===#
|
|
|
|
# Target that depends on all unittests
|
|
add_custom_target(FlangRTUnitTests)
|
|
set_target_properties(FlangRTUnitTests PROPERTIES FOLDER "Flang-RT/Meta")
|
|
|
|
# LLVM uses a modified version of GTest that uses LLVMSupport for console
|
|
# output. We are using the pre-compiled GTest library from the LLVM build,
|
|
# if available. Otherwise, do nothing.
|
|
|
|
if (CMAKE_CROSSCOMPILING)
|
|
# TODO: It is possible that LLVM_GTEST_RUN_UNDER defines an emulator or
|
|
# ssh remote command invocation; for this case provide an option to
|
|
# enable unittests.
|
|
message(STATUS "Flang-RT unittests disabled because we are cross-compiling")
|
|
return ()
|
|
endif ()
|
|
|
|
if (NOT TARGET llvm_gtest)
|
|
message(WARNING "Flang-RT unittests disabled due to GTest being unavailable; "
|
|
"Try LLVM_INSTALL_GTEST=ON for the LLVM build")
|
|
return ()
|
|
endif ()
|
|
|
|
|
|
add_dependencies(flang-rt-test-depends
|
|
FlangRTUnitTests
|
|
flang_rt.runtime.unittest
|
|
)
|
|
|
|
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
|
|
add_compile_options("-Wno-suggest-override")
|
|
endif()
|
|
|
|
|
|
function(add_flangrt_unittest_offload_properties target)
|
|
# Set CUDA_RESOLVE_DEVICE_SYMBOLS.
|
|
if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")
|
|
set_target_properties(${target}
|
|
PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON
|
|
)
|
|
endif()
|
|
# Enable OpenMP offload during linking. We may need to replace
|
|
# LINK_OPTIONS with COMPILE_OPTIONS when there are OpenMP offload
|
|
# unittests.
|
|
#
|
|
# FIXME: replace 'native' in --offload-arch option with the list
|
|
# of targets that Fortran Runtime was built for.
|
|
if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "OpenMP")
|
|
set_target_properties(${target}
|
|
PROPERTIES LINK_OPTIONS
|
|
"-fopenmp;--offload-arch=native"
|
|
)
|
|
endif()
|
|
endfunction()
|
|
|
|
|
|
function(add_flangrt_unittest test_dirname)
|
|
cmake_parse_arguments(ARG
|
|
""
|
|
""
|
|
"LINK_LIBS"
|
|
${ARGN})
|
|
|
|
add_unittest(FlangRTUnitTests ${test_dirname} ${ARG_UNPARSED_ARGUMENTS})
|
|
|
|
target_link_libraries(${test_dirname} PRIVATE ${ARG_LINK_LIBS})
|
|
add_flangrt_unittest_offload_properties(${test_dirname})
|
|
|
|
# Required because LLVMSupport is compiled with this option.
|
|
# FIXME: According to CMake documentation, this is the default. Why is it
|
|
# needed? LLVM's add_unittest doesn't set it either.
|
|
set_target_properties(${test_dirname}
|
|
PROPERTIES
|
|
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL"
|
|
)
|
|
endfunction()
|
|
|
|
function(add_flangrt_nongtest_unittest test_name)
|
|
cmake_parse_arguments(ARG
|
|
"SLOW_TEST"
|
|
""
|
|
"LINK_LIBS"
|
|
${ARGN})
|
|
|
|
if(ARG_SLOW_TEST)
|
|
set(suffix .slow)
|
|
else()
|
|
set(suffix .test)
|
|
endif()
|
|
|
|
add_executable(${test_name}${suffix} EXCLUDE_FROM_ALL ${ARG_UNPARSED_ARGUMENTS})
|
|
set_target_properties(${test_name}${suffix} PROPERTIES FOLDER "Flang-RT/Tests/Unit")
|
|
|
|
target_link_libraries(${test_name}${suffix} PRIVATE NonGTestTesting ${ARG_LINK_LIBS})
|
|
|
|
if(NOT ARG_SLOW_TEST)
|
|
add_dependencies(FlangRTUnitTests ${test_name}${suffix})
|
|
endif()
|
|
|
|
add_flangrt_unittest_offload_properties(${test_name}${suffix})
|
|
endfunction()
|
|
|
|
add_subdirectory(Evaluate)
|
|
add_subdirectory(Runtime)
|