8000 Fix benchmark/CMakeLists.txt · robertodr/xtensor-python@fe0841a · GitHub
[go: up one dir, main page]

Skip to content

Commit fe0841a

Browse files
committed
Fix benchmark/CMakeLists.txt
1 parent 1c5e4f1 commit fe0841a

File tree

2 files changed

+58
-29
lines changed

2 files changed

+58
-29
lines changed

benchmark/CMakeLists.txt

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,82 @@
99
message(STATUS "Forcing tests build type to Release")
1010
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
1111

12-
include(CheckCXXCompilerFlag)
13-
1412
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
1513

16-
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
17-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wunused-parameter -Wextra -Wreorder -Wconversion")
18-
CHECK_CXX_COMPILER_FLAG("-std=c++14" HAS_CPP14_FLAG)
14+
include(${CMAKE_CURRENT_LIST_DIR}/test/set_compiler_flag.cmake)
15+
if(CPP17)
16+
# User requested C++17, but compiler might not oblige.
17+
set_compiler_flag(
18+
_cxx_std_flag CXX
19+
"-std=c++17" # this should work with GNU, Intel, PGI
20+
"/std:c++17" # this should work with MSVC
21+
)
22+
if(_cxx_std_flag)
23+
message(STATUS "Building with C++17")
24+
endif()
25+
else()
26+
set_compiler_flag(
27+
_cxx_std_flag CXX REQUIRED
28+
"-std=c++14" # this should work with GNU, Intel, PGI
29+
"/std:c++14" # this should work with MSVC
30+
)
31+
message(STATUS "Building with C++14")
32+
endif()
1933

20-
if (HAS_CPP14_FLAG)
21-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
22-
else()
23-
message(FATAL_ERROR "Unsupported compiler -- xtensor requires C++14 support!")
24-
endif()
34+
if(NOT _cxx_std_flag)
35+
message(FATAL_ERROR "xtensor-python needs a C++14-compliant compiler.")
36+
endif()
37+
38+
# Check for Link Time Optimization support
39+
set_compiler_flag(
40+
_lto_flag CXX
41+
"-flto" # this works with GNU and Clang
42+
"-ipo" # this works with Intel
43+
)
44+
45+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT WIN32))
46+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} -march=native -Wunused-parameter -Wextra -Wreorder -Wconversion")
2547

2648
# Enable link time optimization and set the default symbol
2749
# visibility to hidden (very important to obtain small binaries)
28-
if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
50+
if(NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
2951
# Default symbol visibility
3052
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
31-
3253
# Check for Link Time Optimization support
33-
# (GCC/Clang)
34-
CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG)
35-
if (HAS_LTO_FLAG)
36-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
37-
endif()
38-
39-
# Intel equivalent to LTO is called IPO
40-
if (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
41-
CHECK_CXX_COMPILER_FLAG("-ipo" HAS_IPO_FLAG)
42-
if (HAS_IPO_FLAG)
43-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
44-
endif()
54+
if(_lto_flag)
55+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_lto_flag}")
4556
endif()
4657
endif()
47-
endif()
48-
49-
if(MSVC)
58+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
5059
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /bigobj")
5160
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
5261
foreach(flag_var
5362
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
5463
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
5564
string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}")
5665
endforeach()
66+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
67+
if(NOT WIN32)
68+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} -march=native -Wunused-parameter -Wextra -Wreorder -Wconversion")
69+
if(NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
70+
# Default symbol visibility
71+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
72+
# Check for Link Time Optimization support
73+
if(_lto_flag)
74+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_lto_flag}")
75+
endif()
76+
endif()
77+
else() # We are using clang-cl
78+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} /EHsc /MP /bigobj")
79+
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
80+
foreach(flag_var
81+
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
82+
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
83+
string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}")
84+
endforeach()
85+
endif()
86+
else()
87+
message(FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}")
5788
endif()
5889

5990
set(XTENSOR_PYTHON_BENCHMARK

test/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file 57A7 line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ endif ()
2121
message(STATUS "Forcing tests build type to Release")
2222
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
2323

24-
include(CheckCXXCompilerFlag)
25-
2624
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
2725

2826
include(set_compiler_flag.cmake)

0 commit comments

Comments
 (0)
0