brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.3 KiB · b313f22 Raw
160 lines · plain
1##===----------------------------------------------------------------------===##2#3# Build OMPT unit testing library: ompTest4#5##===----------------------------------------------------------------------===##6 7cmake_minimum_required(VERSION 3.20)8project(omptest LANGUAGES CXX)9 10option(LIBOMPTEST_BUILD_STANDALONE11       "Build ompTest 'standalone', i.e. w/o GoogleTest."12       ${OPENMP_STANDALONE_BUILD})13option(LIBOMPTEST_BUILD_UNITTESTS14       "Build ompTest's unit tests, requires GoogleTest." OFF)15option(LIBOMPTEST_INSTALL_COMPONENTS16       "Install ompTest library, headers and package files." OFF)17 18# Exit early if OMPT support or LLVM-tests were disabled by the user.19if((NOT ${LIBOMP_OMPT_SUPPORT}) OR (NOT ${LLVM_INCLUDE_TESTS}))20  return()21endif()22 23include(CMakePackageConfigHelpers)24 25include_directories(${LIBOMP_INCLUDE_DIR})26 27set(OMPTEST_HEADERS28  ./include/AssertMacros.h29  ./include/InternalEvent.h30  ./include/InternalEventCommon.h31  ./include/Logging.h32  ./include/OmptAliases.h33  ./include/OmptAsserter.h34  ./include/OmptAssertEvent.h35  ./include/OmptCallbackHandler.h36  ./include/OmptTester.h37  ./include/OmptTesterGlobals.h38)39 40add_library(omptest41  SHARED42 43  ${OMPTEST_HEADERS}44  ./src/InternalEvent.cpp45  ./src/InternalEventOperators.cpp46  ./src/Logging.cpp47  ./src/OmptAsserter.cpp48  ./src/OmptAssertEvent.cpp49  ./src/OmptCallbackHandler.cpp50  ./src/OmptTester.cpp51)52 53# Target: ompTest library54# On (implicit) request of GoogleTest, link against the one provided with LLVM.55if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)56  # Check if standalone build was requested together with unittests57  if (LIBOMPTEST_BUILD_STANDALONE)58    # Emit warning: this build actually depends on LLVM's GoogleTest59    message(WARNING "LIBOMPTEST_BUILD_STANDALONE and LIBOMPTEST_BUILD_UNITTESTS"60                    " requested simultaneously.\n"61                    "Linking against LLVM's GoogleTest library archives.\n"62                    "Disable LIBOMPTEST_BUILD_UNITTESTS to perform an actual"63                    " standalone build.")64    # Explicitly disable LIBOMPTEST_BUILD_STANDALONE65    set(LIBOMPTEST_BUILD_STANDALONE OFF)66  endif()67 68  # Add dependency llvm_gtest; emits error if unavailable.69  add_dependencies(omptest llvm_gtest)70 71  # Link llvm_gtest as whole-archive to expose required symbols72  set(GTEST_LINK_CMD "-Wl,--whole-archive" llvm_gtest73                     "-Wl,--no-whole-archive" LLVMSupport)74 75  # Add GoogleTest-based header76  target_sources(omptest PRIVATE ./include/OmptTesterGoogleTest.h)77 78  # Add LLVM-provided GoogleTest include directories.79  target_include_directories(omptest PRIVATE80    ${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include)81 82  # TODO: Re-visit ABI breaking checks, disable for now.83  target_compile_definitions(omptest PUBLIC84    -DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING)85 86  # Link against gtest and gtest_main87  target_link_libraries(omptest PRIVATE ${GTEST_LINK_CMD})88else()89  # Add 'standalone' compile definitions90  target_compile_definitions(omptest PRIVATE91    -DOPENMP_LIBOMPTEST_BUILD_STANDALONE)92 93  # Add 'standalone' source files94  target_sources(omptest PRIVATE95    ./include/OmptTesterStandalone.h96    ./src/OmptTesterStandalone.cpp)97endif()98 99if(TARGET cxx-headers)100  add_dependencies(omptest cxx-headers)101endif()102 103if(TARGET cxx_shared)104  add_dependencies(omptest cxx_shared)105endif()106 107if(TARGET cxxabi_shared)108  add_dependencies(omptest cxxabi_shared)109endif()110 111# Add common include directories.112target_include_directories(omptest PUBLIC113  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>114  $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${LIBOMP_HEADERS_INSTALL_PATH}/omptest>115)116 117target_compile_features(omptest PRIVATE cxx_std_17)118 119# Perform package configuration.120set(OMPTEST_CONFIG_INSTALL_DIR "${OPENMP_INSTALL_LIBDIR}/cmake/openmp/omptest")121configure_package_config_file(122  ${CMAKE_CURRENT_SOURCE_DIR}/cmake/omptest-config.cmake.in123  ${CMAKE_CURRENT_BINARY_DIR}/cmake/omptest-config.cmake124  INSTALL_DESTINATION "${OMPTEST_CONFIG_INSTALL_DIR}"125)126 127# Perform installation only if requested by the user.128if(LIBOMPTEST_INSTALL_COMPONENTS)129  # Install package configuration files.130  install(FILES ${omptest_BINARY_DIR}/cmake/omptest-config.cmake131          DESTINATION "${OMPTEST_CONFIG_INSTALL_DIR}")132 133  # Install libomptest header files: Copy header-files from include dir134  set(OMPTEST_HEADER_INSTALL_DIR "${LIBOMP_HEADERS_INSTALL_PATH}/omptest")135  install(DIRECTORY ./include/136          DESTINATION "${OMPTEST_HEADER_INSTALL_DIR}"137          FILES_MATCHING PATTERN "*.h")138 139  # Install library and export targets.140  # Note: find_package(omptest) may require setting of PATH_SUFFIXES141  #       Example: "lib/cmake/openmp/omptest", this is due to the install location142  install(TARGETS omptest143          EXPORT OPENMPomptest144          LIBRARY COMPONENT omptest145          DESTINATION "${OPENMP_INSTALL_LIBDIR}"146          INCLUDES DESTINATION "${OMPTEST_HEADER_INSTALL_DIR}")147 148  # Allow to link omptest by using: target_link_libraries( ... omptest::omptest)149  # Additionally, it automatically propagates the include directory.150  install(EXPORT OPENMPomptest151          DESTINATION "${OMPTEST_CONFIG_INSTALL_DIR}"152          NAMESPACE omptest::153          FILE omptest-targets.cmake)154endif()155 156# Discover unit tests (added to check-openmp)157if(LIBOMPTEST_BUILD_UNITTESTS)158  add_subdirectory(test)159endif()160