Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DLR-AMR
GitHub Repository: DLR-AMR/t8code
Path: blob/main/src/CMakeLists.txt
898 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
if ( T8CODE_BUILD_AS_SHARED_LIBRARY )
22
add_library( T8 SHARED )
23
set_target_properties( T8 PROPERTIES VERSION ${T8CODE_VERSION_MAJOR}.${T8CODE_VERSION_MINOR}.${T8CODE_VERSION_PATCH} SOVERSION ${T8CODE_VERSION_RAW})
24
set_target_properties( T8 PROPERTIES POSITION_INDEPENDENT_CODE ON )
25
else()
26
add_library( T8 STATIC )
27
endif()
28
29
target_compile_features( T8 PUBLIC c_std_11 cxx_std_20 )
30
add_library( T8CODE::T8 ALIAS T8 )
31
target_compile_definitions( T8 PUBLIC T8_TEST_LEVEL_INT=${T8_TEST_LEVEL_INT})
32
33
if( CMAKE_BUILD_TYPE STREQUAL "Release" )
34
set (T8_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
35
set (T8_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}")
36
endif()
37
38
if( CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
39
set (T8_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
40
set (T8_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
41
endif()
42
43
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
44
set (T8_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
45
set (T8_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}")
46
47
target_compile_definitions( T8 PUBLIC T8_ENABLE_DEBUG=1 )
48
endif()
49
50
if( T8CODE_EXPORT_COMPILE_COMMANDS )
51
set_target_properties( T8 PROPERTIES EXPORT_COMPILE_COMMANDS ON )
52
endif( T8CODE_EXPORT_COMPILE_COMMANDS )
53
54
set_target_properties( T8 PROPERTIES OUTPUT_NAME t8 )
55
56
target_include_directories( T8 PUBLIC
57
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
58
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>
59
)
60
61
target_link_libraries( T8 PUBLIC P4EST::P4EST SC::SC )
62
63
if ( T8CODE_ENABLE_MPI )
64
target_compile_definitions( T8 PUBLIC T8_ENABLE_MPI=1 )
65
target_compile_definitions( T8 PUBLIC T8_ENABLE_MPIIO=1 )
66
target_link_libraries( T8 PUBLIC MPI::MPI_C )
67
endif()
68
69
if( T8CODE_ENABLE_VTK )
70
set (T8CODE_VTK_VERSION_USED "${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}")
71
# Define T8_VTK_VERSION_USED for internal and external use in source files.
72
# Note, external libraries linking against t8code (i.e. using find_package ( T8CODE REQUIRED )) can
73
# use T8_VTK_VERSION_USED in source code and T8CODE_VTK_VERSION_USED (defined in config.cmake.in) in their CMake scripts.
74
target_compile_definitions( T8 PUBLIC T8_VTK_VERSION_USED="${T8CODE_VTK_VERSION_USED}" )
75
target_compile_definitions( T8 PUBLIC T8_ENABLE_VTK=1 )
76
target_include_directories( T8 PUBLIC ${VTK_INCLUDE_DIR} )
77
target_link_libraries( T8 PUBLIC ${VTK_LIBRARIES} )
78
target_sources(T8 PRIVATE
79
t8_vtk/t8_with_vtk/t8_vtk_parallel.cxx
80
t8_vtk/t8_with_vtk/t8_vtk_polydata.cxx
81
t8_vtk/t8_with_vtk/t8_vtk_unstructured.cxx
82
t8_vtk/t8_with_vtk/t8_vtk_reader.cxx
83
)
84
install( FILES
85
t8_vtk/t8_with_vtk/t8_vtk_parallel.hxx
86
t8_vtk/t8_with_vtk/t8_vtk_polydata.hxx
87
t8_vtk/t8_with_vtk/t8_vtk_unstructured.hxx
88
t8_vtk/t8_with_vtk/t8_vtk_reader.hxx
89
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/t8_vtk/t8_with_vtk
90
)
91
endif()
92
93
if( T8CODE_ENABLE_OCC )
94
target_compile_definitions( T8 PUBLIC T8_ENABLE_OCC=1 )
95
target_include_directories( T8 SYSTEM PUBLIC ${OpenCASCADE_INCLUDE_DIR} )
96
target_link_libraries( T8 PUBLIC ${OpenCASCADE_LIBRARIES} )
97
target_sources(T8 PRIVATE
98
t8_geometry/t8_geometry_implementations/t8_geometry_cad.cxx
99
t8_cad/t8_cad.cxx
100
)
101
install( FILES
102
t8_geometry/t8_geometry_implementations/t8_geometry_cad.hxx
103
t8_geometry/t8_geometry_implementations/t8_geometry_cad.h
104
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/t8_geometry/t8_geometry_implementations
105
)
106
install( FILES
107
t8_cad/t8_cad.hxx
108
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/t8_cad
109
)
110
endif()
111
112
if( T8CODE_BUILD_PEDANTIC )
113
target_compile_options( T8 PUBLIC -pedantic )
114
set (T8_CXXFLAGS "${T8_CXXFLAGS} -Wpedantic")
115
set (T8_CFLAGS "${T8_CFLAGS} -Wpedantic")
116
endif()
117
118
if( T8CODE_BUILD_WALL)
119
target_compile_options( T8 PUBLIC -Wall )
120
set (T8_CXXFLAGS "${T8_CXXFLAGS} -Wall")
121
set (T8_CFLAGS "${T8_CFLAGS} -Wall")
122
endif()
123
124
if( T8CODE_BUILD_WERROR )
125
target_compile_options( T8 PUBLIC -Werror )
126
set (T8_CXXFLAGS "${T8_CXXFLAGS} -Werror")
127
set (T8_CFLAGS "${T8_CFLAGS} -Werror")
128
endif()
129
130
if( T8CODE_BUILD_WEXTRA )
131
target_compile_options( T8 PUBLIC -Wextra )
132
set (T8_CXXFLAGS "${T8_CXXFLAGS} -Wextra")
133
set (T8_CFLAGS "${T8_CFLAGS} -Wextra")
134
endif()
135
136
137
target_sources( T8 PRIVATE
138
t8.c
139
t8_eclass.c
140
t8_element_shape.c
141
t8_element.cxx
142
t8_refcount.c
143
t8_version.c
144
t8_vtk.c
145
t8_cmesh/t8_cmesh.cxx
146
t8_cmesh/t8_cmesh_cad.cxx
147
t8_cmesh/t8_cmesh_geometry.cxx
148
t8_cmesh/t8_cmesh_examples.cxx
149
t8_cmesh/t8_cmesh_helpers.cxx
150
t8_cmesh/t8_cmesh_internal/t8_cmesh_commit.cxx
151
t8_cmesh/t8_cmesh_internal/t8_cmesh_copy.c
152
t8_cmesh/t8_cmesh_internal/t8_cmesh_offset.c
153
t8_cmesh/t8_cmesh_internal/t8_cmesh_partition.cxx
154
t8_cmesh/t8_cmesh_internal/t8_cmesh_stash.c
155
t8_cmesh/t8_cmesh_internal/t8_cmesh_trees.cxx
156
t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_conn_tree_to_vertex.cxx
157
t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_conn_vertex_to_tree.cxx
158
t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_connectivity.cxx
159
t8_cmesh/t8_cmesh_io/t8_cmesh_readmshfile.cxx
160
t8_cmesh/t8_cmesh_io/t8_cmesh_save.cxx
161
t8_cmesh/t8_cmesh_io/t8_cmesh_triangle.cxx
162
t8_data/t8_shmem.c
163
t8_data/t8_containers.cxx
164
t8_forest/t8_forest_adapt.cxx
165
t8_forest/t8_forest_partition.cxx
166
t8_forest/t8_forest_partition_for_coarsening.cxx
167
t8_forest/t8_forest_pfc_helper.cxx
168
t8_forest/t8_forest.cxx
169
t8_forest/t8_forest_private.cxx
170
t8_forest/t8_forest_ghost.cxx
171
t8_forest/t8_forest_iterate.cxx
172
t8_forest/t8_forest_balance.cxx
173
t8_forest/t8_forest_search/t8_forest_search.cxx
174
t8_geometry/t8_geometry.cxx
175
t8_geometry/t8_geometry_helpers.c
176
t8_geometry/t8_geometry_base.cxx
177
t8_geometry/t8_geometry_handler.cxx
178
t8_geometry/t8_geometry_with_vertices.cxx
179
t8_geometry/t8_geometry_implementations/t8_geometry_analytic.cxx
180
t8_geometry/t8_geometry_implementations/t8_geometry_linear.cxx
181
t8_geometry/t8_geometry_implementations/t8_geometry_linear_axis_aligned.cxx
182
t8_geometry/t8_geometry_implementations/t8_geometry_lagrange.cxx
183
t8_geometry/t8_geometry_implementations/t8_geometry_zero.cxx
184
t8_geometry/t8_geometry_implementations/t8_geometry_examples.cxx
185
t8_schemes/t8_scheme.cxx
186
t8_schemes/t8_default/t8_default.cxx
187
t8_schemes/t8_default/t8_default_hex/t8_default_hex.cxx
188
t8_schemes/t8_default/t8_default_hex/t8_dhex_bits.c
189
t8_schemes/t8_default/t8_default_line/t8_default_line.cxx
190
t8_schemes/t8_default/t8_default_line/t8_dline_bits.c
191
t8_schemes/t8_default/t8_default_prism/t8_default_prism.cxx
192
t8_schemes/t8_default/t8_default_prism/t8_dprism_bits.c
193
t8_schemes/t8_default/t8_default_pyramid/t8_default_pyramid.cxx
194
t8_schemes/t8_default/t8_default_pyramid/t8_dpyramid_bits.c
195
t8_schemes/t8_default/t8_default_pyramid/t8_dpyramid_connectivity.c
196
t8_schemes/t8_default/t8_default_quad/t8_default_quad.cxx
197
t8_schemes/t8_default/t8_default_quad/t8_default_quad_bits.cxx
198
t8_schemes/t8_default/t8_default_tet/t8_default_tet.cxx
199
t8_schemes/t8_default/t8_default_tet/t8_dtet_bits.c
200
t8_schemes/t8_default/t8_default_tet/t8_dtet_connectivity.c
201
t8_schemes/t8_default/t8_default_tri/t8_default_tri.cxx
202
t8_schemes/t8_default/t8_default_tri/t8_dtri_bits.c
203
t8_schemes/t8_default/t8_default_tri/t8_dtri_connectivity.c
204
t8_schemes/t8_default/t8_default_vertex/t8_default_vertex.cxx
205
t8_types/t8_vec.cxx
206
t8_schemes/t8_standalone/t8_standalone.cxx
207
t8_vtk/t8_vtk_writer.cxx
208
t8_vtk/t8_vtk_write_ASCII.cxx
209
t8_vtk/t8_vtk_writer_helper.cxx
210
)
211
212
target_compile_definitions( T8 PUBLIC T8_CMAKE_BUILD )
213
target_compile_definitions( T8 PUBLIC T8_CC="${CMAKE_C_COMPILER}" )
214
target_compile_definitions( T8 PUBLIC T8_CFLAGS="${T8_CFLAGS}" )
215
target_compile_definitions( T8 PUBLIC T8_CXX="${CMAKE_CXX_COMPILER}" )
216
target_compile_definitions( T8 PUBLIC T8_CXXFLAGS="${T8_CXXFLAGS}" )
217
target_compile_definitions( T8 PUBLIC T8_LDFLAGS="${CMAKE_SHARED_LINKER_FLAGS}" )
218
219
target_compile_definitions( T8 PUBLIC T8_PACKAGE_STRING="t8 ${T8CODE_VERSION}" )
220
target_compile_definitions( T8 PUBLIC T8_VERSION="${T8CODE_VERSION}" )
221
target_compile_definitions( T8 PUBLIC T8_VERSION_MAJOR=${T8CODE_VERSION_MAJOR} )
222
target_compile_definitions( T8 PUBLIC T8_VERSION_MINOR=${T8CODE_VERSION_MINOR} )
223
target_compile_definitions( T8 PUBLIC T8_VERSION_PATCH=${T8CODE_VERSION_PATCH} )
224
target_compile_definitions( T8 PUBLIC T8_VERSION_POINT=${T8CODE_VERSION_POINT} )
225
226
get_target_property( T8_LIBS_LIST T8 LINK_LIBRARIES )
227
string( REPLACE ";" " " T8_LIBS "${T8_LIBS_LIST}" )
228
target_compile_definitions( T8 PUBLIC T8_LIBS="${T8_LIBS}" )
229
230
install( FILES
231
t8.h
232
t8_eclass.h
233
t8_element.h
234
t8_element_shape.h
235
t8_mat.h
236
t8_refcount.h
237
t8_version.h
238
t8_vtk.h
239
t8_with_macro_error.h
240
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
241
)
242
243
# Note: Some of the created install directories will be empty, for example t8_cmesh/t8_cmesh_internal
244
# since none of the files in them should be installed.
245
# However, CMake still creates the folder. It would be better if it did not do so.
246
# It seems like we cannot force CMake to not create the folder.
247
# See https://gitlab.kitware.com/cmake/cmake/-/issues/19189
248
249
install( DIRECTORY t8_helper_functions
250
DESTINATION PRIVATE_HEADER
251
FILES_MATCHING
252
PATTERN "*.hxx"
253
)
254
install( DIRECTORY t8_cmesh
255
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
256
FILES_MATCHING
257
PATTERN "*.h"
258
PATTERN "*.hxx"
259
PATTERN "t8_cmesh/t8_cmesh_internal*" EXCLUDE
260
PATTERN "t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_connectivity.hxx" EXCLUDE
261
PATTERN "t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_conn_*.hxx" EXCLUDE
262
)
263
install( DIRECTORY t8_data
264
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
265
FILES_MATCHING
266
PATTERN "*.h"
267
PATTERN "*.hxx"
268
)
269
install( DIRECTORY t8_forest
270
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
271
FILES_MATCHING
272
PATTERN "*.h"
273
PATTERN "*.hxx"
274
PATTERN "t8_forest/t8_forest_balance.h" EXCLUDE
275
PATTERN "t8_forest/t8_forest_ghost.h " EXCLUDE
276
PATTERN "t8_forest/t8_forest_private.h" EXCLUDE
277
)
278
install( DIRECTORY t8_geometry
279
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
280
FILES_MATCHING
281
PATTERN "*.h"
282
PATTERN "*.hxx"
283
PATTERN "t8_geometry/t8_geometry_implementations/t8_geometry_cad.h" EXCLUDE
284
PATTERN "t8_geometry/t8_geometry_implementations/t8_geometry_cad.hxx" EXCLUDE
285
)
286
install( DIRECTORY t8_schemes
287
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
288
FILES_MATCHING
289
PATTERN "*.h"
290
PATTERN "*.hxx"
291
)
292
install( DIRECTORY t8_vtk
293
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
294
FILES_MATCHING
295
PATTERN "*.h"
296
PATTERN "*.hxx"
297
PATTERN "t8_vtk/t8_with_vtk/t8_vtk_parallel.hxx" EXCLUDE
298
PATTERN "t8_vtk/t8_with_vtk/t8_vtk_polydata.hxx" EXCLUDE
299
PATTERN "t8_vtk/t8_with_vtk/t8_vtk_unstructured.hxx" EXCLUDE
300
PATTERN "t8_vtk/t8_vtk_write_ASCII.hxx" EXCLUDE
301
PATTERN "t8_vtk/t8_vtk_writer_helper.hxx" EXCLUDE
302
)
303
install( DIRECTORY t8_types
304
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
305
FILES_MATCHING
306
PATTERN "*.hxx"
307
PATTERN "*.h"
308
)
309
310
install( TARGETS T8
311
EXPORT ${PROJECT_NAME}-targets
312
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
313
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
314
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
315
)
316
317
include( CMakePackageConfigHelpers )
318
319
configure_package_config_file( ${CMAKE_CURRENT_LIST_DIR}/config.cmake.in
320
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}Config.cmake
321
INSTALL_DESTINATION cmake
322
)
323
324
write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}ConfigVersion.cmake
325
COMPATIBILITY SameMajorVersion
326
VERSION "${T8CODE_VERSION_MAJOR}.${T8CODE_VERSION_MINOR}.${T8CODE_VERSION_PATCH}"
327
)
328
329
install( EXPORT ${PROJECT_NAME}-targets
330
NAMESPACE ${PROJECT_NAME}::
331
DESTINATION cmake
332
)
333
334
install( FILES
335
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}Config.cmake
336
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}ConfigVersion.cmake
337
DESTINATION cmake
338
)
339
340