[Openmp-commits] [openmp] [OpenMP] Add libomp unit test infrastructure (PR #168063)

Michael Kruse via Openmp-commits openmp-commits at lists.llvm.org
Wed Dec 17 06:08:59 PST 2025


================
@@ -0,0 +1,63 @@
+add_custom_target(OpenMPUnitTests)
+set_target_properties(OpenMPUnitTests PROPERTIES FOLDER "OpenMP/Tests")
+
+if(WIN32 OR STUBS_LIBRARY)
+  message(WARNING "OpenMP unittests disabled due to stub library or Windows")
+  return()
+endif()
+
+# Build a testing version of libomp that exports all symbols for unit tests.
+# This library uses the same compiled objects as libomp, but with all symbols
+# exported to allow testing internal functions.
+
+libomp_get_ldflags(LIBOMP_TEST_LDFLAGS FOR_UNITTESTS)
+libomp_get_libflags(LIBOMP_TEST_LIBFLAGS)
+
+# Create the testing library from the same objects as libomp.
+add_library(omp_testing SHARED $<TARGET_OBJECTS:obj.omp>)
+set_property(TARGET omp_testing PROPERTY FOLDER "OpenMP/Libraries")
+target_link_libraries(omp_testing PUBLIC default_gtest)
+target_link_libraries(omp_testing PUBLIC ${LIBOMP_TEST_LIBFLAGS} ${LIBOMP_DL_LIBS})
+set_target_properties(omp_testing PROPERTIES
+  PREFIX "" SUFFIX "" OUTPUT_NAME "libomp_testing${LIBOMP_LIBRARY_SUFFIX}"
+  LINK_FLAGS "${LIBOMP_TEST_LDFLAGS}"
+  LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}
+  EXCLUDE_FROM_ALL TRUE  # Don't build by default, only when tests need it
----------------
Meinersbur wrote:

```suggestion
```
`EXCLUDE_FROM_ALL` can be also just part of `add_library`:
```
add_library(omp_testing ... EXCLUDE_FROM_ALL)
```

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


More information about the Openmp-commits mailing list