-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
277 lines (224 loc) · 9.13 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
276
277
cmake_minimum_required(VERSION 3.0...3.28)
# ##############################################################################
# GENERAL SETTINGS
# ##############################################################################
project(FANS
VERSION 0.3.0
LANGUAGES C CXX
)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# with -fno-implicit-templates I get linker errors when using std:: stuff
# TODO: should be developer specific, by using e.g. CMake Presets
set(CMAKE_CXX_FLAGS "-fmax-errors=1 -O3")
set(CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
# IPO
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.9")
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported)
get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
check_ipo_supported(RESULT result LANGUAGES ${languages})
if (result AND NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
option(CMAKE_INTERPROCEDURAL_OPTIMIZATION
"Enable interprocedural optimization for all targets." ON
)
message(STATUS "IPO activated.")
elseif (NOT result)
message(STATUS "IPO not supported.")
endif ()
endif ()
# ##############################################################################
# RPATH settings
# ##############################################################################
# Taken from https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# From https://stackoverflow.com/questions/73248130/how-to-avoid-the-removal-of-the-rpath-during-cmake-install-step
# Set RPATH to be relative and honor user overrides, whether at the command line or FetchContent
set(RPATH_BASE "$ORIGIN")
file(RELATIVE_PATH REL_PATH_LIB
"/${CMAKE_INSTALL_BINDIR}/"
"/${CMAKE_INSTALL_LIBDIR}/")
set(CMAKE_INSTALL_RPATH "${RPATH_BASE};${RPATH_BASE}/${REL_PATH_LIB}"
CACHE STRING "Install RPATH")
# ##############################################################################
# REQUIRED PACKAGES
# ##############################################################################
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
if ("$ENV{SETVARS_COMPLETED}" STREQUAL "1")
message(
WARNING
"Intel OneAPI environment is active, which might lead to issues with MPI discovery."
)
endif ()
set(HDF5_ENABLE_PARALLEL ON)
find_package(HDF5 REQUIRED COMPONENTS CXX)
find_package(Eigen3 REQUIRED)
find_package(OpenMP REQUIRED)
find_package(MPI REQUIRED)
find_package(FFTW3 REQUIRED COMPONENTS DOUBLE MPI)
# ##############################################################################
# TARGETS
# ##############################################################################
option(FANS_BUILD_STATIC "Build static library" OFF)
if (FANS_BUILD_STATIC)
add_library(FANS_FANS STATIC)
else ()
add_library(FANS_FANS SHARED)
endif ()
add_library(FANS::FANS ALIAS FANS_FANS)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm|aarch64")
target_compile_options(FANS_FANS PUBLIC -march=armv8-a+simd+fp+crypto)
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
target_compile_options(FANS_FANS PUBLIC -mavx2 -mfma)
endif ()
add_executable(FANS_main)
add_custom_command(
TARGET FANS_main
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
$<TARGET_FILE:FANS_main>
${CMAKE_CURRENT_SOURCE_DIR}/test/$<TARGET_FILE_NAME:FANS_main>
COMMENT "Create a symlink for FANS executable to ${CMAKE_CURRENT_SOURCE_DIR}/test/"
)
# ##############################################################################
# HEADERS
# ##############################################################################
target_include_directories(FANS_FANS PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
# TODO: when creating a shared library in the future, maybe create one single
# FANS.h header that consuming projects can use
set_property(TARGET FANS_FANS PROPERTY PUBLIC_HEADER
include/general.h
include/json.hpp
include/matmodel.h
include/reader.h
include/solverCG.h
include/solverFP.h
include/solver.h
include/setup.h
include/material_models/LinearThermal.h
include/material_models/LinearElastic.h
include/material_models/PseudoPlastic.h
include/material_models/J2Plasticity.h
)
# ##############################################################################
# SOURCES
# ##############################################################################
target_sources(FANS_FANS PRIVATE
src/reader.cpp
)
target_sources(FANS_main PRIVATE
src/main.cpp
)
# ##############################################################################
# LINKING
# ##############################################################################
target_link_libraries(FANS_FANS PRIVATE m)
# TODO: when switching to a newer CMake version this can all be done by one
# call to target_link_libraries(FANS_FANS PUBLIC HDF5::HDF5). But CMake 3.16
# does not yet support this.
target_include_directories(FANS_FANS PUBLIC ${HDF5_INCLUDE_DIRS})
target_link_libraries(FANS_FANS PUBLIC ${HDF5_CXX_LIBRARIES})
target_compile_definitions(FANS_FANS PUBLIC ${HDF5_DEFINITIONS})
if (HDF5_IS_PARALLEL)
target_compile_definitions(FANS_FANS PUBLIC H5_HAVE_PARALLEL)
endif ()
target_link_libraries(FANS_FANS PUBLIC MPI::MPI_CXX)
target_include_directories(FANS_FANS PUBLIC ${FFTW3_INCLUDE_DIRS})
target_link_libraries(FANS_FANS PUBLIC ${FFTW3_LIBRARIES})
target_compile_definitions(FANS_FANS PUBLIC ${FFTW3_DEFINITIONS})
target_link_libraries(FANS_FANS PUBLIC Eigen3::Eigen)
target_link_libraries(FANS_FANS PUBLIC OpenMP::OpenMP_CXX)
target_link_libraries(FANS_main PRIVATE FANS::FANS)
# ##############################################################################
# NAMING
# ##############################################################################
set_target_properties(FANS_FANS PROPERTIES OUTPUT_NAME FANS)
set_target_properties(FANS_FANS PROPERTIES EXPORT_NAME FANS)
set_target_properties(FANS_main PROPERTIES OUTPUT_NAME FANS)
# ##############################################################################
# INSTALLING
# ##############################################################################
install(
TARGETS FANS_FANS
EXPORT FANS
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT FANS_Runtime
NAMELINK_COMPONENT FANS_Development
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT FANS_Development
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/FANS
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/FANS
COMPONENT FANS_Development
PRIVATE_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/FANS
COMPONENT FANS_Development
)
install(
TARGETS FANS_main
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT FANS_Runtime
)
install(
EXPORT FANS
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/FANS
NAMESPACE FANS::
FILE FANSTargets.cmake
COMPONENT FANS_Development
)
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/FindFFTW3.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/FANS/modules
COMPONENT FANS_Development
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/FANSConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/FANSConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/FANSConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/FANS"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/FANSConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/FANSConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/FANS
COMPONENT FANS_Development
)
# ##############################################################################
# TESTING
# ##############################################################################
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(FANS_ENABLE_TESTING_DEFAULT ON)
endif ()
option(FANS_ENABLE_TESTING "Enable testing" ${FANS_ENABLE_TESTING_DEFAULT})
if (FANS_ENABLE_TESTING)
enable_testing()
add_subdirectory(test)
endif ()
# ##############################################################################
# PACKAGING
# ##############################################################################
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(FANS_ENABLE_PACKAGING_DEFAULT ON)
endif ()
option(FANS_ENABLE_PACKAGING "Enable creation of Debian packages" ${FANS_ENABLE_PACKAGING_DEFAULT})
if (FANS_ENABLE_PACKAGING)
add_subdirectory(cmake/packaging)
endif ()