From ec7e1d731081da8cdcfe41c88116e016144315f4 Mon Sep 17 00:00:00 2001 From: Mario Emmenlauer Date: Wed, 21 Oct 2020 14:51:35 +0200 Subject: [PATCH 1/2] test/CMakeLists.txt: Modernized GTest-integration --- CMakeLists.txt | 1 + test/CMakeLists.txt | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b523a4..4d26941 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,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) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bb99cc6..fcca898 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) @@ -103,7 +105,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() @@ -145,6 +150,7 @@ 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}) add_custom_target(xtest COMMAND test_xtensor_blas DEPENDS test_xtensor_blas) +add_test(NAME xtest COMMAND test_xtensor_blas) From 93a0935d4aa5ff06885e722a107921c21c8180fa Mon Sep 17 00:00:00 2001 From: Mario Emmenlauer Date: Wed, 21 Oct 2020 18:18:50 +0200 Subject: [PATCH 2/2] Build gtest from source in CI --- .appveyor.yml | 4 ++-- azure-pipelines.yml | 2 +- test/CMakeLists.txt | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index dc53d80..a8ca53f 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -20,7 +20,7 @@ install: - conda config --set always_yes yes --set changeps1 no - conda update -q conda - conda info -a - - conda install gtest cmake -c conda-forge + - conda install cmake -c conda-forge - conda install xtensor=0.21.4 -c conda-forge - conda install m2w64-openblas -c msys2 # Patch OpenBLASConfig.cmake @@ -28,7 +28,7 @@ install: - 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 - 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 - 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 - - cmake -G "NMake Makefiles" -DOpenBLAS_DIR=%MINICONDA%\Library\mingw-w64\lib\cmake\openblas -DCMAKE_INSTALL_PREFIX=%MINICONDA%\Library -DBUILD_TESTS=ON . + - cmake -G "NMake Makefiles" -DOpenBLAS_DIR=%MINICONDA%\Library\mingw-w64\lib\cmake\openblas -DCMAKE_INSTALL_PREFIX=%MINICONDA%\Library -DBUILD_TESTS=ON -DDOWNLOAD_GTEST=ON . - nmake test_xtensor_blas - cd test diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 56b6ce0..3689c21 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -39,7 +39,6 @@ jobs: # Note: conda activate doesn't work here, because it creates a new shell! - script: | conda install cmake==3.14.0 ^ - gtest==1.10.0 ^ mkl-devel ^ ninja ^ xtensor=0.21.4 ^ @@ -66,6 +65,7 @@ jobs: -DCMAKE_C_COMPILER=clang-cl ^ -DCMAKE_CXX_COMPILER=clang-cl ^ -DBUILD_TESTS=ON ^ + -DDOWNLOAD_GTEST=ON ^ $(Build.SourcesDirectory) displayName: "Configure xtensor-blas" workingDirectory: $(Build.BinariesDirectory) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fcca898..9996424 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -69,7 +69,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} -march=native -Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast -Wunused-variable") else() # We are using clang-cl - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} /EHsc /MP /bigobj") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} /EHsc /MP /bigobj -Wno-unused-command-line-argument") set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO) add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) @@ -99,6 +99,8 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR) message(FATAL_ERROR "Build step for googletest failed: ${result}") endif() + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + # Add googletest directly to our build. This defines # the gtest and gtest_main targets. add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src