-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
231 lines (178 loc) · 9.84 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
# Copyright (c) 2018-2020 Jakob Meng, <[email protected]>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
#################### project settings ####################
project(hbrs-theta_utils VERSION 2020.0.0.0)
include(FeatureSummary)
#################### options ####################
option(HBRS_THETA_UTILS_ENABLE_TESTS "Build unit tests." OFF)
#################### find all used packages ####################
# NOTE: Keep list of packages in sync with dependencies in *-cmake.in!
find_package(hbrs-cmake)
set_package_properties(hbrs-cmake PROPERTIES
PURPOSE "Required for CMake modules."
TYPE REQUIRED)
find_package(hbrs-mpl)
set_package_properties(hbrs-mpl PROPERTIES
PURPOSE "Required for linear algebra algorithms."
TYPE REQUIRED)
find_package(Boost 1.62 COMPONENTS unit_test_framework system thread serialization chrono program_options filesystem iostreams regex exception log)
set_package_properties(Boost PROPERTIES
PURPOSE "Required for meta programming, unit tests and others."
TYPE REQUIRED)
find_package(MPI)
set_package_properties(MPI PROPERTIES
PURPOSE "Required for distributed linear algebra algortihms."
TYPE REQUIRED)
find_package(netcdf)
set_package_properties(netcdf PROPERTIES
PURPOSE "Required for reading theta result files."
TYPE REQUIRED)
find_package(VTK)
set_package_properties(VTK PROPERTIES
PURPOSE "Required for writing visualization output files.")
if(NOT VTK_FOUND)
# We will fall back to ParaView's internal VTK install if a standalone VTK install is not found
find_package(ParaView)
set_package_properties(ParaView PROPERTIES
PURPOSE "Required for writing visualization output files.")
endif()
# Either ParaView..
if(ParaView_FOUND)
set_package_properties(ParaView PROPERTIES
TYPE REQUIRED)
endif()
# ..or VTK is required
if(NOT VTK_FOUND AND NOT ParaView_FOUND)
set_package_properties(VTK PROPERTIES
TYPE REQUIRED)
endif()
feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES)
#################### source settings ####################
# put the include dirs which are in the source or build tree before all other include dirs, so the headers in the sources are preferred over the already installed ones
set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
# Src: kdelibs/cmake/modules/KDE4Defaults.cmake
if(VTK_FOUND AND VTK_USE_FILE)
include(${VTK_USE_FILE})
endif()
set(CXX_TEMPLATE_DEPTH 250 CACHE STRING "Set the maximum instantiation depth for template classes to n (-ftemplate-depth=n).") # increased depth is required by operators.hpp
set(CXX_TEMPLATE_BACKTRACE_LIMIT 250 CACHE STRING "Set the maximum number of template instantiation notes for a single warning or error to n (-ftemplate-backtrace-limit=n).")
set(CXX_ERROR_LIMIT 0 CACHE STRING "Limits the maximum number of error messages to n (-fmax-errors=n / -ferror-limit=n).")
set(CXX_CONSTEXPR_BACKTRACE_LIMIT 250 CACHE STRING "-fconstexpr-backtrace-limit=n")
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "Whether to create a position-independent target")
set(CMAKE_C_VISIBILITY_PRESET hidden CACHE STRING "Value for symbol visibility C compile flags")
set(CMAKE_CXX_VISIBILITY_PRESET hidden CACHE STRING "Value for symbol visibility C++ compile flags")
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON CACHE BOOL "Whether to add a compile flag to hide symbols of inline functions")
# "CMake will generate tests only if the enable_testing() command has been invoked." [1]
# "Note that ctest expects to find a test file in the build directory root. Therefore, this command should be in the
# source directory root." [2]
# References:
# [1] https://cmake.org/cmake/help/latest/command/add_test.html#command:add_test
# [2] https://cmake.org/cmake/help/latest/command/enable_testing.html
if(HBRS_THETA_UTILS_ENABLE_TESTS)
enable_testing()
endif()
#################### build settings ####################
include(MaybeAddFlags)
maybe_add_c_flag (HBRS_THETA_UTILS_HAS_C_WALL "-Wall")
maybe_add_cxx_flag(HBRS_THETA_UTILS_HAS_CXX_WALL "-Wall")
#maybe_add_c_flag (HBRS_THETA_UTILS_HAS_C_WEXTRA "-Wextra")
#maybe_add_cxx_flag(HBRS_THETA_UTILS_HAS_CXX_WEXTRA "-Wextra")
maybe_add_c_flag (HBRS_THETA_UTILS_HAS_C_WPEDANTIC "-Wpedantic")
maybe_add_cxx_flag(HBRS_THETA_UTILS_HAS_CXX_WPEDANTIC "-Wpedantic")
maybe_add_c_flag (HBRS_THETA_UTILS_HAS_C_WERROR_RETURN_TYPE "-Werror=return-type")
maybe_add_cxx_flag(HBRS_THETA_UTILS_HAS_CXX_WERROR_RETURN_TYPE "-Werror=return-type")
maybe_add_c_flag (HBRS_THETA_UTILS_HAS_C_PEDANTIC_ERRORS "-pedantic-errors")
maybe_add_cxx_flag(HBRS_THETA_UTILS_HAS_CXX_PEDANTIC_ERRORS "-pedantic-errors")
maybe_add_cxx_flag(HBRS_THETA_UTILS_HAS_CXX_FTEMPLATE_DEPTH "-ftemplate-depth=${CXX_TEMPLATE_DEPTH}")
maybe_add_cxx_flag(HBRS_THETA_UTILS_HAS_CXX_FTEMPLATE_BACKTRACE_LIMIT "-ftemplate-backtrace-limit=${CXX_TEMPLATE_BACKTRACE_LIMIT}")
maybe_add_cxx_flag(HBRS_THETA_UTILS_HAS_CXX_FCONSTEXPR_BACKTRACE_LIMIT "-fconstexpr-backtrace-limit=${CXX_CONSTEXPR_BACKTRACE_LIMIT}")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
maybe_add_cxx_flag(HBRS_THETA_UTILS_HAS_CXX_FERROR_LIMIT "-ferror-limit=${CXX_ERROR_LIMIT}")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
maybe_add_cxx_flag(HBRS_THETA_UTILS_HAS_CXX_FMAX_ERRORS "-fmax-errors=${CXX_ERROR_LIMIT}")
endif()
if(NOT HBRS_THETA_UTILS_HAS_CXX_FTEMPLATE_DEPTH)
message(FATAL_ERROR "Your C++ compiler ${CMAKE_CXX_COMPILER} does not support '-ftemplate-depth=${CXX_TEMPLATE_DEPTH}', use it at your own risk.")
endif()
if(NOT HBRS_THETA_UTILS_HAS_CXX_FTEMPLATE_BACKTRACE_LIMIT)
message(WARNING "Your C++ compiler ${CMAKE_CXX_COMPILER} does not support '-ftemplate-backtrace-limit=${CXX_TEMPLATE_BACKTRACE_LIMIT}', use it at your own risk.")
endif()
if(NOT HBRS_THETA_UTILS_HAS_CXX_FCONSTEXPR_BACKTRACE_LIMIT)
message(WARNING "Your C++ compiler ${CMAKE_CXX_COMPILER} does not support '-fconstexpr-backtrace-limit=${CXX_CONSTEXPR_BACKTRACE_LIMIT}', use it at your own risk.")
endif()
include(CheckIPOSupported)
check_ipo_supported(RESULT HBRS_THETA_UTILS_HAS_IPO)
if(HBRS_THETA_UTILS_HAS_IPO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
endif()
#################### install settings ####################
include(GNUInstallDirs)
# Src.: http://www.cmake.org/cmake/help/v2.8.8/cmake.html#module:GNUInstallDirs
# Offer a choice of overriding the installation directories
set(HBRS_THETA_UTILS_INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "install dir for executables")
set(HBRS_THETA_UTILS_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "install dir for libraries")
set(HBRS_THETA_UTILS_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "install dir for headers")
set(HBRS_THETA_UTILS_INSTALL_CMAKEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME} CACHE PATH "install dir for CMake files")
set(HBRS_THETA_UTILS_INSTALL_TARGETS_DEFAULT_DESTINATIONS
RUNTIME DESTINATION "${HBRS_THETA_UTILS_INSTALL_BINDIR}"
LIBRARY DESTINATION "${HBRS_THETA_UTILS_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${HBRS_THETA_UTILS_INSTALL_LIBDIR}"
PUBLIC_HEADER DESTINATION "${HBRS_THETA_UTILS_INSTALL_INCLUDEDIR}"
PRIVATE_HEADER DESTINATION "${HBRS_THETA_UTILS_INSTALL_INCLUDEDIR}"
INCLUDES DESTINATION "${HBRS_THETA_UTILS_INSTALL_INCLUDEDIR}")
#################### tests ####################
# CMake's target test does not build but only executes tests
# Ref.: https://stackoverflow.com/a/736838/6490710
if(HBRS_THETA_UTILS_ENABLE_TESTS)
set(_TESTS_MAYBE_ALL ALL)
endif()
add_custom_target(tests ${_TESTS_MAYBE_ALL} COMMENT "Build all tests.")
include(DevTools)
function(hbrs_theta_utils_add_test target)
add_executable(${target} EXCLUDE_FROM_ALL "${ARGN}")
target_link_libraries(${target} hbrs_theta_utils ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
target_include_directories(${target}
SYSTEM
PUBLIC ${Boost_INCLUDE_DIRS})
target_compile_definitions(${target} PUBLIC ${MPI_CXX_COMPILE_DEFINITIONS} BOOST_LOG_DYN_LINK)
add_test(${target} ${CMAKE_CURRENT_BINARY_DIR}/${target})
add_dependencies(tests ${target})
endfunction()
#################### list the subdirectories ####################
add_subdirectory(src)
#################### install files ####################
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/hbrs-theta_utils-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/hbrs-theta_utils-config.cmake"
INSTALL_DESTINATION "${HBRS_THETA_UTILS_INSTALL_CMAKEDIR}"
PATH_VARS
HBRS_THETA_UTILS_INSTALL_BINDIR
HBRS_THETA_UTILS_INSTALL_LIBDIR
HBRS_THETA_UTILS_INSTALL_INCLUDEDIR
HBRS_THETA_UTILS_INSTALL_CMAKEDIR)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/hbrs-theta_utils-config-version.cmake"
VERSION ${hbrs-theta_utils_VERSION}
COMPATIBILITY AnyNewerVersion)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/hbrs-theta_utils-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/hbrs-theta_utils-config-version.cmake"
DESTINATION ${HBRS_THETA_UTILS_INSTALL_CMAKEDIR}
COMPONENT development)
install(EXPORT hbrs-theta_utils-targets
FILE hbrs-theta_utils-targets.cmake
NAMESPACE hbrs-theta_utils::
DESTINATION ${HBRS_THETA_UTILS_INSTALL_CMAKEDIR})
#################### summary ####################
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)