-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
588 lines (501 loc) · 16.5 KB
/
CMakeLists.txt
File metadata and controls
588 lines (501 loc) · 16.5 KB
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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
##
# CMake for the PRISMS-PF core library
##
# =========================================================
# CMake setup & loading functions
# =========================================================
# CMake config
message(STATUS "Using CMake ${CMAKE_VERSION}")
cmake_minimum_required(VERSION 3.25)
cmake_policy(VERSION 3.25)
# Prohibit in-source build
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "In-source build prohibited.")
endif()
# Project declaration, language, and version
project(prisms_pf LANGUAGES CXX VERSION 4.0.0)
# Export compile command for IDE lsp support
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Set the location of additional CMake modules
set(
CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${PROJECT_SOURCE_DIR}/cmake
${PROJECT_SOURCE_DIR}/cmake/functions
)
include(prisms_pf_cmake_functions)
# =========================================================
# Configuration setup
# =========================================================
set(PRISMS_PF_VERSION ${PROJECT_VERSION})
version_decomposition(${PRISMS_PF_VERSION})
print_subsection("Configuring PRISMS-PF v${PRISMS_PF_VERSION}")
prisms_pf_git_version()
print_variables(
""
PRISMS_PF_GIT_BRANCH
PRISMS_PF_GIT_TAG
PRISMS_PF_GIT_REVISION
PRISMS_PF_GIT_SHORTREV
PRISMS_PF_GIT_TIMESTAMP
""
)
# TODO: Refactor this somewhere else
# Configuration options
option(PRISMS_PF_AUTODETECTION "Autodetection of PRISMS-PF dependencies." ON)
option(PRISMS_PF_UNIT_TESTS "Whether to build the unit tests or not." OFF)
option(PRISMS_PF_REGRESSION_TESTS "Whether to build the regression tests or not." OFF)
option(PRISMS_PF_PERFORMANCE_TESTS "Whether to build the performance tests or not." OFF)
option(PRISMS_PF_EXAMPLES "Whether to build examples or not." OFF)
option(PRISMS_PF_DOCS "Whether to build documentation or not." OFF)
option(PRISMS_PF_CLANG_TIDY "Whether to run clang-tidy during the build stage." OFF)
# NOTE: This relies on the fact that deal.II is also compiled with 64-bit indices
option(PRISMS_PF_64BIT_INDICES "Whether to use 64-bit indices for large simulations" OFF)
# NOTE: This can only go higher than 6 if deal.II is compiled with >6 for the element degree.
option(PRISMS_PF_ADDITIONAL_DEGREES "Whether to compile with element degrees of 3+." OFF)
# NOTE: When on deal.II will try to use the max number of threads with respect to the number
# of MPI processes.
option(PRISMS_PF_THREADS "Whether to use threading." ON)
option(PRISMS_PF_GPU "Whether to use GPU backends" OFF)
if(PRISMS_PF_GPU)
message(WARNING "GPU backends are still under development")
endif()
option(
PRISMS_PF_WITH_VTK
"Whether the user wants to compile PRISMS-PF with vtk, or not"
OFF
)
option(
PRISMS_PF_WITH_HDF5
"Whether the user wants to compile PRISMS-PF with HDF5, or not"
OFF
)
option(
PRISMS_PF_WITH_CALIPER
"Whether the user wants to compile PRISMS-PF with the profiling code Caliper, or not."
OFF
)
print_variables(
""
PRISMS_PF_AUTODETECTION
""
PRISMS_PF_UNIT_TESTS
PRISMS_PF_REGRESSION_TESTS
PRISMS_PF_PERFORMANCE_TESTS
PRISMS_PF_EXAMPLES
""
PRISMS_PF_64BIT_INDICES
PRISMS_PF_ADDITIONAL_DEGREES
PRISMS_PF_THREADS
""
PRISMS_PF_WITH_VTK
PRISMS_PF_WITH_CALIPER
""
)
if(PRISMS_PF_CLANG_TIDY)
# NOTE: I've tested clang-tidy-18 and found that it fails. clang-tidy-20 works.
find_program(
CLANG_TIDY_TOOL
NAMES
clang-tidy
clang-tidy-20
clang-tidy-19
)
execute_process(
COMMAND
${CLANG_TIDY_TOOL} --version
OUTPUT_VARIABLE CLANG_TIDY_TOOL_VERSION
ERROR_VARIABLE CLANG_TIDY_TOOL_VERSION
)
string(
REGEX MATCH
"[0-9]+(\\.[0-9]+)+"
CLANG_TIDY_TOOL_VERSION
"${CLANG_TIDY_TOOL_VERSION}"
)
message(STATUS "clang-tidy ${CLANG_TIDY_TOOL_VERSION} (${CLANG_TIDY_TOOL})")
# NOTE: To avoid linting on the vendored source files we set CXX_CLANG_TIDY
# as a property of our targets
endif()
# =========================================================
# Find dependencies
# =========================================================
print_subsection("Configuring external libraries")
# First, vendored dependencies
include(FetchContent)
FetchContent_Declare(
libassert
GIT_REPOSITORY https://github.com/jeremy-rifkin/libassert.git
GIT_TAG v2.2.1
SYSTEM
)
if(PRISMS_PF_UNIT_TESTS)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.13.0
SYSTEM
)
endif()
# TODO: Refactor this
# Find MPI
# TODO: We should see if there's a minimum version we need to specify
find_package(MPI REQUIRED COMPONENTS CXX)
if(NOT MPI_CXX_FOUND)
message(
FATAL_ERROR
"MPI CXX component not found. Please make sure your MPI installation includes C++ support."
)
endif()
if(NOT MPI_CXX_COMPILER)
message(
FATAL_ERROR
"MPI CXX compiler wrapper not found. Please make sure you have `mpicxx`"
)
endif()
# Find the MPI CXX version if not already populated
if(NOT MPI_CXX_VERSION)
file(READ "${MPI_CXX_INCLUDE_DIRS}/mpi.h" _mpi_header_content)
string(REGEX MATCH "#define MPI_MAJOR_VERSION ([0-9]+)" _ "${_mpi_header_content}")
set(_mpi_major ${CMAKE_MATCH_1})
string(REGEX MATCH "#define MPI_MINOR_VERSION ([0-9]+)" _ "${_mpi_header_content}")
set(_mpi_major ${CMAKE_MATCH_1})
set(MPI_CXX_VERSION "${_mpi_major}.${_mpi_minor}")
endif()
# TODO: Refactor this
# Once we've found MPI, we need to find deal.II. Since deal.II likes to do things
# a little differently, provide some directory hints.
find_package(
deal.II
9.6.0
REQUIRED
HINTS
${DEAL_II_DIR}
$ENV{DEAL_II_DIR}
)
# Print some information about deal.II configuration
print_variables(
""
DEAL_II_VERSION
DEAL_II_BUILD_TYPE
DEAL_II_CXX_COMPILER
DEAL_II_C_COMPILER
""
DEAL_II_WITH_THREADS
DEAL_II_WITH_64BIT_INDICES
DEAL_II_WITH_BOOST
DEAL_II_BOOST_VERSION
DEAL_II_WITH_KOKKOS
DEAL_II_KOKKOS_VERSION
DEAL_II_FEATURE_KOKKOS_BUNDLED_CONFIGURED
DEAL_II_WITH_LAPACK
DEAL_II_LAPACK_WITH_MKL
DEAL_II_WITH_MPI
DEAL_II_MPI_VERSION
DEAL_II_WITH_P4EST
DEAL_II_P4EST_VERSION
DEAL_II_P4EST_WITH_VTK_BINARY
DEAL_II_WITH_TASKFLOW
DEAL_II_TASKFLOW_VERSION
DEAL_II_FEATURE_TASKFLOW_BUNDLED_CONFIGURED
DEAL_II_WITH_TBB
DEAL_II_WITH_VTK
DEAL_II_WITH_ZLIB
DEAL_II_ZLIB_VERSION
""
DEAL_II_CXX_FLAGS
DEAL_II_CXX_FLAGS_DEBUG
DEAL_II_CXX_FLAGS_RELEASE
""
DEAL_II_WARNING_FLAGS
""
DEAL_II_LINKER_FLAGS
DEAL_II_LINKER_FLAGS_DEBUG
DEAL_II_LINKER_FLAGS_RELEASE
""
)
# TODO: Don't rely on deal.II do stuff ourselves
function(strip_dealii_flags input output)
string(REGEX REPLACE "-O[0-9s]|-std=[^ ]+" "" stripped "${input}")
string(STRIP "${stripped}" stripped)
set(${output} "${stripped}" PARENT_SCOPE)
endfunction()
strip_dealii_flags("${DEAL_II_CXX_FLAGS}" DEAL_II_CXX_FLAGS)
strip_dealii_flags("${DEAL_II_CXX_FLAGS_DEBUG}" DEAL_II_CXX_FLAGS_DEBUG)
strip_dealii_flags("${DEAL_II_CXX_FLAGS_RELEASE}" DEAL_II_CXX_FLAGS_RELEASE)
# TODO: Fix this so it prints with meaningful variable names
print_variables(
DEAL_II_CXX_FLAGS
DEAL_II_CXX_FLAGS_DEBUG
DEAL_II_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
)
# Check the deal.II was built with the right dependencies
if(NOT DEAL_II_WITH_MPI)
message(FATAL_ERROR "deal.II was not built with MPI support!")
endif()
if(NOT DEAL_II_WITH_LAPACK)
message(FATAL_ERROR "deal.II was not built with LAPACK support!")
endif()
if(NOT DEAL_II_WITH_ZLIB)
message(FATAL_ERROR "deal.II was not built with zlib support!")
endif()
if(NOT DEAL_II_WITH_P4EST)
message(FATAL_ERROR "deal.II was not built with p4est support!")
endif()
# Check that deal.II links against the same MPI that we find earlier.
get_target_property(DEAL_II_MPI_LIBS dealii::interface_mpi INTERFACE_LINK_LIBRARIES)
get_target_property(PRISMS_PF_MPI_LIBS MPI::MPI_CXX INTERFACE_LINK_LIBRARIES)
if(NOT DEAL_II_MPI_LIBS STREQUAL PRISMS_PF_MPI_LIBS)
message(
WARNING
"deal.II MPI libraries: ${DEAL_II_MPI_LIBS}\n"
"Found MPI libraries: ${PRISMS_PF_MPI_LIBS}\n"
"These do not match! This may cause runtime issues."
)
endif()
# Check that deal.II has the same width indices as PRISMS-PF
if(NOT DEAL_II_WITH_64BIT_INDICES STREQUAL PRISMS_PF_64BIT_INDICES)
message(
FATAL_ERROR
"PRISMS-PF and deal.II must both use the same index width. You have:\n"
" PRISMS_PF_64BIT_INDICES = ${PRISMS_PF_64BIT_INDICES}\n"
" DEAL_II_WITH_64BIT_INDICES = ${DEAL_II_WITH_64BIT_INDICES}\n"
)
endif()
# Find Caliper if we've enabled it
if(PRISMS_PF_WITH_CALIPER)
find_package(
caliper
REQUIRED
HINTS
${CALIPER_DIR}
$ENV{CALIPER_DIR}
)
endif()
# TODO: Add VTK
# FetchCotent MakeAvailable for the other vendored dependencies
set(PRISMS_PF_VENDORED_PACKAGES libassert)
if(PRISMS_PF_UNIT_TESTS OR PRISMS_PF_REGRESSION_TESTS OR PRISMS_PF_PERFORMANCE_TESTS)
list(APPEND PRISMS_PF_VENDORED_PACKAGES Catch2)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "DebugRelease")
# If we have DebugRelease as the build type, we want to build
# libassert with Debug and Release targets to link to later
include(ExternalProject)
# Populate libassert so we can get the source directory
FetchContent_Populate(libassert)
# External projects for the debug and release libassert targets
ExternalProject_Add(
libassert_debug
SOURCE_DIR ${libassert_SOURCE_DIR}
PREFIX ${CMAKE_BINARY_DIR}/_deps/libassert-debug
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
INSTALL_DIR ${CMAKE_BINARY_DIR}/_deps/libassert-debug/install
)
ExternalProject_Add(
libassert_release
SOURCE_DIR ${libassert_SOURCE_DIR}
PREFIX ${CMAKE_BINARY_DIR}/_deps/libassert-release
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
INSTALL_DIR ${CMAKE_BINARY_DIR}/_deps/libassert-release/install
)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/_deps/libassert-debug/install/include)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/_deps/libassert-release/install/include)
add_library(libassert_imported INTERFACE IMPORTED GLOBAL)
add_dependencies(
libassert_imported
libassert_debug
libassert_release
)
set_property(
TARGET
libassert_imported
PROPERTY
INTERFACE_LINK_LIBRARIES
"$<$<CONFIG:Debug>:${CMAKE_BINARY_DIR}/_deps/libassert-debug/install/lib/libassert.a>"
"$<$<CONFIG:Release>:${CMAKE_BINARY_DIR}/_deps/libassert-release/install/lib/libassert.a>"
)
set_property(
TARGET
libassert_imported
PROPERTY
INTERFACE_INCLUDE_DIRECTORIES
"${CMAKE_BINARY_DIR}/_deps/libassert-debug/install/include"
"${CMAKE_BINARY_DIR}/_deps/libassert-release/install/include"
)
add_library(libassert::assert ALIAS libassert_imported)
# Still make available other vendored packages (e.g. Catch2)
list(REMOVE_ITEM PRISMS_PF_VENDORED_PACKAGES libassert)
FetchContent_MakeAvailable(${PRISMS_PF_VENDORED_PACKAGES})
else()
FetchContent_MakeAvailable(${PRISMS_PF_VENDORED_PACKAGES})
endif()
# =========================================================
# Configure targets
# =========================================================
print_subsection("Configuring build targets")
# TODO: Add status messages here
# Configure the config file
configure_file(include/prismspf/config.h.in include/prismspf/config.h @ONLY)
# Configure the template inst file and add the code generator script
add_subdirectory(cmake/scripts)
if(PRISMS_PF_ADDITIONAL_DEGREES)
set(_additional_degrees "; 3; 4; 5; 6")
else()
set(_additional_degrees "")
endif()
configure_file(cmake/templates.in cmake/templates @ONLY)
if(CMAKE_BUILD_TYPE STREQUAL "DebugRelease")
add_library(prisms_pf_debug)
add_library(prisms_pf_release)
prisms_pf_configure_target(prisms_pf_debug "Debug")
prisms_pf_configure_target(prisms_pf_release "Release")
add_library(prisms_pf::prisms_pf_debug ALIAS prisms_pf_debug)
add_library(prisms_pf::prisms_pf_release ALIAS prisms_pf_release)
set(
PRISMS_PF_TARGETS
prisms_pf_debug
prisms_pf_release
)
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_library(prisms_pf_debug)
prisms_pf_configure_target(prisms_pf_debug "Debug")
add_library(prisms_pf::prisms_pf ALIAS prisms_pf_debug)
add_library(prisms_pf::prisms_pf_debug ALIAS prisms_pf_debug)
set(PRISMS_PF_TARGETS prisms_pf_debug)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
add_library(prisms_pf_release)
prisms_pf_configure_target(prisms_pf_release "Release")
add_library(prisms_pf::prisms_pf ALIAS prisms_pf_release)
add_library(prisms_pf::prisms_pf_release ALIAS prisms_pf_release)
set(PRISMS_PF_TARGETS prisms_pf_release)
endif()
add_subdirectory(src)
# =========================================================
# Installation
# =========================================================
print_subsection("Configuring installation targets")
# TODO: Add status messages here
include(GNUInstallDirs)
install(
TARGETS
${PRISMS_PF_TARGETS}
EXPORT prisms_pf_targets
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
FILE_SET HEADERS
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# Install the generated config.h separately since it's in the build tree
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/include/prismspf/config.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/prismspf
)
# Export the targets file so downstream can use find_package(PRISMS-PF)
install(
EXPORT prisms_pf_targets
FILE prisms_pf_targets.cmake
NAMESPACE PRISMS-PF::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PRISMS-PF
)
# Generate and install the config file for find_package support
include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/PRISMS-PFConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/PRISMS-PFConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PRISMS-PF
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/cmake/PRISMS-PFConfigVersion.cmake
VERSION ${PRISMS_PF_VERSION}
COMPATIBILITY SameMinorVersion
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/cmake/PRISMS-PFConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/PRISMS-PFConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PRISMS-PF
)
# Install executable utilities
install(
PROGRAMS
${CMAKE_SOURCE_DIR}/contrib/postprocessing/visualize2D
DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# =========================================================
# Build exports (find_package with build dir)
# =========================================================
print_subsection("Configuring build-tree export")
export(
TARGETS
${PRISMS_PF_TARGETS}
NAMESPACE PRISMS-PF::
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/prisms_pf_targets.cmake"
)
# =========================================================
# Examples
# =========================================================
print_subsection("Configuring PRISMS-PF examples")
# TODO: Add status messages here
if(PRISMS_PF_EXAMPLES)
add_subdirectory(applications)
endif()
# =========================================================
# Testing
# =========================================================
print_subsection("Configuring PRISMS-PF tests")
# TODO: Add status messages here
if(PRISMS_PF_UNIT_TESTS OR PRISMS_PF_REGRESSION_TESTS OR PRISMS_PF_PERFORMANCE_TESTS)
enable_testing()
endif()
if(PRISMS_PF_UNIT_TESTS)
add_subdirectory(tests/unit)
endif()
if(PRISMS_PF_REGRESSION_TESTS)
#add_subdirectory(tests/regression)
endif()
if(PRISMS_PF_PERFORMANCE_TESTS)
#add_subdirectory(tests/performance)
endif()
# =========================================================
# Documentation
# =========================================================
if(PRISMS_PF_DOCS)
print_subsection("Configuring PRISMS-PF documentation")
find_package(Doxygen REQUIRED)
# Path of Doxyfile and its output
set(DOXYGEN_INPUT ${CMAKE_SOURCE_DIR}/doc/doxygen/Doxyfile)
set(DOXYGEN_OUTPUT ${CMAKE_BINARY_DIR}/doc/doxygen/Doxyfile.out)
# The directory where the documentation will be generated
set(DOXYGEN_HTML_OUTPUT "${PRISMS_PF_VERSION}")
set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/doc)
# Copy input to output
configure_file(${DOXYGEN_INPUT} ${DOXYGEN_OUTPUT} @ONLY)
# Add target to generate documentation
doxygen_add_docs(
doc
COMMENT "Generating Doxygen documentation"
CONFIG_FILE ${DOXYGEN_OUTPUT}
ALL
)
message(
STATUS
"Doxygen documentation will be generated using:\n"
" ${DOXYGEN_INPUT}\n"
" and output to:\n"
" ${DOXYGEN_OUTPUT_DIRECTORY}/${DOXYGEN_HTML_OUTPUT}\n"
)
endif()
# =========================================================
# Final steps to print some nice messages
# =========================================================