@@ -51,7 +51,7 @@ add_library(omptest
5151)
5252
5353# Target: ompTest library
54- # On (implicit) request of GoogleTest, link against the one provided with LLVM.
54+ # On (implicit) request of GoogleTest, embed the sources provided with LLVM.
5555if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
5656 # Check if standalone build was requested together with unittests
5757 if (LIBOMPTEST_BUILD_STANDALONE)
@@ -65,26 +65,56 @@ if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
6565 set (LIBOMPTEST_BUILD_STANDALONE OFF )
6666 endif ()
6767
68- # Add dependency llvm_gtest; emits error if unavailable.
69- add_dependencies (omptest llvm_gtest)
68+ # Set and check GTest's source directory.
69+ set (OMPTEST_GTEST_PATH ${LLVM_THIRD_PARTY_DIR} /unittest/googletest)
70+ if (NOT EXISTS "${OMPTEST_GTEST_PATH} /src/gtest-all.cc" )
71+ message (FATAL_ERROR "Missing gtest-all.cc under ${OMPTEST_GTEST_PATH} . "
72+ "Make sure LLVM_THIRD_PARTY_DIR is set properly." )
73+ endif ()
74+
75+ # Build GTest as OBJECT library, so we can merge it into omptest.
76+ add_library (omptest_gtest OBJECT "${OMPTEST_GTEST_PATH} /src/gtest-all.cc" )
7077
71- # Link llvm_gtest as whole-archive to expose required symbols
72- set (GTEST_LINK_CMD "-Wl,--whole-archive" llvm_gtest
73- "-Wl,--no-whole-archive" LLVMSupport)
78+ # Ensure PIC for inclusion into a shared library on ELF platforms.
79+ set_target_properties (omptest_gtest PROPERTIES POSITION_INDEPENDENT_CODE ON )
7480
75- # Add GoogleTest-based header
76- target_sources (omptest PRIVATE ./include /OmptTesterGoogleTest.h)
81+ # Set GTest include directories for omptest_gtest
82+ target_include_directories (omptest_gtest PRIVATE
83+ "${OMPTEST_GTEST_PATH} "
84+ "${OMPTEST_GTEST_PATH} /include"
85+ )
7786
78- # Add LLVM-provided GoogleTest include directories.
79- target_include_directories (omptest PRIVATE
80- ${LLVM_THIRD_PARTY_DIR} /unittest/googletest/include )
87+ # Set GTest include directories for omptest
88+ target_include_directories (omptest PUBLIC
89+ $<BUILD_INTERFACE:${OMPTEST_GTEST_PATH} >
90+ $<BUILD_INTERFACE:${OMPTEST_GTEST_PATH} /include >
91+ )
8192
82- # TODO: Re-visit ABI breaking checks, disable for now.
83- target_compile_definitions (omptest PUBLIC
84- -DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING)
93+ # Avoid using LLVM-specific ostream helpers inside GoogleTest.
94+ target_compile_definitions (omptest_gtest PRIVATE GTEST_NO_LLVM_SUPPORT=1)
8595
86- # Link against gtest and gtest_main
87- target_link_libraries (omptest PRIVATE ${GTEST_LINK_CMD} )
96+ # Add GoogleTest-based header and merge GTest into the shared lib.
97+ target_sources (omptest PRIVATE
98+ ./include /OmptTesterGoogleTest.h
99+ $<TARGET_OBJECTS:omptest_gtest>
100+ )
101+
102+ # Link against LLVMSupport and Threads (recommended for GTest).
103+ find_package (Threads REQUIRED)
104+ target_link_libraries (omptest PUBLIC LLVMSupport Threads::Threads)
105+
106+ # Ensure that embedded GTest symbols are exported from libomptest.so even in
107+ # builds that default to hidden.
108+ set_target_properties (omptest PROPERTIES
109+ CXX_VISIBILITY_PRESET default
110+ VISIBILITY_INLINES_HIDDEN OFF
111+ )
112+
113+ # Make sure correct include directories are used, e.g. by the unit tests.
114+ # Otherwise, ABI-checks may fail.
115+ if (DEFINED LLVM_INCLUDE_DIRS)
116+ target_include_directories (omptest PUBLIC ${LLVM_INCLUDE_DIRS} )
117+ endif ()
88118else ()
89119 # Add 'standalone' compile definitions
90120 target_compile_definitions (omptest PRIVATE
0 commit comments