Skip to content

Improved c++14/17 integration, follows more closely modern cmake #175

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ target_include_directories(xtensor-blas
$<INSTALL_INTERFACE:include>)

OPTION(CXXBLAS_DEBUG "print cxxblas debug information" OFF)
OPTION(CPP17 "enables C++17" OFF)
OPTION(XTENSOR_USE_FLENS_BLAS "use FLENS generic implementation instead of cblas" OFF)
# Decide whether to use OpenBLAS or not.
# The user might have the folder containing OpenBLASConfig.cmake file
Expand Down
13 changes: 6 additions & 7 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wunused-parameter -Wextra -Wreorder")
CHECK_CXX_COMPILER_FLAG("-std=c++14" HAS_CPP14_FLAG)

if (HAS_CPP14_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
message(FATAL_ERROR "Unsupported compiler -- xtensor requires C++14 support!")
endif()

# Enable link time optimization and set the default symbol
# visibility to hidden (very important to obtain small binaries)
Expand Down Expand Up @@ -124,6 +117,12 @@ set(XTENSOR_BENCHMARK
set(XTENSOR_BENCHMARK_TARGET benchmark_xtensor)
add_executable(${XTENSOR_BENCHMARK_TARGET} EXCLUDE_FROM_ALL ${XTENSOR_BENCHMARK} ${XTENSOR_HEADERS})
target_link_libraries(${XTENSOR_BENCHMARK_TARGET} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GBENCHMARK_LIBRARIES})
if(CPP17)
target_compile_features(${XTENSOR_BENCHMARK_TARGET} PUBLIC cxx_std_17)
else()
target_compile_features(${XTENSOR_BENCHMARK_TARGET} PUBLIC cxx_std_14)
endif()


add_custom_target(xbenchmark
COMMAND benchmark_xtensor
Expand Down
33 changes: 5 additions & 28 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,6 @@ else()
message(STATUS "Tests build type is ${CMAKE_BUILD_TYPE}")
endif()

include(CheckCXXCompilerFlag)

string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)

include(set_compiler_flag.cmake)

if(CPP17)
# User requested C++17, but compiler might not oblige.
set_compiler_flag(
_cxx_std_flag CXX
"-std=c++17" # this should work with GNU, Intel, PGI
"/std:c++17" # this should work with MSVC
)
if(_cxx_std_flag)
message(STATUS "Building with C++17")
endif()
else()
set_compiler_flag(
_cxx_std_flag CXX REQUIRED
"-std=c++14" # this should work with GNU, Intel, PGI
"/std:c++14" # this should work with MSVC
)
message(STATUS "Building with C++14")
endif()

if(NOT _cxx_std_flag)
message(FATAL_ERROR "xtensor-blas needs a C++14-compliant compiler.")
endif()

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

target_link_libraries(test_xtensor_blas ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} GTest::GTest GTest::Main ${CMAKE_THREAD_LIBS_INIT})
if(CPP17)
target_compile_features(test_xtensor_blas PUBLIC cxx_std_17)
else()
target_compile_features(test_xtensor_blas PUBLIC cxx_std_14)
endif()

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