Skip to content

Commit b8f0c61

Browse files
committed
Improved c++14/17 integration, follows more closely modern cmake
1 parent e3b3619 commit b8f0c61

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
@@ -67,6 +67,7 @@ target_include_directories(xtensor-blas
6767
$<INSTALL_INTERFACE:include>)
6868

6969
OPTION(CXXBLAS_DEBUG "print cxxblas debug information" OFF)
70+
OPTION(CPP17 "enables C++17" OFF)
7071
OPTION(XTENSOR_USE_FLENS_BLAS "use FLENS generic implementation instead of cblas" OFF)
7172
# Decide whether to use OpenBLAS or not.
7273
# 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
@@ -25,34 +25,6 @@ else()
2525
message(STATUS "Tests build type is ${CMAKE_BUILD_TYPE}")
2626
endif()
2727

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

5729
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT WIN32))
5830
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} -march=native -Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion")
@@ -146,5 +118,10 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
146118
endif()
147119

148120
target_link_libraries(test_xtensor_blas ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
121+
if(CPP17)
122+
target_compile_features(test_xtensor_blas PUBLIC cxx_std_17)
123+
else()
124+
target_compile_features(test_xtensor_blas PUBLIC cxx_std_14)
125+
endif()
149126

150127
add_custom_target(xtest COMMAND test_xtensor_blas DEPENDS test_xtensor_blas)

0 commit comments

Comments
 (0)