-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathCMakeLists.txt
276 lines (233 loc) · 10.5 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# Main dcgp/dcgpy project version.
set(DCGP_PROJECT_VERSION 1.6.1)
# CMake version check.
# NOTE: C++17 supported since CMake 3.8.
cmake_minimum_required(VERSION 3.8)
# Module path setup.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules" "${CMAKE_SOURCE_DIR}/cmake_modules/yacma")
message(STATUS "System name: ${CMAKE_SYSTEM_NAME}")
# Set default build type to "Release".
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
# Main build options: build dcgp or dcgpy. They cannot be on at the same time,
# and only one must be chosen.
option(DCGP_BUILD_DCGP "Build dcgp." ON)
option(DCGP_BUILD_DCGPY "Build dcgpy." OFF)
# Check consistency.
if(DCGP_BUILD_DCGP AND DCGP_BUILD_DCGPY)
message(FATAL_ERROR "Please select whether to build dcgp or dcgpy: you cannot build them both at the same time.")
endif()
if((NOT DCGP_BUILD_DCGP) AND (NOT DCGP_BUILD_DCGPY))
message(FATAL_ERROR "Please select if you want to build dcgp or dcgpy.")
endif()
if(DCGP_BUILD_DCGP)
# Initial setup of a dcgp build.
project(dcgp VERSION ${DCGP_PROJECT_VERSION})
enable_testing()
# Build option: enable test set.
option(DCGP_BUILD_TESTS "Build test set." ON)
# Build option: enable benchmark.
option(DCGP_BUILD_BENCHMARKS "Build benchmarks." OFF)
# Build option: enable examples
option(DCGP_BUILD_EXAMPLES "Build test set." OFF)
# Build Option: when active the file main.cpp is built.
option(DCGP_BUILD_MAIN "Build 'main.cpp'." OFF)
else()
# Initial setup of a dcgpy build.
project(dcgpy VERSION ${DCGP_PROJECT_VERSION})
endif()
# Common general bits.
# Initial setup of compiler flags.
include(YACMACompilerLinkerSettings)
# Threading setup.
include(YACMAThreadingSetup)
# Assemble the flags.
set(DCGP_CXX_FLAGS_DEBUG ${YACMA_CXX_FLAGS} ${YACMA_CXX_FLAGS_DEBUG} ${YACMA_THREADING_CXX_FLAGS})
set(DCGP_CXX_FLAGS_RELEASE ${YACMA_CXX_FLAGS} ${YACMA_THREADING_CXX_FLAGS})
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND YACMA_COMPILER_IS_CLANGXX)
message(STATUS "Clang compiler on OSX detected, setting the standard library to 'libc++'.")
list(APPEND DCGP_CXX_FLAGS_DEBUG "-stdlib=libc++")
list(APPEND DCGP_CXX_FLAGS_RELEASE "-stdlib=libc++")
endif()
if(YACMA_COMPILER_IS_MSVC)
include(CheckCXXCompilerFlag)
# Disable the idiotic minmax macros on MSVC, some annoying warnings,
# and enable the bigobj option.
# Also, enable the WIN32_LEAN_AND_MEAN definition.
list(APPEND DCGP_CXX_FLAGS_DEBUG "-DNOMINMAX" "/wd4459" "/wd4127" "/wd4702" "/bigobj" "-DWIN32_LEAN_AND_MEAN")
list(APPEND DCGP_CXX_FLAGS_RELEASE "-DNOMINMAX" "/wd4459" "/wd4127" "/wd4702" "/bigobj" "-DWIN32_LEAN_AND_MEAN")
# Enable strict conformance mode, if supported.
set(CMAKE_REQUIRED_QUIET TRUE)
check_cxx_compiler_flag("/permissive-" _DCGP_MSVC_SUPPORTS_STRICT_CONFORMANCE)
unset(CMAKE_REQUIRED_QUIET)
if(_DCGP_MSVC_SUPPORTS_STRICT_CONFORMANCE)
message(STATUS "The '/permissive-' flag is supported, enabling it.")
list(APPEND DCGP_CXX_FLAGS_DEBUG "/permissive-")
list(APPEND DCGP_CXX_FLAGS_RELEASE "/permissive-")
endif()
unset(_DCGP_MSVC_SUPPORTS_STRICT_CONFORMANCE)
if(YACMA_COMPILER_IS_CLANGXX)
# clang-cl emits various warnings from GMP/MPFR, let's just silence them.
# NOTE: at one point in the recent past, MSVC added an options similar to GCC's isystem:
# https://blogs.msdn.microsoft.com/vcblog/2017/12/13/broken-warnings-theory/
# We probably just need to wait for this to be picked up by CMake/clang-cl. Let's
# revisit the issue in the future.
list(APPEND _DCGP_CLANG_CL_DISABLED_WARNINGS
"-Wno-unused-variable"
"-Wno-inconsistent-dllimport"
"-Wno-unknown-pragmas"
"-Wno-unused-parameter"
"-Wno-sign-compare"
"-Wno-deprecated-declarations"
"-Wno-deprecated-dynamic-exception-spec"
"-Wno-old-style-cast"
"-Wno-sign-conversion"
"-Wno-non-virtual-dtor"
"-Wno-deprecated"
"-Wno-shadow"
"-Wno-shorten-64-to-32"
"-Wno-reserved-id-macro"
"-Wno-undef"
"-Wno-c++98-compat-pedantic"
"-Wno-documentation-unknown-command"
"-Wno-zero-as-null-pointer-constant"
"-Wno-language-extension-token"
"-Wno-gnu-anonymous-struct"
"-Wno-nested-anon-types"
"-Wno-documentation"
"-Wno-comma"
"-Wno-nonportable-system-include-path"
"-Wno-global-constructors"
"-Wno-redundant-parens"
"-Wno-exit-time-destructors"
"-Wno-missing-noreturn"
"-Wno-switch-enum"
"-Wno-covered-switch-default"
"-Wno-float-equal"
"-Wno-double-promotion"
"-Wno-microsoft-enum-value"
"-Wno-missing-prototypes"
"-Wno-implicit-fallthrough"
"-Wno-format-nonliteral"
"-Wno-cast-qual"
"-Wno-disabled-macro-expansion"
"-Wno-unused-private-field"
"-Wno-unused-template"
"-Wno-unused-macros"
"-Wno-extra-semi-stmt"
"-Wno-c++98-compat"
"-Wno-microsoft-cpp-macro")
list(APPEND DCGP_CXX_FLAGS_DEBUG ${_DCGP_CLANG_CL_DISABLED_WARNINGS})
list(APPEND DCGP_CXX_FLAGS_RELEASE ${_DCGP_CLANG_CL_DISABLED_WARNINGS})
unset(_DCGP_CLANG_CL_DISABLED_WARNINGS)
endif()
endif()
if(YACMA_COMPILER_IS_INTELXX)
# NOTE: on MSVC we use the push/pop pragmas, but they do not seem to work on Intel (the pragmas
# in icc influence the behaviour at instantiation point, not at definition point).
# These warnings are useful in principle, but they are generated a lot from cereal and we have no
# way of disabling them selectively. Just rely on the other compilers to provde good diagnostic.
list(APPEND DCGP_CXX_FLAGS_DEBUG "-diag-disable" "2259,1682,68")
list(APPEND DCGP_CXX_FLAGS_RELEASE "-diag-disable" "2259,1682,68")
endif()
if(MINGW)
# Flag needed to deal with big binaries in MinGW.
message(STATUS "Enabling the '-Wa,-mbig-obj' flag in MinGW builds.")
list(APPEND DCGP_CXX_FLAGS_DEBUG "-Wa,-mbig-obj")
list(APPEND DCGP_CXX_FLAGS_RELEASE "-Wa,-mbig-obj")
endif()
# Some flags that generate warnings due to Eigen obsolete versions
list(REMOVE_ITEM DCGP_CXX_FLAGS_DEBUG "-Wduplicated-branches")
list(REMOVE_ITEM DCGP_CXX_FLAGS_DEBUG "-Wold-style-cast")
# Creates the file config.hpp
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.hpp.in" "${CMAKE_CURRENT_SOURCE_DIR}/include/dcgp/config.hpp" @ONLY)
if(DCGP_BUILD_DCGPY)
include(YACMAPythonSetup)
# Python version check.
if(${PYTHON_VERSION_MAJOR} LESS 2 OR (${PYTHON_VERSION_MAJOR} EQUAL 2 AND ${PYTHON_VERSION_MINOR} LESS 7))
message(FATAL_ERROR "Minimum supported Python version is 2.7.")
endif()
# NOTE: for the time being, require that dcgp/dcgpy versions are matching exactly.
find_package(dcgp ${DCGP_PROJECT_VERSION} EXACT REQUIRED)
endif()
# Boost setup (common to dcgp/dcgpy).
include(DCGPFindBoost)
if(DCGP_BUILD_DCGP)
# Eigen setup
find_package(Eigen3 REQUIRED)
message(STATUS "Eigen include directory: ${EIGEN3_INCLUDE_DIR}")
message(STATUS "Eigen version detected: ${EIGEN3_VERSION}")
include_directories(${EIGEN3_INCLUDE_DIR})
# Audi setup
find_package(Audi REQUIRED)
message(STATUS "AUDI include dir is: ${DCGP_INCLUDE_DIRS}")
# Pagmo setup
find_package(Pagmo REQUIRED)
message(STATUS "Pagmo dir is: ${Pagmo_DIR}")
# TBB setup (this will be invoked and found by pagmo too, can it be removed?)
find_package(TBB REQUIRED)
message(STATUS "TBB include dir is: ${TBB_INCLUDE_DIRS}")
message(STATUS "TBB library is: ${TBB_LIBRARIES}")
# Symengine setup
find_package(SymEngine REQUIRED)
message(STATUS "Symengine library found.")
message(STATUS "Symengine include dir is: ${SYMENGINE_INCLUDE_DIRS}")
message(STATUS "Symengine library is: ${SYMENGINE_LIBRARIES}")
include_directories(${SYMENGINE_INCLUDE_DIRS})
# Setup of the header-only dcgp library.
add_library(dcgp INTERFACE)
# This sets up the include directory to be different if we build
target_include_directories(dcgp INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(dcgp INTERFACE Boost::boost Boost::serialization Eigen3::eigen3 TBB::tbb)
target_link_libraries(dcgp INTERFACE Audi::audi Pagmo::pagmo ${SYMENGINE_LIBRARIES})
# Build main
if(DCGP_BUILD_MAIN)
add_executable(main main.cpp)
target_link_libraries(main dcgp)
set_property(TARGET main PROPERTY CXX_STANDARD 17)
set_property(TARGET main PROPERTY CXX_STANDARD_REQUIRED YES)
set_property(TARGET main PROPERTY CXX_EXTENSIONS NO)
endif()
# Builds the tests
if(DCGP_BUILD_TESTS)
add_subdirectory("${CMAKE_SOURCE_DIR}/test")
endif()
# Builds the examples
if(DCGP_BUILD_EXAMPLES)
add_subdirectory("${CMAKE_SOURCE_DIR}/examples")
endif()
# Builds the benchmarks
if(DCGP_BUILD_BENCHMARKS)
add_subdirectory("${CMAKE_SOURCE_DIR}/benchmark")
endif()
# Configure the doc files.
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen/Doxyfile.in" "${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen/Doxyfile" @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/doc/sphinx/conf.py.in" "${CMAKE_CURRENT_SOURCE_DIR}/doc/sphinx/conf.py" @ONLY)
# Setup of the export.
install(TARGETS dcgp EXPORT dcgp_export)
# Setup cmake config files
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/dcgp-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/dcgp-config.cmake" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/dcgp-config.cmake" DESTINATION "lib/cmake/dcgp")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/DCGPFindBoost.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindEigen3.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindTBB.cmake"
DESTINATION "lib/cmake/dcgp")
install(EXPORT dcgp_export NAMESPACE Dcgp:: DESTINATION lib/cmake/dcgp)
# Take care of versioning.
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/dcgp-config-version.cmake" VERSION ${dcgp_VERSION}
COMPATIBILITY ExactVersion)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/dcgp-config-version.cmake" DESTINATION "lib/cmake/dcgp")
# Do the actual library installation.
install(DIRECTORY include/ DESTINATION include)
endif()
if(DCGP_BUILD_DCGPY)
add_subdirectory("${CMAKE_SOURCE_DIR}/dcgpy")
endif()