[Openmp-commits] [openmp] Reland: [OpenMP] Add ompTest library to OpenMP (PR #154786)

Michael Halkenhäuser via Openmp-commits openmp-commits at lists.llvm.org
Tue Sep 16 05:48:45 PDT 2025


================
@@ -0,0 +1,154 @@
+##===----------------------------------------------------------------------===##
+#
+# Build OMPT unit testing library: ompTest
+#
+##===----------------------------------------------------------------------===##
+
+cmake_minimum_required(VERSION 3.20)
+project(omptest LANGUAGES CXX)
+
+option(LIBOMPTEST_BUILD_STANDALONE
+       "Build ompTest 'standalone', i.e. w/o GoogleTest."
+       ${OPENMP_STANDALONE_BUILD})
+option(LIBOMPTEST_BUILD_UNITTESTS
+       "Build ompTest's unit tests, requires GoogleTest." OFF)
+
+# In absence of corresponding OMPT support: exit early
+if(NOT ${LIBOMP_OMPT_SUPPORT})
+  return()
+endif()
+
+include(CMakePackageConfigHelpers)
+
+set(OMPTEST_HEADERS
+  ./include/AssertMacros.h
+  ./include/InternalEvent.h
+  ./include/InternalEventCommon.h
+  ./include/Logging.h
+  ./include/OmptAliases.h
+  ./include/OmptAsserter.h
+  ./include/OmptAssertEvent.h
+  ./include/OmptCallbackHandler.h
+  ./include/OmptTester.h
+  ./include/OmptTesterGlobals.h
+)
+
+add_library(omptest
+  SHARED
+
+  ${OMPTEST_HEADERS}
+  ./src/InternalEvent.cpp
+  ./src/InternalEventOperators.cpp
+  ./src/Logging.cpp
+  ./src/OmptAsserter.cpp
+  ./src/OmptAssertEvent.cpp
+  ./src/OmptCallbackHandler.cpp
+  ./src/OmptTester.cpp
+)
+
+# Target: ompTest library
+# On (implicit) request of GoogleTest, link against the one provided with LLVM.
+if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
+  # Check if standalone build was requested together with unittests
+  if (LIBOMPTEST_BUILD_STANDALONE)
+    # Emit warning: this build actually depends on LLVM's GoogleTest
+    message(WARNING "LIBOMPTEST_BUILD_STANDALONE and LIBOMPTEST_BUILD_UNITTESTS"
+                    " requested simultaneously.\n"
+                    "Linking against LLVM's GoogleTest library archives.\n"
+                    "Disable LIBOMPTEST_BUILD_UNITTESTS to perform an actual"
+                    " standalone build.")
+    # Explicitly disable LIBOMPTEST_BUILD_STANDALONE
+    set(LIBOMPTEST_BUILD_STANDALONE OFF)
+  endif()
+
+  # Make sure target llvm_gtest is available
+  if (NOT TARGET llvm_gtest)
+    message(FATAL_ERROR "Required target not found: llvm_gtest")
+  endif()
+
+  # Add llvm_gtest as dependency
+  add_dependencies(omptest llvm_gtest)
+
+  # Link llvm_gtest as whole-archive to expose required symbols
+  set(GTEST_LINK_CMD "-Wl,--whole-archive" llvm_gtest
+                     "-Wl,--no-whole-archive" LLVMSupport)
----------------
mhalk wrote:

Actually "yes", ompTest should be usable like an OMPT-extended version of GoogleTest.
Thus, my goal is pulling in all symbols, but I'm by no means an expert on this matter.

The issue is that without it, there are linker errors because of missing symbols, like e.g. `testing::Test::Test()` or `testing::internal::GTestLog::~GTestLog()`.
Advice on how to improve this part would be greatly appreciated.

One possibility I saw was to use an intermediate build file, similar to this:
```cmake
  [...]

  set(GTEST_OBJECT "build/third-party/unittest/CMakeFiles/llvm_gtest.dir/googletest/src/gtest-all.cc.o")

  # Add GoogleTest-based header and merge pre-built object
  target_sources(omptest PRIVATE
    ./include/OmptTesterGoogleTest.h
    "${GTEST_OBJECT}")

  [...]
```
Apart from locating that file properly, I'm not sure which other dependencies this approach would imply (maybe `compiler-rt`?).

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


More information about the Openmp-commits mailing list