Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DLR-AMR
GitHub Repository: DLR-AMR/t8code
Path: blob/main/example/CMakeLists.txt
901 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
# Conditionally adding new sources to the main T8 target as in the original BS looked wrong...
22
if ( T8CODE_BUILD_AS_SHARED_LIBRARY )
23
add_library( t8example SHARED )
24
else()
25
add_library( t8example STATIC )
26
endif()
27
target_sources( t8example PRIVATE common/t8_example_common.cxx common/t8_example_common_functions.cxx )
28
target_include_directories( t8example PRIVATE ${CMAKE_CURRENT_LIST_DIR}/.. ${SC_INCLUDE_DIR} )
29
target_link_libraries( t8example PRIVATE T8 ${SC_LIBRARIES} m )
30
install( TARGETS t8example LIBRARY )
31
32
function( add_t8_example )
33
set( options "" )
34
set( oneValueArgs "NAME" )
35
set( multiValueArgs "SOURCES" )
36
cmake_parse_arguments( ADD_T8_EXAMPLE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
37
38
# Get the path of the first file listed in the SOURCES list and use it to determine the build directory.
39
# The executable will be build in the same directory as the first source file.
40
list(GET ADD_T8_EXAMPLE_SOURCES 0 FIRST_SOURCE)
41
get_filename_component(EXAMPLE_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/${FIRST_SOURCE}" DIRECTORY)
42
file(RELATIVE_PATH EXAMPLE_RELATIVE_DIR "${CMAKE_SOURCE_DIR}" "${EXAMPLE_SOURCE_DIR}")
43
set(EXAMPLE_BUILD_DIR "${CMAKE_BINARY_DIR}/${EXAMPLE_RELATIVE_DIR}")
44
45
add_executable( ${ADD_T8_EXAMPLE_NAME} ${ADD_T8_EXAMPLE_SOURCES} )
46
target_link_libraries( ${ADD_T8_EXAMPLE_NAME} PRIVATE T8 t8example SC::SC )
47
target_include_directories( ${ADD_T8_EXAMPLE_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/.. )
48
49
set_target_properties(${ADD_T8_EXAMPLE_NAME} PROPERTIES
50
RUNTIME_OUTPUT_DIRECTORY "${EXAMPLE_BUILD_DIR}"
51
LIBRARY_OUTPUT_DIRECTORY "${EXAMPLE_BUILD_DIR}"
52
ARCHIVE_OUTPUT_DIRECTORY "${EXAMPLE_BUILD_DIR}"
53
)
54
55
if( T8CODE_EXPORT_COMPILE_COMMANDS )
56
set_target_properties( ${ADD_T8_EXAMPLE_NAME} PROPERTIES EXPORT_COMPILE_COMMANDS ON )
57
endif( T8CODE_EXPORT_COMPILE_COMMANDS )
58
59
install( TARGETS ${ADD_T8_EXAMPLE_NAME} DESTINATION RUNTIME)
60
endfunction()
61
62
#copy example files to the exact same location in the builddir as they are in the source dir
63
function( copy_example_file EXAMPLE_FILE_NAME_SUBPATH )
64
configure_file(${CMAKE_CURRENT_LIST_DIR}/${EXAMPLE_FILE_NAME_SUBPATH} ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE_FILE_NAME_SUBPATH} COPYONLY)
65
endfunction()
66
67
add_t8_example( NAME t8_advection SOURCES advect/t8_advection.cxx )
68
69
add_t8_example( NAME t8_cmesh_partition SOURCES cmesh/t8_cmesh_partition.cxx )
70
add_t8_example( NAME t8_cmesh_set_join_by_vertices SOURCES cmesh/t8_cmesh_set_join_by_vertices.cxx )
71
add_t8_example( NAME t8_cmesh_geometry_examples SOURCES cmesh/t8_cmesh_geometry_examples.cxx )
72
add_t8_example( NAME t8_cmesh_create_partitioned SOURCES cmesh/t8_cmesh_create_partitioned.cxx )
73
add_t8_example( NAME t8_cmesh_hypercube_pad SOURCES cmesh/t8_cmesh_hypercube_pad.cxx )
74
75
add_t8_example( NAME t8_test_ghost SOURCES forest/t8_test_ghost.cxx )
76
add_t8_example( NAME t8_test_face_iterate SOURCES forest/t8_test_face_iterate.cxx )
77
add_t8_example( NAME t8_test_ghost_large_level_diff SOURCES forest/t8_test_ghost_large_level_diff.cxx )
78
79
add_t8_example( NAME t8_example_geometries SOURCES geometry/t8_example_geometries.cxx )
80
81
add_t8_example( NAME t8_cmesh_load_save SOURCES IO/cmesh/t8_cmesh_load_save.cxx )
82
add_t8_example( NAME t8_read_msh_file SOURCES IO/cmesh/gmsh/t8_read_msh_file.cxx )
83
add_t8_example( NAME t8_load_and_refine_square_w_hole SOURCES IO/cmesh/gmsh/t8_load_and_refine_square_w_hole.cxx )
84
add_t8_example( NAME t8_read_tetgen SOURCES IO/cmesh/tetgen/t8_read_tetgen_file.cxx )
85
add_t8_example( NAME t8_time_tetgen SOURCES IO/cmesh/tetgen/t8_time_tetgen_file.cxx )
86
add_t8_example( NAME t8_forest_tetgen SOURCES IO/cmesh/tetgen/t8_forest_from_tetgen.cxx )
87
add_t8_example( NAME t8_read_triangle SOURCES IO/cmesh/triangle/t8_read_triangle_file.cxx )
88
89
copy_example_file (IO/cmesh/gmsh/circlesquare_hybrid_hole.msh)
90
91
if(T8CODE_ENABLE_VTK)
92
add_t8_example( NAME t8_cmesh_read_from_vtk SOURCES IO/cmesh/vtk/t8_cmesh_read_from_vtk.cxx )
93
endif()
94
95
add_t8_example( NAME t8_gmsh_to_vtk SOURCES IO/forest/gmsh/t8_gmsh_to_vtk.cxx )
96
97
add_t8_example( NAME t8_example_spheres SOURCES remove/t8_example_spheres.cxx )
98
add_t8_example( NAME t8_example_gauss_blob SOURCES remove/t8_example_gauss_blob.cxx )
99
add_t8_example( NAME t8_example_empty_trees SOURCES remove/t8_example_empty_trees.cxx )
100
101
add_t8_example( NAME t8_version SOURCES version/t8_version.cxx )
102
103