|
| 1 | +##===----------------------------------------------------------------------===## |
| 2 | +# |
| 3 | +# Build OMPT unit testing library: ompTest |
| 4 | +# |
| 5 | +##===----------------------------------------------------------------------===## |
| 6 | + |
| 7 | +cmake_minimum_required(VERSION 3.22) |
| 8 | +project(omptest LANGUAGES CXX) |
| 9 | + |
| 10 | +option(LIBOMPTEST_BUILD_STANDALONE |
| 11 | + "Build ompTest 'standalone', i.e. w/o GoogleTest." OFF) |
| 12 | +option(LIBOMPTEST_BUILD_UNITTESTS |
| 13 | + "Build ompTest's unit tests , requires GoogleTest." OFF) |
| 14 | + |
| 15 | +# In absence of corresponding OMPT support: exit early |
| 16 | +if(NOT ${LIBOMPTARGET_OMPT_SUPPORT}) |
| 17 | + return() |
| 18 | +endif() |
| 19 | + |
| 20 | +set(OMPTEST_HEADERS |
| 21 | + ./include/AssertMacros.h |
| 22 | + ./include/InternalEvent.h |
| 23 | + ./include/InternalEventCommon.h |
| 24 | + ./include/Logging.h |
| 25 | + ./include/OmptAliases.h |
| 26 | + ./include/OmptAsserter.h |
| 27 | + ./include/OmptAssertEvent.h |
| 28 | + ./include/OmptCallbackHandler.h |
| 29 | + ./include/OmptTester.h |
| 30 | + ./include/OmptTesterGlobals.h |
| 31 | +) |
| 32 | + |
| 33 | +add_library(omptest |
| 34 | + SHARED |
| 35 | + |
| 36 | + ${OMPTEST_HEADERS} |
| 37 | + ./src/InternalEvent.cpp |
| 38 | + ./src/InternalEventOperators.cpp |
| 39 | + ./src/Logging.cpp |
| 40 | + ./src/OmptAsserter.cpp |
| 41 | + ./src/OmptAssertEvent.cpp |
| 42 | + ./src/OmptCallbackHandler.cpp |
| 43 | + ./src/OmptTester.cpp |
| 44 | +) |
| 45 | + |
| 46 | +# Target: ompTest library |
| 47 | +# On (implicit) request of GoogleTest, link against the one provided with LLVM. |
| 48 | +if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS) |
| 49 | + # Check if standalone build was requested together with unittests |
| 50 | + if (LIBOMPTEST_BUILD_STANDALONE) |
| 51 | + # Emit warning: this build actually depends on LLVM's GoogleTest |
| 52 | + message(WARNING "LIBOMPTEST_BUILD_STANDALONE and LIBOMPTEST_BUILD_UNITTESTS" |
| 53 | + " requested simultaneously.\n" |
| 54 | + "Linking against LLVM's GoogleTest library archives.\n" |
| 55 | + "Disable LIBOMPTEST_BUILD_UNITTESTS to perform an actual" |
| 56 | + " standalone build.") |
| 57 | + # Explicitly disable LIBOMPTEST_BUILD_STANDALONE |
| 58 | + set(LIBOMPTEST_BUILD_STANDALONE OFF) |
| 59 | + endif() |
| 60 | + |
| 61 | + # Use LLVM's gtest library archive |
| 62 | + set(GTEST_LIB "${LLVM_BINARY_DIR}/lib/libllvm_gtest.a") |
| 63 | + # Link gtest as whole-archive to expose required symbols |
| 64 | + set(GTEST_LINK_CMD "-Wl,--whole-archive" ${GTEST_LIB} |
| 65 | + "-Wl,--no-whole-archive" LLVMSupport) |
| 66 | + |
| 67 | + # Add GoogleTest-based header |
| 68 | + target_sources(omptest PRIVATE ./include/OmptTesterGoogleTest.h) |
| 69 | + |
| 70 | + # Add LLVM-provided GoogleTest include directories. |
| 71 | + target_include_directories(omptest PRIVATE |
| 72 | + ${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include) |
| 73 | + |
| 74 | + # TODO: Re-visit ABI breaking checks, disable for now. |
| 75 | + target_compile_definitions(omptest PUBLIC |
| 76 | + -DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING) |
| 77 | + |
| 78 | + # Link against gtest and gtest_main |
| 79 | + target_link_libraries(omptest PRIVATE ${GTEST_LINK_CMD}) |
| 80 | +else() |
| 81 | + # Add 'standalone' compile definitions |
| 82 | + target_compile_definitions(omptest PRIVATE |
| 83 | + -DOPENMP_LIBOMPTEST_BUILD_STANDALONE) |
| 84 | + |
| 85 | + # Add 'standalone' source files |
| 86 | + target_sources(omptest PRIVATE |
| 87 | + ./include/OmptTesterStandalone.h |
| 88 | + ./src/OmptTesterStandalone.cpp) |
| 89 | +endif() |
| 90 | + |
| 91 | +# Add common include directories. |
| 92 | +target_include_directories(omptest PRIVATE |
| 93 | + ./include |
| 94 | + ${LIBOMPTARGET_INCLUDE_DIR}) |
| 95 | +target_compile_features(omptest PRIVATE cxx_std_17) |
| 96 | + |
| 97 | +# Create and install package configuration files. |
| 98 | +configure_file( |
| 99 | + ${omptest_SOURCE_DIR}/cmake/omptest-config.cmake.in |
| 100 | + ${omptest_BINARY_DIR}/cmake/omptest-config.cmake @ONLY) |
| 101 | + |
| 102 | +install(FILES ${omptest_BINARY_DIR}/cmake/omptest-config.cmake |
| 103 | + DESTINATION "${OPENMP_INSTALL_LIBDIR}/cmake/openmp/omptest") |
| 104 | + |
| 105 | +# Install libomptest header files: Copy header-files from include dir |
| 106 | +install(DIRECTORY ./include |
| 107 | + DESTINATION "${LIBOMP_HEADERS_INSTALL_PATH}/omptest" |
| 108 | + FILES_MATCHING PATTERN "*.h") |
| 109 | + |
| 110 | +install(TARGETS omptest LIBRARY COMPONENT omptest |
| 111 | + DESTINATION "${OPENMP_INSTALL_LIBDIR}") |
| 112 | + |
| 113 | +# Discover unit tests (added to check-openmp) |
| 114 | +if(LIBOMPTEST_BUILD_UNITTESTS) |
| 115 | + add_subdirectory(test) |
| 116 | +endif() |
0 commit comments