Skip to content

Commit 9175d7e

Browse files
committed
Improved c++14/17 integration, follows more closely modern cmake
1 parent 7ceb791 commit 9175d7e

File tree

3 files changed

+12
-35
lines changed

3 files changed

+12
-35
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ target_include_directories(xtensor-blas
7878
$<INSTALL_INTERFACE:include>)
7979

8080
OPTION(CXXBLAS_DEBUG "print cxxblas debug information" OFF)
81+
OPTION(CPP17 "enables C++17" OFF)
8182
OPTION(XTENSOR_USE_FLENS_BLAS "use FLENS generic implementation instead of cblas" OFF)
8283
# Decide whether to use OpenBLAS or not.
8384
# The user might have the folder containing OpenBLASConfig.cmake file

benchmark/CMakeLists.txt

+6-7
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
2424

2525
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
2626
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wunused-parameter -Wextra -Wreorder")
27-
CHECK_CXX_COMPILER_FLAG("-std=c++14" HAS_CPP14_FLAG)
28-
29-
if (HAS_CPP14_FLAG)
30-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
31-
else()
32-
message(FATAL_ERROR "Unsupported compiler -- xtensor requires C++14 support!")
33-
endif()
3427

3528
# Enable link time optimization and set the default symbol
3629
# visibility to hidden (very important to obtain small binaries)
@@ -124,6 +117,12 @@ set(XTENSOR_BENCHMARK
124117
set(XTENSOR_BENCHMARK_TARGET benchmark_xtensor)
125118
add_executable(${XTENSOR_BENCHMARK_TARGET} EXCLUDE_FROM_ALL ${XTENSOR_BENCHMARK} ${XTENSOR_HEADERS})
126119
target_link_libraries(${XTENSOR_BENCHMARK_TARGET} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GBENCHMARK_LIBRARIES})
120+
if(CPP17)
121+
target_compile_features(${XTENSOR_BENCHMARK_TARGET} PUBLIC cxx_std_17)
122+
else()
123+
target_compile_features(${XTENSOR_BENCHMARK_TARGET} PUBLIC cxx_std_14)
124+
endif()
125+
127126

128127
add_custom_target(xbenchmark
129128
COMMAND benchmark_xtensor

test/CMakeLists.txt

+5-28
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,6 @@ else()
2727
message(STATUS "Tests build type is ${CMAKE_BUILD_TYPE}")
2828
endif()
2929

30-
include(CheckCXXCompilerFlag)
31-
32-
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
33-
34-
include(set_compiler_flag.cmake)
35-
36-
if(CPP17)
37-
# User requested C++17, but compiler might not oblige.
38-
set_compiler_flag(
39-
_cxx_std_flag CXX
40-
"-std=c++17" # this should work with GNU, Intel, PGI
41-
"/std:c++17" # this should work with MSVC
42-
)
43-
if(_cxx_std_flag)
44-
message(STATUS "Building with C++17")
45-
endif()
46-
else()
47-
set_compiler_flag(
48-
_cxx_std_flag CXX REQUIRED
49-
"-std=c++14" # this should work with GNU, Intel, PGI
50-
"/std:c++14" # this should work with MSVC
51-
)
52-
message(STATUS "Building with C++14")
53-
endif()
54-
55-
if(NOT _cxx_std_flag)
56-
message(FATAL_ERROR "xtensor-blas needs a C++14-compliant compiler.")
57-
endif()
5830

5931
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT WIN32))
6032
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} -march=native -Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion")
@@ -153,6 +125,11 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
153125
endif()
154126

155127
target_link_libraries(test_xtensor_blas ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} GTest::GTest GTest::Main ${CMAKE_THREAD_LIBS_INIT})
128+
if(CPP17)
129+
target_compile_features(test_xtensor_blas PUBLIC cxx_std_17)
130+
else()
131+
target_compile_features(test_xtensor_blas PUBLIC cxx_std_14)
132+
endif()
156133

157134
add_custom_target(xtest COMMAND test_xtensor_blas DEPENDS test_xtensor_blas)
158135
add_test(NAME xtest COMMAND test_xtensor_blas)

0 commit comments

Comments
 (0)