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

Michał Górny via llvm-commits llvm-commits at lists.llvm.org
Sat May 3 10:32:29 PDT 2025


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

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`.

>From f979508959acf8dc813db7de3f742798291fa32c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny at gentoo.org>
Date: Sat, 3 May 2025 19:27:46 +0200
Subject: [PATCH] [offload] Fix enabling unittests in standalone builds

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`.
---
 offload/CMakeLists.txt | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

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()



More information about the llvm-commits mailing list