Skip to content

Commit

Permalink
test/CMakeLists.txt: Modernized GTest-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
emmenlau committed Oct 21, 2020
1 parent b8f0c61 commit 22d822a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
endif()

if(BUILD_TESTS)
enable_testing()
include_directories(${XTENSOR_BLAS_INCLUDE_DIR})
include_directories(${xtensor_INCLUDE_DIRS})
add_subdirectory(test)
Expand Down
10 changes: 8 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ cmake_minimum_required(VERSION 3.1)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
project(xtensor-blas-test)

enable_testing()

find_package(xtensor REQUIRED CONFIG)
set(XTENSOR_INCLUDE_DIR ${xtensor_INCLUDE_DIRS})
find_package(xtensor-blas REQUIRED CONFIG)
Expand Down Expand Up @@ -75,7 +77,10 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL)

set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include")
set(GTEST_BOTH_LIBRARIES gtest_main gtest)
add_library(GTest::GTest INTERFACE IMPORTED)
target_link_libraries(GTest::GTest INTERFACE gtest)
add_library(GTest::Main INTERFACE IMPORTED)
target_link_libraries(GTest::Main INTERFACE gtest_main)
else()
find_package(GTest REQUIRED)
endif()
Expand Down Expand Up @@ -117,11 +122,12 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
add_dependencies(test_xtensor_blas gtest_main)
endif()

target_link_libraries(test_xtensor_blas ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(test_xtensor_blas ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} GTest::GTest GTest::Main ${CMAKE_THREAD_LIBS_INIT})
if(CPP17)
target_compile_features(test_xtensor_blas PUBLIC cxx_std_17)
else()
target_compile_features(test_xtensor_blas PUBLIC cxx_std_14)
endif()

add_custom_target(xtest COMMAND test_xtensor_blas DEPENDS test_xtensor_blas)
add_test(NAME xtest COMMAND test_xtensor_blas)

0 comments on commit 22d822a

Please sign in to comment.