forked from higra/Higra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
208 lines (173 loc) · 7.14 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
############################################################################
# Copyright ESIEE Paris (2018) #
# #
# Contributor(s) : Benjamin Perret #
# #
# Distributed under the terms of the CECILL-B License. #
# #
# The full license is in the file LICENSE, distributed with this software. #
############################################################################
cmake_minimum_required(VERSION 2.8.12)
project(higra)
##########################
# VERSION
##########################
file(STRINGS "include/higra/config.hpp" higra_version_defines
REGEX "#define HIGRA_VERSION_(MAJOR|MINOR|PATCH)")
foreach(ver ${higra_version_defines})
if(ver MATCHES "#define HIGRA_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
set(HIGRA_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
endif()
endforeach()
set(${PROJECT_NAME}_VERSION
${HIGRA_VERSION_MAJOR}.${HIGRA_VERSION_MINOR}.${HIGRA_VERSION_PATCH})
message(STATUS "Building higra v${${PROJECT_NAME}_VERSION}")
##########################
# CMAKE config
##########################
#if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.12)
# cmake_policy(SET CMP0074 NEW) # use XXX_ROOT env variable for find_package
#endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/lib/")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${CMAKE_SOURCE_DIR}/lib/")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/tools")
include(higraTools)
##########################
# Build Type and flags
##########################
# new build type coverage
message("* Adding build types...")
SET(CMAKE_CXX_FLAGS_COVERAGE
"${GCC_DEBUG_FLAGS} -fprofile-arcs -ftest-coverage"
CACHE STRING "Flags used by the C++ compiler during coverage builds."
FORCE )
SET(CMAKE_C_FLAGS_COVERAGE
"${GCC_DEBUG_FLAGS} -fprofile-arcs -ftest-coverage"
CACHE STRING "Flags used by the C compiler during coverage builds."
FORCE )
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE
""
CACHE STRING "Flags used for linking binaries during coverage builds."
FORCE )
SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
""
CACHE STRING "Flags used by the shared libraries linker during coverage builds."
FORCE )
MARK_AS_ADVANCED(
CMAKE_CXX_FLAGS_COVERAGE
CMAKE_C_FLAGS_COVERAGE
CMAKE_EXE_LINKER_FLAGS_COVERAGE
CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Coverage." FORCE)
endif()
message("Current build type is: ${CMAKE_BUILD_TYPE}")
include(CheckCXXCompilerFlag)
message("Current compiler is: ${CMAKE_CXX_COMPILER_ID}")
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
find_program(CCACHE_FOUND "ccache")
if(CCACHE_FOUND)
message("Using ccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
endif(CCACHE_FOUND)
set(CMAKE_CXX_STANDARD 14)
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} -Wall -Wno-unused-local-typedefs")# -Wno-unused-but-set-variable -Wno-missing-braces -Wno-mismatched-tags -Wno-unneeded-internal-declaration")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-braces")
endif()
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
if(COMPILER_SUPPORTS_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.")
endif()
# Not debug => optim flag
if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math -fno-finite-math-only -Wno-strict-overflow")#-march=native
# check link time optimization -faligned-new
CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG)
if (HAS_LTO_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
CHECK_CXX_COMPILER_FLAG("-ipo" HAS_IPO_FLAG)
if (HAS_IPO_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo")
endif ()
endif ()
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# using Visual Studio C++
CHECK_CXX_COMPILER_FLAG("/std:c++14" COMPILER_SUPPORTS_CXX14)
if(COMPILER_SUPPORTS_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++14")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.")
endif()
add_definitions("-DNOMINMAX")
if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast /GL /EHsc /MP /bigobj /O2")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTCG /MANIFEST:NO")
endif()
else()
message(FATAL_ERROR "Unknown compiler, please use GCC, Clang or MSVC.")
endif()
##########################
# Options
##########################
find_package(Catch2 REQUIRED)
option(DO_CPP_TEST
"Build c++ test suit." ON)
option(DO_EMBEDDED_PYTHON_CPP_TEST
"Build c++ test with python interpreter embedded suit." OFF)
enable_testing()
option (USE_SIMD
"Enabled SIMD support for xtensor." ON)
if (USE_SIMD)
add_definitions("-DXTENSOR_USE_XSIMD")
endif()
option(DO_BENCHMARK
"Build benchmark suit." OFF)
if (DO_BENCHMARK)
if(${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
message(FATAL_ERROR "Benchmark cannot be built in Debug mode")
endif()
find_package(benchmark REQUIRED)
endif ()
if(NOT ${U_CMAKE_BUILD_TYPE} MATCHES RELEASE)
add_definitions("-DHG_ENABLE_TRACE")
endif()
option(HG_USE_TBB
"Enable Intel TBB support." OFF)
if (HG_USE_TBB)
find_package(TBB REQUIRED)
message(STATUS "Found intel TBB: ${TBB_INCLUDE_DIRS}")
add_definitions("-DTBB_SUPPRESS_DEPRECATED_MESSAGES")
endif ()
option(HG_BUILD_WHEEL
"Should be set to On when building a wheel." OFF)
##########################
# Build Python bindings
##########################
find_package(PythonInterp 3 REQUIRED)
find_package(pybind11 CONFIG REQUIRED)
find_package(NumPy REQUIRED)
add_subdirectory(higra)
configure_file(setup.py ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
configure_file(README.md ${CMAKE_CURRENT_BINARY_DIR}/README.md COPYONLY)
##########################
# Build Tests
##########################
option(DO_AUTO_TEST
"Execute test suit automatically at the end of the build." OFF)
add_subdirectory(test)
##########################
# Build benchmark
##########################
if (DO_BENCHMARK)
add_subdirectory(benchmark)
endif ()
message("CMAKE_CXX_FLAGS" ${CMAKE_CXX_FLAGS})
message("CMAKE_EXE_LINKER_FLAGS" ${CMAKE_EXE_LINKER_FLAGS})