Skip to content

Commit e82a80e

Browse files
committed
test/CMakeLists.txt: Modernized GTest-integration
1 parent b8f0c61 commit e82a80e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
9999
endif()
100100

101101
if(BUILD_TESTS)
102+
enable_testing()
102103
include_directories(${XTENSOR_BLAS_INCLUDE_DIR})
103104
include_directories(${xtensor_INCLUDE_DIRS})
104105
add_subdirectory(test)

test/CMakeLists.txt

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ cmake_minimum_required(VERSION 3.1)
1212
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
1313
project(xtensor-blas-test)
1414

15+
enable_testing()
16+
1517
find_package(xtensor REQUIRED CONFIG)
1618
set(XTENSOR_INCLUDE_DIR ${xtensor_INCLUDE_DIRS})
1719
find_package(xtensor-blas REQUIRED CONFIG)
@@ -75,7 +77,10 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
7577
${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL)
7678

7779
set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include")
78-
set(GTEST_BOTH_LIBRARIES gtest_main gtest)
80+
add_library(GTest::gtest INTERFACE IMPORTED)
81+
target_link_libraries(GTest::gtest INTERFACE gtest)
82+
add_library(GTest::gtest_main INTERFACE IMPORTED)
83+
target_link_libraries(GTest::gtest_main INTERFACE gtest_main)
7984
else()
8085
find_package(GTest REQUIRED)
8186
endif()
@@ -117,11 +122,12 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
117122
add_dependencies(test_xtensor_blas gtest_main)
118123
endif()
119124

120-
target_link_libraries(test_xtensor_blas ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
125+
target_link_libraries(test_xtensor_blas ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} GTest::gtest GTest::gtest_main ${CMAKE_THREAD_LIBS_INIT})
121126
if(CPP17)
122127
target_compile_features(test_xtensor_blas PUBLIC cxx_std_17)
123128
else()
124129
target_compile_features(test_xtensor_blas PUBLIC cxx_std_14)
125130
endif()
126131

127132
add_custom_target(xtest COMMAND test_xtensor_blas DEPENDS test_xtensor_blas)
133+
add_test(NAME xtest COMMAND test_xtensor_blas)

0 commit comments

Comments
 (0)