-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
476 lines (453 loc) · 17.9 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
cmake_minimum_required(VERSION 3.21)
project(Tatooine)
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(FetchContent)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
# ------------------------------------------------------------------------------
# git submodules
# ------------------------------------------------------------------------------
find_package(Git REQUIRED)
function(update_git_submodule dir)
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive -- ${dir}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(
FATAL_ERROR
"When updating submodule ${dir}:\n\
git submodule update --init --recursive -- ${dir}\n\
failed with ${GIT_SUBMOD_RESULT}, please checkout submodules.")
endif()
endfunction()
# ------------------------------------------------------------------------------
set(TATOOINE_MANDATORY_GIT_SUBMODULES external/rapidxml external/indicators
external/gcem)
foreach(SUBMODULE ${TATOOINE_MANDATORY_GIT_SUBMODULES})
update_git_submodule(${SUBMODULE})
endforeach()
add_library(rapidxml INTERFACE)
target_include_directories(rapidxml SYSTEM INTERFACE external/rapidxml)
# ------------------------------------------------------------------------------
set(REAL_NUMBER double float)
set(TATOOINE_REAL_NUMBER_TYPE
double
CACHE STRING "Floating point type for real numbers")
set_property(CACHE TATOOINE_REAL_NUMBER_TYPE PROPERTY STRINGS ${REAL_NUMBER})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/tatooine/real.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/tatooine/real.h)
# ------------------------------------------------------------------------------
# filesystem check
# ------------------------------------------------------------------------------
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
try_compile(
TATOOINE_STD_FILESYSTEM_COMPILED "${CMAKE_BINARY_DIR}/temp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/test_has_filesystem.cpp"
CMAKE_FLAGS -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD_REQUIRED=ON
LINK_LIBRARIES stdc++fs)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
try_compile(
TATOOINE_STD_FILESYSTEM_COMPILED "${CMAKE_BINARY_DIR}/temp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/test_has_filesystem.cpp"
CMAKE_FLAGS -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD_REQUIRED=ON)
endif()
# ------------------------------------------------------------------------------
set(TATOOINE_EXTERNAL ${CMAKE_SOURCE_DIR}/external)
include(target_link_libraries_system)
# ------------------------------------------------------------------------------
# clang-tidy
find_program(
CLANG_TIDY_EXECUTABLE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable")
if(CLANG_TIDY_EXECUTABLE)
option(TATOOINE_USE_CLANG_TIDY "use clang-tidy checks while building" FALSE)
string(
CONCAT CLANG_TIDY_CHECKS
"-*"
",cppcoreguidelines*"
",hicpp-*"
",modernize-*"
",performance-*"
",readability-*"
",-cppcoreguidelines-pro-type-reinterpret-cast"
",-cppcoreguidelines-pro-bounds-pointer-arithmetic"
",-cppcoreguidelines-pro-bounds-constant-array-index"
",-cppcoreguidelines-macro-usage"
",-cert-err34-c"
",-readability-magic-numbers"
",-readability-isolate-declaration"
",-readability-static-accessed-through-instance"
",-readability-named-parameter")
set(CLANG_TIDY_DOMMAND
${CLANG_TIDY_EXECUTABLE} -header-filter=${CMAKE_SOURCE_DIR}
-checks=-*,cppcoreguidelines-*,modernize-*)
else()
set(TATOOINE_USE_CLANG_TIDY FALSE)
endif()
# ------------------------------------------------------------------------------
# create library target
add_library(base INTERFACE)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
target_compile_definitions(base INTERFACE _USE_MATH_DEFINES)
target_compile_definitions(base INTERFACE NOMINMAX)
endif()
set_property(TARGET base PROPERTY CXX_STANDARD 20)
option(TATOOINE_BUILD_DOC "Builds the documentation" OFF)
if(TATOOINE_BUILD_DOC)
option(TATOOINE_DOC_ONLY "Only builds documentation" OFF)
add_subdirectory(doc)
target_compile_options(base INTERFACE -DTATOOINE_DOC_ONLY)
endif()
# ------------------------------------------------------------------------------
# Boost
# ------------------------------------------------------------------------------
# set include dirs
target_include_directories(
base
INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
external/indicators/include)
target_link_libraries(base INTERFACE rapidxml)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(base INTERFACE -Wno-interference-size)
endif()
target_include_directories(base SYSTEM INTERFACE external/gcem/include)
if(TATOOINE_STD_FILESYSTEM_COMPILED)
set(TATOOINE_STD_FILESYSTEM_AVAILABLE 1)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
target_link_libraries(base INTERFACE stdc++fs)
endif()
else()
set(TATOOINE_STD_FILESYSTEM_AVAILABLE 0)
find_package(Boost REQUIRED COMPONENTS filesystem)
target_link_libraries(base INTERFACE Boost::filesystem)
endif()
target_compile_definitions(
base
INTERFACE
TATOOINE_STD_FILESYSTEM_AVAILABLE=${TATOOINE_STD_FILESYSTEM_AVAILABLE})
# enable warnings
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}"
STREQUAL "Clang")
target_compile_options(base INTERFACE -Wall -Wextra -Wpedantic -Wconversion)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(base INTERFACE /W4)
endif()
if(NOT TATOOINE_DOC_ONLY)
# ============================================================================
# Required Packages
# ============================================================================
find_package(Boost REQUIRED)
target_link_libraries(base INTERFACE Boost::headers)
# ----------------------------------------------------------------------------
# OpenMP
# ----------------------------------------------------------------------------
find_package(OpenMP COMPONENTS CXX)
if(OpenMP_FOUND)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(base INTERFACE "/openmp:llvm")
else()
target_link_libraries(base INTERFACE OpenMP::OpenMP_CXX)
target_compile_options(base INTERFACE -fopenmp)
endif()
set(TATOOINE_OPENMP_AVAILABLE 1)
message(STATUS "Compiling with OpenMP")
else()
set(TATOOINE_OPENMP_AVAILABLE 0)
message(STATUS "OpenMP not available")
endif()
target_compile_definitions(
base INTERFACE TATOOINE_OPENMP_AVAILABLE=${TATOOINE_OPENMP_AVAILABLE})
# ============================================================================
# Optional Packages
# ============================================================================
# ----------------------------------------------------------------------------
# PNG
# ----------------------------------------------------------------------------
find_package(PNG)
if(PNG_FOUND)
find_package(PNG++)
if(DEFINED PNG++_INCLUDE_DIRS)
target_include_directories(base INTERFACE ${PNG_INCLUDE_DIRS}
${PNG++_INCLUDE_DIRS})
target_link_libraries(base INTERFACE ${PNG_LIBRARIES} ${PNG++_LIBRARIES})
message(STATUS "${PNG_LIBRARIES} ${PNG++_LIBRARIES}")
set(TATOOINE_PNG_AVAILABLE 1)
else()
set(TATOOINE_PNG_AVAILABLE 0)
endif()
else()
set(TATOOINE_PNG_AVAILABLE 0)
endif()
target_compile_definitions(
base INTERFACE TATOOINE_PNG_AVAILABLE=${TATOOINE_PNG_AVAILABLE})
# ----------------------------------------------------------------------------
# MPI
# ----------------------------------------------------------------------------
get_filename_component(C_COMPILER_EXECUTABLE ${CMAKE_C_COMPILER} NAME)
get_filename_component(CXX_COMPILER_EXECUTABLE ${CMAKE_CXX_COMPILER} NAME)
if("${CXX_COMPILER_EXECUTABLE}" STREQUAL "mpicxx")
find_package(
MPI
COMPONENTS C
QUIET)
if(MPI_C_FOUND)
option(TATOOINE_BUILD_MPI "Builds MPI-related projecs" ON)
if(TATOOINE_BUILD_MPI)
set(TATOOINE_MPI_AVAILABLE 1)
else()
set(TATOOINE_MPI_AVAILABLE 0)
endif()
else()
set(TATOOINE_MPI_AVAILABLE 0)
endif()
else()
message(STATUS "MPI can only be used if CXX_COMPILER_EXECUTABLE is mpicxx.\
Current: ${CXX_COMPILER_EXECUTABLE}")
set(TATOOINE_MPI_AVAILABLE 0)
endif()
# ----------------------------------------------------------------------------
# HDF5
# ----------------------------------------------------------------------------
option(TATOOINE_USE_HDF5 "Compile with HDF5 support" ON)
if(TATOOINE_USE_HDF5)
find_package(HDF5 QUIET COMPONENTS C)
if(HDF5_FOUND)
option(TATOOINE_USE_SYSTEM_HDF5_LIBS
"By setting this to ON tatooine will not compile HDF5 on its own."
ON)
else()
set(TATOOINE_USE_SYSTEM_HDF5_LIBS OFF)
endif()
if(TATOOINE_USE_SYSTEM_HDF5_LIBS)
if(HDF5_IS_PARALLEL)
message(STATUS "HDF5 available with MPI support")
else()
message(STATUS "HDF5 available without MPI support")
endif()
target_compile_definitions(base INTERFACE ${HDF5_DEFINITIONS}
${HDF5_C_DEFINITIONS})
set(TATOOINE_HDF5_AVAILABLE 1)
target_link_libraries(base INTERFACE ${HDF5_LIBRARIES})
target_include_directories(base INTERFACE ${HDF5_INCLUDE_DIRS})
set(TATOOINE_HDF5_HEADER hdf5.h)
else()
update_git_submodule(${TATOOINE_EXTERNAL}/hdf5)
set(ALLOW_UNSUPPORTED ON)
set(HDF5_EXTERNALLY_CONFIGURED 1)
set(HDF5_EXTERNAL_LIB_PREFIX
"tatooine"
CACHE STRING "Use prefix for custom library naming.")
set(HDF5_BUILD_CPP_LIB
OFF
CACHE BOOL "Build HDF5 C++ Library")
set(HDF5_BUILD_HL_LIB
OFF
CACHE BOOL "Build HIGH Level HDF5 Library")
set(HDF5_BUILD_JAVA
OFF
CACHE BOOL "Build Java HDF5 Library")
set(HDF5_BUILD_TOOLS
OFF
CACHE BOOL "Build HDF5 Tools")
set(HDF5_BUILD_UTILS
OFF
CACHE BOOL "Build HDF5 Utils")
set(HDF5_BUILD_EXAMPLES
OFF
CACHE BOOL "Build HDF5 Library Examples")
set(HDF5_ENABLE_COVERAGE
OFF
CACHE BOOL "Enable code coverage for Libraries and Programs")
set(HDF5_ENABLE_THREADSAFE
ON
CACHE BOOL "Enable thread-safety")
set(HDF5_ENABLE_DEPRECATED_SYMBOLS
OFF
CACHE BOOL "Enable deprecated public API symbols")
if(("${C_COMPILER_EXECUTABLE}" STREQUAL "mpicc"
OR "${C_COMPILER_EXECUTABLE}" STREQUAL "mpiicc")
AND TATOOINE_MPI_AVAILABLE)
message(STATUS "Building HDF5 with thread-safety and MPI support.")
set(HDF5_ENABLE_PARALLEL
ON
CACHE BOOL "Enable parallel build (requires MPI)")
set(HDF5_ENABLE_PARALLEL ON)
else()
message(
STATUS "Building HDF5 with thread-safety but without MPI support.")
set(HDF5_ENABLE_PARALLEL
OFF
CACHE BOOL "Enable parallel build (requires MPI)")
set(HDF5_ENABLE_PARALLEL OFF)
endif()
add_subdirectory(external/hdf5 EXCLUDE_FROM_ALL)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}"
STREQUAL "Clang")
set(TATOOINE_HDF5_WNOS
-Wno-larger-than
-Wno-null-dereference
-Wno-strict-overflow
-Wno-missing-field-initializers
-Wno-cast-qual
-Wno-sign-conversion
-Wno-unused-function
-Wno-unused-variable
-Wno-unused-parameter
-Wno-unused-label)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
list(
APPEND
TATOOINE_HDF5_WNOS
-Wno-stringop-overflow
-Wno-maybe-uninitialized
-Wno-discarded-qualifiers
-Wno-cast-function-type
-Wno-stringop-truncation)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
list(
APPEND
TATOOINE_HDF5_WNOS
-Wno-unknown-warning-option
-Wno-double-promotion
-Wno-discarded-qualifiers
-Wno-misleading-indentation
-Wno-incompatible-pointer-types-discards-qualifiers
-Wno-format-pedantic
-Wno-implicit-fallthrough
-Wno-cast-function-type
-Wno-maybe-uninitialized
-Wno-stringop-truncation
-Wno-stringop-overflow)
endif()
target_compile_options(hdf5-static PRIVATE ${TATOOINE_HDF5_WNOS})
endif()
target_link_libraries(base INTERFACE hdf5-static)
set(TATOOINE_HDF5_AVAILABLE 1)
list(APPEND TATOOINE_EXPORTING_TARGETS hdf5-static)
target_compile_definitions(base INTERFACE TATOOINE_USE_SYSTEM_HDF5_LIBS=0)
set(TATOOINE_HDF5_HEADER ${TATOOINE_EXTERNAL}/hdf5/src/hdf5.h)
endif()
else()
set(TATOOINE_HDF5_AVAILABLE 0)
endif()
target_compile_definitions(
base INTERFACE TATOOINE_HDF5_AVAILABLE=${TATOOINE_HDF5_AVAILABLE})
if(TATOOINE_HDF5_AVAILABLE)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/tatooine/hdf5_include.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/tatooine/hdf5_include.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/tatooine/hdf5/type.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/tatooine/hdf5/type.h)
endif()
# ----------------------------------------------------------------------------
# NetCDF
# ----------------------------------------------------------------------------
if(TATOOINE_USE_SYSTEM_HDF5_LIBS)
# option(TATOOINE_USE_SYSTEM_NETCDF_LIBS "By setting this to ON tatooine
# will not compile NetCDF on its own." OFF) if
# (TATOOINE_USE_SYSTEM_NETCDF_LIBS)
find_package(NetCDF QUIET)
if(NETCDF_FOUND)
message(STATUS "NetCDF available")
set(TATOOINE_NETCDF_AVAILABLE 1)
target_compile_definitions(base INTERFACE TATOOINE_NETCDF_AVAILABLE=1)
target_link_libraries(base INTERFACE ${NETCDF_LIBRARIES})
target_include_directories(base INTERFACE ${NETCDF_INCLUDES})
else()
target_compile_definitions(base INTERFACE TATOOINE_NETCDF_AVAILABLE=0)
endif()
# endif() endif() if ((NOT TATOOINE_USE_SYSTEM_NETCDF_LIBS) OR
# (TATOOINE_USE_SYSTEM_NETCDF_LIBS AND NOT NETCDF_FOUND))
# set(TATOOINE_NETCDF_AVAILABLE 0) target_compile_definitions(base INTERFACE
# TATOOINE_NETCDF_AVAILABLE=0)
# #update_git_submodule(${TATOOINE_EXTERNAL}/netcdf-c)
# #update_git_submodule(${TATOOINE_EXTERNAL}/netcdf-cxx4)
# #add_subdirectory(external/netcdf-c EXCLUDE_FROM_ALL)
# #add_subdirectory(external/netcdf-cxx4 EXCLUDE_FROM_ALL)
endif()
# ----------------------------------------------------------------------------
# GINAC
# ----------------------------------------------------------------------------
# find_package(GINAC QUIET) if (${GINAC_FOUND}) option(TATOOINE_USE_GINAC "use
# GiNaC for symbolics support" FALSE) if (${TATOOINE_USE_GINAC})
# set(TATOOINE_GINAC_AVAILABLE 1) target_include_directories(base INTERFACE
# ${GINAC_INCLUDE_DIR}) target_link_libraries(base INTERFACE ${GINAC_LIBRARY})
# else() set(TATOOINE_GINAC_AVAILABLE 0) endif() else()
set(TATOOINE_GINAC_AVAILABLE 0)
# endif()
get_target_property(defs base COMPILE_DEFINITIONS)
list(REMOVE_ITEM defs _FORTIFY_SOURCE)
set_property(TARGET base PROPERTY COMPILE_DEFINITIONS ${defs})
# ----------------------------------------------------------------------------
# Subdirectories
# ----------------------------------------------------------------------------
add_subdirectory(preprocessor)
target_link_libraries(base INTERFACE preprocessor)
add_subdirectory(multidim_array)
add_subdirectory(tensor)
add_subdirectory(geometry)
add_subdirectory(fields)
if(TATOOINE_MPI_AVAILABLE)
add_subdirectory(mpi)
add_subdirectory(insitu)
endif()
add_subdirectory(gl)
add_subdirectory(rendering)
option(TATOOINE_BUILD_TESTS "" OFF)
if(TATOOINE_BUILD_TESTS)
add_subdirectory(test)
endif()
option(TATOOINE_BUILD_BENCHMARKS "" OFF)
if(TATOOINE_BUILD_BENCHMARKS)
add_subdirectory(benchmarks EXCLUDE_FROM_ALL)
endif()
option(TATOOINE_BUILD_EXAMPLES "" OFF)
if(TATOOINE_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# ----------------------------------------------------------------------------
configure_file(${CMAKE_SOURCE_DIR}/tatooineConfig.cmake.in
${CMAKE_BINARY_DIR}/tatooineConfig.cmake @ONLY)
export(
TARGETS base
geometry
multidim_array
tensor
preprocessor
fields
rapidxml
APPEND
FILE "${CMAKE_BINARY_DIR}/tatooineConfig.cmake"
NAMESPACE tatooine::)
if(TATOOINE_GL_AVAILABLE)
export(
TARGETS gl glfw imgui imgui-filebrowser glad
APPEND
FILE "${CMAKE_BINARY_DIR}/tatooineConfig.cmake"
NAMESPACE tatooine::)
endif()
export(
TARGETS rendering
APPEND
FILE "${CMAKE_BINARY_DIR}/tatooineConfig.cmake"
NAMESPACE tatooine::)
if(TATOOINE_CDT_AVAILABLE)
export(
TARGETS CDT
APPEND
FILE "${CMAKE_BINARY_DIR}/tatooineConfig.cmake"
NAMESPACE tatooine::)
endif()
export(PACKAGE tatooine)
endif()
# ------------------------------------------------------------------------------
# configure files
# ------------------------------------------------------------------------------
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/include/tatooine/available_libraries.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/include/tatooine/available_libraries.h")