Skip to content

Minor CMake change to better integrate c++17 and modernize GTest-integration #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ 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
- 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
- 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

Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ^
Expand All @@ -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)
Expand Down
14 changes: 11 additions & 3 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 @@ -67,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)
Expand Down Expand Up @@ -97,13 +99,18 @@ 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
${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 @@ -145,6 +152,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)