[Openmp-commits] [openmp] [OpenMP] Add libomp unit test infrastructure (PR #168063)
Robert Imschweiler via Openmp-commits
openmp-commits at lists.llvm.org
Wed Dec 17 08:26:08 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
----------------
ro-i wrote:
```
add_library(omp_testing SHARED $<TARGET_OBJECTS:obj.omp> EXCLUDE_FROM_ALL)
```
whould lead to
```
CMake Error at .../llvm-project/openmp/runtime/unittests/CMakeLists.txt:17 (add_library):
Cannot find source file:
EXCLUDE_FROM_ALL
CMake Error at .../llvm-project/openmp/runtime/unittests/CMakeLists.txt:17 (add_library):
No SOURCES given to target: omp_testing
```
tho
https://github.com/llvm/llvm-project/pull/168063
More information about the Openmp-commits
mailing list