Skip to content

Commit ec7e1d7

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

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
9898
endif()
9999

100100
if(BUILD_TESTS)
101+
enable_testing()
101102
include_directories(${XTENSOR_BLAS_INCLUDE_DIR})
102103
include_directories(${xtensor_INCLUDE_DIRS})
103104
add_subdirectory(test)

test/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
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)
@@ -103,7 +105,10 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
103105
${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL)
104106

105107
set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include")
106-
set(GTEST_BOTH_LIBRARIES gtest_main gtest)
108+
add_library(GTest::GTest INTERFACE IMPORTED)
109+
target_link_libraries(GTest::GTest INTERFACE gtest)
110+
add_library(GTest::Main INTERFACE IMPORTED)
111+
target_link_libraries(GTest::Main INTERFACE gtest_main)
107112
else()
108113
find_package(GTest REQUIRED)
109114
endif()
@@ -145,6 +150,7 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
145150
add_dependencies(test_xtensor_blas gtest_main)
146151
endif()
147152

148-
target_link_libraries(test_xtensor_blas ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
153+
target_link_libraries(test_xtensor_blas ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} GTest::GTest GTest::Main ${CMAKE_THREAD_LIBS_INIT})
149154

150155
add_custom_target(xtest COMMAND test_xtensor_blas DEPENDS test_xtensor_blas)
156+
add_test(NAME xtest COMMAND test_xtensor_blas)

0 commit comments

Comments
 (0)