[llvm] [Flang-RT][Offload] Always use LLVM-built GTest (PR #143682)

David Spickett via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 11 07:06:17 PDT 2025


================
@@ -6,33 +6,39 @@
 #
 #===------------------------------------------------------------------------===#
 
+# 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. Therefore it also needs to include files from LLVM. Unfortunately,
-# LLVM/GTest doesn't add the include search path itself. Limiting the scope
-# using target_include_directories does not work because with
-# LLVM_INSTALL_GTEST=ON, as llvm_gtest is an IMPORT library.
-include_directories("${LLVM_INCLUDE_DIR}" "${LLVM_MAIN_INCLUDE_DIR}")
-
-# Add GTest if not already present.
-# Using a function so LLVM_SUBPROJECT_TITLE does not propagate.
-function (build_gtest)
-  set(LLVM_SUBPROJECT_TITLE "Third-Party/Google Test")
-  add_subdirectory("${LLVM_THIRD_PARTY_DIR}/unittest" "${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest")
-endfunction ()
+# 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)
-  build_gtest()
+  message(WARNING "Flang-RT unittests disabled due to GTest being unavailable; "
+                  "Try LLVM_INSTALL_GTEST=ON for the LLVM build")
----------------
DavidSpickett wrote:

This would be hit usually when you've `ninja install`-ed the LLVM build and are building standalone against that?

If you're building against a build directory, that will work regardless of the value of LLVM_INSTALL_GTEST, as you explained in the PR description.

https://github.com/llvm/llvm-project/pull/143682


More information about the llvm-commits mailing list