Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions openmp/tools/omptest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ 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})
"Build ompTest 'standalone', i.e. w/o GoogleTest." OFF)
option(LIBOMPTEST_BUILD_UNITTESTS
"Build ompTest's unit tests, requires GoogleTest." OFF)
option(LIBOMPTEST_INSTALL_COMPONENTS
Expand All @@ -20,6 +19,15 @@ if((NOT ${LIBOMP_OMPT_SUPPORT}) OR (NOT ${LLVM_INCLUDE_TESTS}))
return()
endif()

# Only support OpenMP runtime 'bootstrap' build mode.
# Check as seen in 'runtimes/CMakeLists.txt', due to passing HAVE_LLVM_LIT to
# llvm_ExternalProject_Add() only.
if (NOT HAVE_LLVM_LIT)
message(STATUS "Skipping omptest build. Reason: Only supported in bootstrap"
" build mode of OpenMP runtime.")
return()
endif()

include(CMakePackageConfigHelpers)

include_directories(${LIBOMP_INCLUDE_DIR})
Expand Down Expand Up @@ -51,7 +59,7 @@ add_library(omptest
)

# Target: ompTest library
# On (implicit) request of GoogleTest, link against the one provided with LLVM.
# On (implicit) request of GoogleTest, embed the sources 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)
Expand All @@ -65,34 +73,39 @@ if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
set(LIBOMPTEST_BUILD_STANDALONE OFF)
endif()

# Add dependency llvm_gtest; emits error if unavailable.
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)

# Add GoogleTest-based header
target_sources(omptest PRIVATE ./include/OmptTesterGoogleTest.h)
message(STATUS "omptest build mode: GTest-based")

# Add LLVM-provided GoogleTest include directories.
target_include_directories(omptest PRIVATE
${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include)

# TODO: Re-visit ABI breaking checks, disable for now.
target_compile_definitions(omptest PUBLIC
-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING)

# Link against gtest and gtest_main
target_link_libraries(omptest PRIVATE ${GTEST_LINK_CMD})
# Add GoogleTest-based header and embed GTest symbols into the shared lib.
# Merging of GTest is desired, such that omptest is self-contained and
# independent of external GTest installations.
target_sources(omptest PRIVATE
$<TARGET_OBJECTS:default_gtest>
)

# Link against the default GTest which at this point primarily pulls in the
# include directories and compile definitions. It is important to make these
# available to dependant targets, e.g. for unit tests.
target_link_libraries(omptest PUBLIC default_gtest)

# Link against Threads (recommended for GTest).
find_package(Threads REQUIRED)
target_link_libraries(omptest PUBLIC Threads::Threads)

# Ensure that embedded GTest symbols are exported from libomptest.so even in
# builds that default to hidden.
set_target_properties(omptest PROPERTIES
CXX_VISIBILITY_PRESET default
VISIBILITY_INLINES_HIDDEN OFF
)
else()
message(STATUS "omptest build mode: standalone")

# Add 'standalone' compile definitions
target_compile_definitions(omptest PRIVATE
-DOPENMP_LIBOMPTEST_BUILD_STANDALONE)

# Add 'standalone' source files
target_sources(omptest PRIVATE
./include/OmptTesterStandalone.h
./src/OmptTesterStandalone.cpp)
endif()

Expand Down Expand Up @@ -138,7 +151,7 @@ if(LIBOMPTEST_INSTALL_COMPONENTS)

# Install library and export targets.
# Note: find_package(omptest) may require setting of PATH_SUFFIXES
# Example: "lib/cmake/openmp/omptest", this is due to the install location
# Example: "lib/cmake/openmp/omptest", due to the install location
install(TARGETS omptest
EXPORT OPENMPomptest
LIBRARY COMPONENT omptest
Expand Down
7 changes: 2 additions & 5 deletions openmp/tools/omptest/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ set(UNITTEST_SOURCES
)
add_executable(omptest-unittests ${UNITTEST_SOURCES})

# Add local and LLVM-provided GoogleTest include directories.
target_include_directories(omptest-unittests PRIVATE
../include
${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include)

# Add local include directory and link omptest library
target_include_directories(omptest-unittests PRIVATE ../include)
target_link_libraries(omptest-unittests PRIVATE omptest)

set_target_properties(omptest-unittests PROPERTIES
Expand Down
Loading