[llvm] [offload] Fix enabling unittests in standalone builds (PR #138418)

via llvm-commits llvm-commits at lists.llvm.org
Sat May 3 10:32:59 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-offload

Author: Michał Górny (mgorny)

<details>
<summary>Changes</summary>

Modify the unittest logic in offload to only look for `third-party/unittest` directory when `llvm_gtest` is not provided by LLVM itself (in-tree or installed).  This makes it possible to run unittests in sparse checkouts without the `third-party/unittest` tree.

While at it, also make sure `LLVM_THIRD_PARTY_DIR` is actually set while performing standalone builds.  The logic is copied from `compiler-rt`.

---
Full diff: https://github.com/llvm/llvm-project/pull/138418.diff


1 Files Affected:

- (modified) offload/CMakeLists.txt (+7-4) 


``````````diff
diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt
index 25c879710645c..ef10d9c949d0b 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -386,9 +386,12 @@ add_subdirectory(liboffload)
 add_subdirectory(test)
 
 # Add unit tests if GMock/GTest is present
-if (EXISTS ${LLVM_THIRD_PARTY_DIR}/unittest)
-  if (NOT TARGET llvm_gtest)
-    add_subdirectory(${LLVM_THIRD_PARTY_DIR}/unittest ${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest)
-  endif()
+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()

``````````

</details>


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


More information about the llvm-commits mailing list