Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DLR-AMR
GitHub Repository: DLR-AMR/t8code
Path: blob/main/CMakeLists.txt
501 views
1
# This file is part of t8code.
2
# t8code is a C library to manage a collection (a forest) of multiple
3
# connected adaptive space-trees of general element types in parallel.
4
#
5
# Copyright (C) 2025 the developers
6
#
7
# t8code is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
11
#
12
# t8code is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with t8code; if not, write to the Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21
cmake_minimum_required( VERSION 3.16 )
22
23
include( cmake/GitProjectVersion.cmake )
24
25
project(
26
T8CODE
27
DESCRIPTION "Parallel algorithms and data structures for tree-based AMR with arbitrary element shapes."
28
LANGUAGES C CXX
29
VERSION "${T8CODE_VERSION_MAJOR}.${T8CODE_VERSION_MINOR}.${T8CODE_VERSION_PATCH}"
30
)
31
32
include( GNUInstallDirs)
33
include( CTest )
34
include( CMakeDependentOption )
35
36
option( T8CODE_BUILD_AS_SHARED_LIBRARY "Whether t8code should be built as a shared or a static library" ON )
37
option( T8CODE_BUILD_PEDANTIC "Compile t8code with `-pedantic` as done in the Github CI." OFF )
38
option( T8CODE_BUILD_WALL "Compile t8code with `-Wall` as done in the Github CI." OFF )
39
option( T8CODE_BUILD_WERROR "Compile t8code with `-Werror` as done in the Github CI." OFF )
40
option( T8CODE_BUILD_WEXTRA "Compile t8code with extra warnings as done in the Github CI." OFF )
41
option( T8CODE_EXPORT_COMPILE_COMMANDS "Export the compile commands as json. Can be used by IDEs for code completion (e.g. intellisense, clangd)" OFF )
42
43
option( T8CODE_BUILD_TESTS "Build t8code's automated tests" ON )
44
cmake_dependent_option( T8CODE_BUILD_TPL_TESTS "Build the tests from libsc and p4est" OFF "T8CODE_BUILD_TESTS" OFF )
45
46
option( T8CODE_BUILD_EXAMPLES "Build t8code's examples" ON )
47
cmake_dependent_option( T8CODE_BUILD_TPL_EXAMPLES "Build the examples from libsc and p4est" OFF "T8CODE_BUILD_EXAMPLES" OFF )
48
49
option( T8CODE_BUILD_TUTORIALS "Build t8code's tutorials" ON )
50
option( T8CODE_BUILD_BENCHMARKS "Build t8code's benchmarks" ON )
51
option( T8CODE_BUILD_FORTRAN_INTERFACE "Build t8code's Fortran interface" OFF )
52
53
option( T8CODE_ENABLE_MPI "Enable t8code's features which rely on MPI" ON )
54
option( T8CODE_ENABLE_VTK "Enable t8code's features which rely on VTK" OFF )
55
option( T8CODE_ENABLE_OCC "Enable t8code's features which rely on OpenCASCADE" OFF )
56
option( T8CODE_ENABLE_NETCDF "Enable t8code's features which rely on netCDF" OFF )
57
58
option( T8CODE_USE_SYSTEM_SC "Use system-installed sc library" OFF )
59
option( T8CODE_USE_SYSTEM_P4EST "Use system-installed p4est library" OFF )
60
61
option( T8CODE_BUILD_DOCUMENTATION "Build t8code's documentation" OFF )
62
cmake_dependent_option( T8CODE_BUILD_DOCUMENTATION_SPHINX "Build t8code's documentation using sphinx" OFF "T8CODE_BUILD_DOCUMENTATION" OFF )
63
64
set(T8CODE_CUSTOM_PARALLEL_TEST_COMMAND "" CACHE STRING "Define a custom command for parallel tests , e.g.: mpirun -np 8 (overwrites standard mpirun -np 4 if build with mpi)")
65
set(T8CODE_CUSTOM_SERIAL_TEST_COMMAND "" CACHE STRING "Define a custom command for serial tests.")
66
67
# Reading the option T8CODE_TEST_LEVEL: Possible choices are T8_TEST_LEVEL_FULL, T8_TEST_LEVEL_MEDIUM, or T8_TEST_LEVEL_BASIC. Default is T8_TEST_LEVEL_FULL.
68
set(T8CODE_TEST_LEVEL "T8_TEST_LEVEL_FULL" CACHE STRING "Test level: T8_TEST_LEVEL_FULL for full tests, T8_TEST_LEVEL_MEDIUM for less thorough tests, T8_TEST_LEVEL_BASIC for minimal tests. (WARNING: Use with care.)")
69
set_property(CACHE T8CODE_TEST_LEVEL PROPERTY STRINGS "T8_TEST_LEVEL_FULL" "T8_TEST_LEVEL_MEDIUM" "T8_TEST_LEVEL_BASIC")
70
71
# Parse string T8CODE_TEST_LEVEL into integer T8_TEST_LEVEL_INT for easier usage within the code.
72
if(T8CODE_TEST_LEVEL STREQUAL "T8_TEST_LEVEL_BASIC" )
73
set(T8_TEST_LEVEL_INT 2)
74
elseif(T8CODE_TEST_LEVEL STREQUAL "T8_TEST_LEVEL_MEDIUM" )
75
set(T8_TEST_LEVEL_INT 1)
76
elseif(T8CODE_TEST_LEVEL STREQUAL "T8_TEST_LEVEL_FULL" )
77
set(T8_TEST_LEVEL_INT 0)
78
else()
79
message( FATAL_ERROR "Invalid string for T8CODE_TEST_LEVEL: ${T8CODE_TEST_LEVEL}. Valid options are T8_TEST_LEVEL_FULL, T8_TEST_LEVEL_MEDIUM, or T8_TEST_LEVEL_BASIC.")
80
endif()
81
82
# Set a default build type if none was specified
83
set(default_build_type "Release")
84
85
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
86
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
87
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
88
STRING "Choose the type of build. Build types available: Release Debug RelWithDebInfo" FORCE)
89
# Set the possible values of build type for cmake-gui
90
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
91
"Debug" "Release" "RelWithDebInfo")
92
endif()
93
94
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
95
96
if( T8CODE_BUILD_FORTRAN_INTERFACE )
97
enable_language( Fortran )
98
endif()
99
100
if( T8CODE_ENABLE_MPI )
101
if( T8CODE_BUILD_FORTRAN_INTERFACE )
102
find_package( MPI COMPONENTS C Fortran REQUIRED )
103
else()
104
find_package( MPI COMPONENTS C REQUIRED )
105
endif()
106
107
if( NOT MPIEXEC_EXECUTABLE )
108
message( FATAL_ERROR "MPIEXEC was not found" )
109
endif()
110
set( SC_ENABLE_MPI ON )
111
endif()
112
113
if( T8CODE_ENABLE_VTK )
114
find_package( VTK REQUIRED COMPONENTS
115
IOXML CommonExecutionModel CommonDataModel
116
IOGeometry IOXMLParser IOParallelXML IOPLY
117
ParallelMPI FiltersCore vtksys CommonCore zlib IOLegacy)
118
if(VTK_FOUND)
119
message("Found VTK")
120
endif (VTK_FOUND)
121
endif( T8CODE_ENABLE_VTK )
122
123
if( T8CODE_ENABLE_OCC )
124
find_package( OpenCASCADE REQUIRED COMPONENTS
125
TKBO TKPrim TKTopAlgo
126
TKGeomAlgo TKBRep
127
TKG3d TKG2d TKMath TKernel )
128
if(OpenCASCADE_FOUND)
129
message("Found OpenCASCADE")
130
endif (OpenCASCADE_FOUND)
131
endif( T8CODE_ENABLE_OCC )
132
133
if( T8CODE_ENABLE_NETCDF )
134
find_package( NetCDF REQUIRED )
135
if(NetCDF_FOUND)
136
message("Found NetCDF")
137
include(cmake/CheckNetCDFPar.cmake)
138
endif (NetCDF_FOUND)
139
endif( T8CODE_ENABLE_NETCDF )
140
141
# Override default for this libsc option
142
set( BUILD_SHARED_LIBS ON CACHE BOOL "Build libsc as a shared library" )
143
144
# Prevent `libsc` and `p4est` from overwriting the default install prefix.
145
set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT FALSE)
146
147
# Rpath options necessary for shared library install to work correctly in user projects.
148
# Compute the relative Rpath for proper library installation
149
set(libPath ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) # Library directory)
150
cmake_path(RELATIVE_PATH libPath
151
BASE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR} # Binary directory
152
OUTPUT_VARIABLE relativeRpath
153
)
154
set(CMAKE_INSTALL_RPATH $ORIGIN $ORIGIN/${relativeRpath})
155
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH true)
156
157
if ( T8CODE_USE_SYSTEM_SC )
158
find_package( SC REQUIRED )
159
else()
160
set( SC_BUILD_EXAMPLES ${T8CODE_BUILD_TPL_EXAMPLES} )
161
set( SC_BUILD_TESTING ${T8CODE_BUILD_TPL_TESTS} )
162
163
# Capture the list of variables before adding the subdirectory to mark the added ones as advanced.
164
get_cmake_property(_vars_before_sc VARIABLES )
165
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/sc )
166
add_library(SC INTERFACE)
167
# Capture the list of variables after adding the subdirectory
168
get_cmake_property(_vars_after_sc VARIABLES )
169
# Compute the difference (new variables added by the subdirectory)
170
set( _new_sc_vars)
171
foreach( _var IN LISTS _vars_after_sc )
172
if( NOT _var IN_LIST _vars_before_sc )
173
list( APPEND _new_sc_vars ${_var} )
174
endif()
175
endforeach()
176
177
# Mark the new variables as advanced
178
mark_as_advanced( FORCE ${_new_sc_vars} )
179
180
########################## Fix for OpenMPI ############################################
181
# OpenMPI sometimes has a mismatch between their C and CXX interface which produces a warning in SC.
182
# The warning makes t8codes build fail when Werror is activated. This fix checks if t8code
183
# is linked against OpenMPI and then suppresses that Werror treats this warning as error.
184
# The warning is still displayed while compiling.
185
# We compile a test program mich checks if a OpenMPI specific macro is defined and then apply the fix.
186
187
include(CheckIncludeFile)
188
189
# Check if mpi.h is available
190
check_include_file("mpi.h" MPI_HEADER_FOUND)
191
192
if(MPI_HEADER_FOUND)
193
# Create a temporary C++ source file to check for OpenMPI-specific macros
194
include(CheckCXXSourceCompiles)
195
check_cxx_source_compiles("
196
#include <mpi.h>
197
#ifndef OPEN_MPI
198
#error 'Not OpenMPI'
199
#endif
200
int main() { return 0; }" HAS_OPENMPI)
201
202
if(HAS_OPENMPI)
203
message(STATUS "OpenMPI detected via mpi.h")
204
# Suppress warning
205
target_compile_options(SC::SC INTERFACE -Wno-error=cast-function-type)
206
endif()
207
else()
208
message(WARNING "mpi.h not found!")
209
endif()
210
########################## End of fix for OpenMPI ############################################
211
endif()
212
213
if ( T8CODE_USE_SYSTEM_P4EST )
214
find_package( P4EST REQUIRED )
215
else()
216
set( P4EST_BUILD_EXAMPLES ${T8CODE_BUILD_TPL_EXAMPLES} )
217
set( P4EST_BUILD_TESTING ${T8CODE_BUILD_TPL_TESTS} )
218
219
# Capture the list of variables before adding the subdirectory to mark the added ones as advanced.
220
get_cmake_property( _vars_before_p4est VARIABLES )
221
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/p4est )
222
# Capture the list of variables after adding the subdirectory
223
get_cmake_property( _vars_after_p4est VARIABLES )
224
# Compute the difference (new variables added by the subdirectory)
225
set( _new_p4est_vars )
226
foreach( _var IN LISTS _vars_after_p4est )
227
if( NOT _var IN_LIST _vars_before_p4est )
228
list( APPEND _new_p4est_vars ${_var} )
229
endif()
230
endforeach()
231
232
# Mark the new variables as advanced
233
mark_as_advanced( FORCE ${_new_p4est_vars} )
234
endif()
235
236
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/src )
237
238
if ( T8CODE_BUILD_TESTS )
239
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/test )
240
endif()
241
242
if ( T8CODE_BUILD_TUTORIALS )
243
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/tutorials )
244
endif()
245
246
if ( T8CODE_BUILD_EXAMPLES )
247
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/example )
248
endif()
249
250
if ( T8CODE_BUILD_BENCHMARKS )
251
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/benchmarks )
252
endif()
253
254
if ( T8CODE_BUILD_DOCUMENTATION )
255
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/doc )
256
endif()
257
258
if( T8CODE_BUILD_FORTRAN_INTERFACE )
259
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/api/t8_fortran_interface )
260
261
if( NOT T8CODE_ENABLE_MPI )
262
message( FATAL_ERROR "Fortran API only available when MPI is enabled." )
263
endif()
264
endif()
265
266
include (cmake/CPackConfig.cmake)
267
268