diff options
| author | Michael Kruse <llvm-project@meinersbur.de> | 2025-07-09 12:53:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-09 12:53:33 +0200 |
| commit | 4be3e95284a028bca54f08ded6dc2e8d4ac2ec75 (patch) | |
| tree | 884974f91196db96846e0c32be96003c1eface7d /offload | |
| parent | fbb2fa92cb72e426c942d48f0189b70bbd8e476a (diff) | |
[Flang-RT][Offload] Always use LLVM-built GTest (#143682)
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
Diffstat (limited to 'offload')
| -rw-r--r-- | offload/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | offload/unittests/CMakeLists.txt | 14 |
2 files changed, 15 insertions, 11 deletions
diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt index 0a441c3bc578..d49069f6eb42 100644 --- a/offload/CMakeLists.txt +++ b/offload/CMakeLists.txt @@ -380,15 +380,5 @@ add_subdirectory(liboffload) # Add tests. if(OFFLOAD_INCLUDE_TESTS) add_subdirectory(test) - - # Add unit tests if GMock/GTest is present - if(NOT LLVM_THIRD_PARTY_DIR) - set(LLVM_THIRD_PARTY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../third-party") - endif() - if(EXISTS ${LLVM_THIRD_PARTY_DIR}/unittest AND NOT TARGET llvm_gtest) - add_subdirectory(${LLVM_THIRD_PARTY_DIR}/unittest ${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest) - endif() - if(TARGET llvm_gtest) - add_subdirectory(unittests) - endif() + add_subdirectory(unittests) endif() diff --git a/offload/unittests/CMakeLists.txt b/offload/unittests/CMakeLists.txt index 1eae785b8765..388d15f834b1 100644 --- a/offload/unittests/CMakeLists.txt +++ b/offload/unittests/CMakeLists.txt @@ -1,6 +1,20 @@ add_custom_target(OffloadUnitTests) set_target_properties(OffloadUnitTests PROPERTIES FOLDER "Tests/UnitTests") +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 "Offload unittests disabled because we are cross-compiling") + return () +endif () + +if (NOT TARGET llvm_gtest) + message(WARNING "Offload unittests disabled due to GTest being unavailable; " + "Try LLVM_INSTALL_GTEST=ON for the LLVM build") + return () +endif () + function(add_offload_test_device_code test_filename test_name) set(SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${test_filename}) set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) |
