Skip to content

Commit 8afdee5

Browse files
authored
Minor CMake change to better integrate c++17 and modernize GTest-integration (#174)
test/CMakeLists.txt: Modernized GTest-integration
1 parent e3b3619 commit 8afdee5

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

.appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ install:
2020
- conda config --set always_yes yes --set changeps1 no
2121
- conda update -q conda
2222
- conda info -a
23-
- conda install gtest cmake -c conda-forge
23+
- conda install cmake -c conda-forge
2424
- conda install xtensor=0.21.4 -c conda-forge
2525
- conda install m2w64-openblas -c msys2
2626
# Patch OpenBLASConfig.cmake
2727
- ps: (Get-Content $Env:MINICONDA\Library\mingw-w64\lib\cmake\openblas\OpenBLASConfig.cmake).replace('mingw64', 'mingw-w64') | Set-Content $Env:MINICONDA\Library\mingw-w64\lib\cmake\openblas\OpenBLASConfig.cmake
2828
- ps: (Get-Content $Env:MINICONDA\Library\mingw-w64\lib\cmake\openblas\OpenBLASConfig.cmake).replace('mingw32', 'mingw-w64') | Set-Content $Env:MINICONDA\Library\mingw-w64\lib\cmake\openblas\OpenBLASConfig.cmake
2929
- ps: (Get-Content $Env:MINICONDA\Library\mingw-w64\lib\cmake\openblas\OpenBLASConfig.cmake).replace('bin', 'lib') | Set-Content $Env:MINICONDA\Library\mingw-w64\lib\cmake\openblas\OpenBLASConfig.cmake
3030
- ps: (Get-Content $Env:MINICONDA\Library\mingw-w64\lib\cmake\openblas\OpenBLASConfig.cmake).replace('dll', 'dll.a') | Set-Content $Env:MINICONDA\Library\mingw-w64\lib\cmake\openblas\OpenBLASConfig.cmake
31-
- cmake -G "NMake Makefiles" -DOpenBLAS_DIR=%MINICONDA%\Library\mingw-w64\lib\cmake\openblas -DCMAKE_INSTALL_PREFIX=%MINICONDA%\Library -DBUILD_TESTS=ON .
31+
- cmake -G "NMake Makefiles" -DOpenBLAS_DIR=%MINICONDA%\Library\mingw-w64\lib\cmake\openblas -DCMAKE_INSTALL_PREFIX=%MINICONDA%\Library -DBUILD_TESTS=ON -DDOWNLOAD_GTEST=ON .
3232
- nmake test_xtensor_blas
3333
- cd test
3434

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)

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ jobs:
3939
# Note: conda activate doesn't work here, because it creates a new shell!
4040
- script: |
4141
conda install cmake==3.14.0 ^
42-
gtest==1.10.0 ^
4342
mkl-devel ^
4443
ninja ^
4544
xtensor=0.21.4 ^
@@ -66,6 +65,7 @@ jobs:
6665
-DCMAKE_C_COMPILER=clang-cl ^
6766
-DCMAKE_CXX_COMPILER=clang-cl ^
6867
-DBUILD_TESTS=ON ^
68+
-DDOWNLOAD_GTEST=ON ^
6969
$(Build.SourcesDirectory)
7070
displayName: "Configure xtensor-blas"
7171
workingDirectory: $(Build.BinariesDirectory)

test/CMakeLists.txt

Lines changed: 11 additions & 3 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)
@@ -67,7 +69,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
6769
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} -march=native -Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion")
6870
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast -Wunused-variable")
6971
else() # We are using clang-cl
70-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} /EHsc /MP /bigobj")
72+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} /EHsc /MP /bigobj -Wno-unused-command-line-argument")
7173
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
7274
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
7375
add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
@@ -97,13 +99,18 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
9799
message(FATAL_ERROR "Build step for googletest failed: ${result}")
98100
endif()
99101

102+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
103+
100104
# Add googletest directly to our build. This defines
101105
# the gtest and gtest_main targets.
102106
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
103107
${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL)
104108

105109
set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include")
106-
set(GTEST_BOTH_LIBRARIES gtest_main gtest)
110+
add_library(GTest::GTest INTERFACE IMPORTED)
111+
target_link_libraries(GTest::GTest INTERFACE gtest)
112+
add_library(GTest::Main INTERFACE IMPORTED)
113+
target_link_libraries(GTest::Main INTERFACE gtest_main)
107114
else()
108115
find_package(GTest REQUIRED)
109116
endif()
@@ -145,6 +152,7 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
145152
add_dependencies(test_xtensor_blas gtest_main)
146153
endif()
147154

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

150157
add_custom_target(xtest COMMAND test_xtensor_blas DEPENDS test_xtensor_blas)
158+
add_test(NAME xtest COMMAND test_xtensor_blas)

0 commit comments

Comments
 (0)