Skip to content

Commit

Permalink
Merge pull request #929 from dutkalex/main
Browse files Browse the repository at this point in the history
Initial CMake support
  • Loading branch information
jmark authored Feb 21, 2024
2 parents e5c5abc + c286541 commit 0405df3
Show file tree
Hide file tree
Showing 8 changed files with 434 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
sc/
p4est/
build-aux/
build/

.deps/
.libs/
Expand Down
68 changes: 68 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
cmake_minimum_required( VERSION 3.16 )
project( T8CODE DESCRIPTION "Parallel algorithms and data structures for tree-based AMR with arbitrary element shapes." LANGUAGES C CXX )
include( CTest )


option( T8CODE_BUILD_AS_SHARED_LIBRARY "Whether t8code should be built as a shared or a static library" ON )
option( T8CODE_BUILD_TESTS "Build t8code's automated tests" ON )
option( T8CODE_BUILD_TUTORIALS "Build t8code's tutorials" ON )
option( T8CODE_BUILD_EXAMPLES "Build t8code's examples" ON )

option( T8CODE_ENABLE_MPI "Enable t8code's features which rely on MPI" ON )
option( T8CODE_ENABLE_VTK "Enable t8code's features which rely on VTK" OFF )


if( NOT CMAKE_BUILD_TYPE )
set( CMAKE_BUILD_TYPE "Release" )
endif()

set( CMAKE_C_STANDARD 11 )
set( CMAKE_C_STANDARD_REQUIRED ON )
set( CMAKE_C_EXTENSIONS OFF )
list( APPEND CMAKE_C_FLAGS "-Wall" )

set( CMAKE_CXX_STANDARD 17 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
set( CMAKE_CXX_EXTENSIONS OFF )
list( APPEND CMAKE_CXX_FLAGS "-Wall" )


if( T8CODE_ENABLE_MPI )
find_package( MPI COMPONENTS C REQUIRED )
if( NOT MPIEXEC_EXECUTABLE )
message( FATAL_ERROR "MPIEXEC was not found" )
endif()
set( SC_ENABLE_MPI ON )
set( mpi ON ) # This is very dirty, we should consider fixing this in the p4est repo
endif()

if( T8CODE_ENABLE_VTK )
find_package( VTK REQUIRED )
endif()

# Override default for this libsc option
set( BUILD_SHARED_LIBS ON CACHE BOOL "Build libsc as a shared library" )

# Prevent `libsc` and `p4est` from overwriting the default install prefix.
set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT FALSE)

# Rpath options necessary for shared library install to work correctly in user projects.
set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH true)

add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/sc )
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/p4est )
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/src )

if ( T8CODE_BUILD_TESTS )
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/test )
endif()

if ( T8CODE_BUILD_TUTORIALS )
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/tutorials )
endif()

if ( T8CODE_BUILD_EXAMPLES )
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/example )
endif()
52 changes: 52 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Conditionally adding new sources to the main T8 target as in the original BS looked wrong...
add_library( t8example )
target_sources( t8example PRIVATE common/t8_example_common.cxx common/t8_example_common_functions.cxx )
target_include_directories( t8example PRIVATE ${CMAKE_CURRENT_LIST_DIR}/.. )
target_link_libraries( t8example PRIVATE T8 )
install( TARGETS t8example DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )

function( add_t8_example )
set( options "" )
set( oneValueArgs "NAME" )
set( multiValueArgs "SOURCES" )
cmake_parse_arguments( ADD_T8_EXAMPLE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

add_executable( ${ADD_T8_EXAMPLE_NAME} ${ADD_T8_EXAMPLE_SOURCES} )
target_link_libraries( ${ADD_T8_EXAMPLE_NAME} PRIVATE T8 t8example SC::SC )
target_include_directories( ${ADD_T8_EXAMPLE_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/.. )

install( TARGETS ${ADD_T8_EXAMPLE_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/example )
endfunction()

add_t8_example( NAME t8_advection SOURCES advect/t8_advection.cxx )

add_t8_example( NAME t8_cmesh_partition SOURCES cmesh/t8_cmesh_partition.cxx )
add_t8_example( NAME t8_cmesh_set_join_by_vertices SOURCES cmesh/t8_cmesh_set_join_by_vertices.cxx )
add_t8_example( NAME t8_cmesh_geometry_examples SOURCES cmesh/t8_cmesh_geometry_examples.cxx )
add_t8_example( NAME t8_cmesh_create_partitioned SOURCES cmesh/t8_cmesh_create_partitioned.cxx )
add_t8_example( NAME t8_cmesh_hypercube_pad SOURCES cmesh/t8_cmesh_hypercube_pad.cxx )

add_t8_example( NAME t8_face_neighbor SOURCES forest/t8_face_neighbor.cxx )
add_t8_example( NAME t8_test_ghost SOURCES forest/t8_test_ghost.cxx )
add_t8_example( NAME t8_test_face_iterate SOURCES forest/t8_test_face_iterate.cxx )
add_t8_example( NAME t8_test_ghost_large_level_diff SOURCES forest/t8_test_ghost_large_level_diff.cxx )

add_t8_example( NAME t8_example_geometries SOURCES geometry/t8_example_geometries.cxx )

add_t8_example( NAME t8_cmesh_load_save SOURCES IO/cmesh/t8_cmesh_load_save.cxx )
add_t8_example( NAME t8_read_msh_file SOURCES IO/cmesh/gmsh/t8_read_msh_file.cxx )
add_t8_example( NAME t8_load_and_refine_square_w_hole SOURCES IO/cmesh/gmsh/t8_load_and_refine_square_w_hole.cxx )
add_t8_example( NAME t8_write_cmesh_netcdf SOURCES IO/cmesh/netcdf/t8_write_cmesh_netcdf.cxx )
add_t8_example( NAME t8_read_tetgen SOURCES IO/cmesh/tetgen/t8_read_tetgen_file.cxx )
add_t8_example( NAME t8_time_tetgen SOURCES IO/cmesh/tetgen/t8_time_tetgen_file.cxx )
add_t8_example( NAME t8_forest_tetgen SOURCES IO/cmesh/tetgen/t8_forest_from_tetgen.cxx )
add_t8_example( NAME t8_read_triangle SOURCES IO/cmesh/triangle/t8_read_triangle_file.cxx )
add_t8_example( NAME t8_cmesh_read_from_vtk SOURCES IO/cmesh/vtk/t8_cmesh_read_from_vtk.cxx )
add_t8_example( NAME t8_netcdf_compilation_status SOURCES IO/forest/netcdf/t8_netcdf_status.c )
add_t8_example( NAME t8_write_forest_netcdf SOURCES IO/forest/netcdf/t8_write_forest_netcdf.cxx )

add_t8_example( NAME t8_example_spheres SOURCES remove/t8_example_spheres.cxx )
add_t8_example( NAME t8_example_gauss_blob SOURCES remove/t8_example_gauss_blob.cxx )
add_t8_example( NAME t8_example_empty_trees SOURCES remove/t8_example_empty_trees.cxx )

add_t8_example( NAME t8_version SOURCES version/t8_version.cxx )
199 changes: 199 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
if ( ${T8CODE_BUILD_AS_SHARED_LIBRARY} )
add_library( T8 SHARED )
set_target_properties( T8 PROPERTIES POSITION_INDEPENDENT_CODE ON )
else()
add_library( T8 STATIC )
endif()

set_target_properties( T8 PROPERTIES OUTPUT_NAME t8 )

target_compile_definitions( T8 PUBLIC T8_CMAKE_BUILD )
target_compile_definitions( T8 PUBLIC T8_CC="${CMAKE_C_COMPILER}" )
target_compile_definitions( T8 PUBLIC T8_CFLAGS="${CMAKE_C_FLAGS}" )
target_compile_definitions( T8 PUBLIC T8_CPP="${CMAKE_CXX_COMPILER}" )
target_compile_definitions( T8 PUBLIC T8_CPPFLAGS="${CMAKE_CXX_FLAGS}" )
target_compile_definitions( T8 PUBLIC T8_LDFLAGS="${CMAKE_SHARED_LINKER_FLAGS}" )
target_compile_definitions( T8 PUBLIC T8_LIBS="Not available with CMake builds" )


find_package( Git REQUIRED )
execute_process( COMMAND ${GIT_EXECUTABLE} describe --tags
COMMAND cut -c 2-
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE T8CODE_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE )
execute_process( COMMAND echo ${T8CODE_VERSION}
COMMAND cut -d. -f1
OUTPUT_VARIABLE T8CODE_VERSION_MAJOR
OUTPUT_STRIP_TRAILING_WHITESPACE )
execute_process( COMMAND echo ${T8CODE_VERSION}
COMMAND cut -d. -f2
OUTPUT_VARIABLE T8CODE_VERSION_MINOR
OUTPUT_STRIP_TRAILING_WHITESPACE )
execute_process( COMMAND echo ${T8CODE_VERSION}
COMMAND cut -d. -f3
OUTPUT_VARIABLE T8CODE_VERSION_POINT
OUTPUT_STRIP_TRAILING_WHITESPACE )

target_compile_definitions( T8 PUBLIC T8_PACKAGE_STRING="t8 ${T8CODE_VERSION}" )
target_compile_definitions( T8 PUBLIC T8_VERSION="${T8CODE_VERSION}" )
target_compile_definitions( T8 PUBLIC T8_VERSION_MAJOR=${T8CODE_VERSION_MAJOR} )
target_compile_definitions( T8 PUBLIC T8_VERSION_MINOR=${T8CODE_VERSION_MINOR} )
target_compile_definitions( T8 PUBLIC T8_VERSION_POINT=${T8CODE_VERSION_POINT} )


target_include_directories( T8 PUBLIC ${CMAKE_CURRENT_LIST_DIR} )
target_link_libraries( T8 PUBLIC P4EST::P4EST SC::SC )

if ( T8CODE_ENABLE_MPI )
target_compile_definitions( T8 PUBLIC T8_ENABLE_MPI )
target_compile_definitions( T8 PUBLIC T8_ENABLE_MPIIO )
target_link_libraries( T8 PUBLIC MPI::MPI_C )
endif()

if( T8CODE_ENABLE_VTK )
target_compile_definitions( T8 PUBLIC T8_VTK_VERSION_USED="${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" )
target_compile_definitions( T8 PUBLIC T8_WITH_VTK=1 )
target_include_directories( T8 PUBLIC ${VTK_INCLUDE_DIRS} )
target_link_libraries( T8 PUBLIC ${VTK_LIBRARIES} )
endif()

target_sources( T8 PRIVATE
t8.c
t8_eclass.c
t8_mesh.c
t8_element.c
t8_element_cxx.cxx
t8_element_c_interface.cxx
t8_refcount.c
t8_cmesh/t8_cmesh.c
t8_cmesh/t8_cmesh_cad.cxx
t8_cmesh/t8_cmesh_cxx.cxx
t8_cmesh/t8_cmesh_triangle.c
t8_cmesh/t8_cmesh_vtk_writer.c
t8_cmesh/t8_cmesh_stash.c
t8_cmesh/t8_cmesh_vtk_reader.cxx
t8_cmesh/t8_cmesh_save.c
t8_cmesh/t8_cmesh_netcdf.c
t8_cmesh/t8_cmesh_trees.c
t8_cmesh/t8_cmesh_commit.c
t8_cmesh/t8_cmesh_partition.c
t8_cmesh/t8_cmesh_copy.c
t8_data/t8_shmem.c
t8_cmesh/t8_cmesh_geometry.cxx
t8_cmesh/t8_cmesh_examples.c
t8_cmesh/t8_cmesh_helpers.c
t8_data/t8_containers.cxx
t8_cmesh/t8_cmesh_offset.c
t8_cmesh/t8_cmesh_readmshfile.cxx
t8_forest/t8_forest.c
t8_forest/t8_forest_adapt.cxx
t8_geometry/t8_geometry.cxx
t8_geometry/t8_geometry_helpers.c
t8_geometry/t8_geometry_base.cxx
t8_geometry/t8_geometry_with_vertices.cxx
t8_geometry/t8_geometry_implementations/t8_geometry_analytic.cxx
t8_geometry/t8_geometry_implementations/t8_geometry_cad.cxx
t8_geometry/t8_geometry_implementations/t8_geometry_linear.cxx
t8_geometry/t8_geometry_implementations/t8_geometry_linear_axis_aligned.cxx
t8_geometry/t8_geometry_implementations/t8_geometry_zero.cxx
t8_geometry/t8_geometry_implementations/t8_geometry_examples.cxx
t8_forest/t8_forest_partition.cxx
t8_forest/t8_forest_cxx.cxx
t8_forest/t8_forest_private.c
t8_forest/t8_forest_vtk.cxx
t8_forest/t8_forest_ghost.cxx
t8_forest/t8_forest_iterate.cxx
t8_version.c
t8_vtk.c
t8_forest/t8_forest_balance.cxx
t8_forest/t8_forest_netcdf.cxx
t8_element_shape.c
t8_netcdf.c
t8_cmesh/t8_cmesh_testcases.c
t8_vtk/t8_vtk_polydata.cxx
t8_vtk/t8_vtk_unstructured.cxx
t8_vtk/t8_vtk_parallel.cxx
t8_vtk/t8_vtk_reader.cxx
t8_schemes/t8_default/t8_default_cxx.cxx
t8_schemes/t8_default/t8_default_common/t8_default_common_cxx.cxx
t8_schemes/t8_default/t8_default_hex/t8_default_hex_cxx.cxx
t8_schemes/t8_default/t8_default_hex/t8_dhex_bits.c
t8_schemes/t8_default/t8_default_line/t8_default_line_cxx.cxx
t8_schemes/t8_default/t8_default_line/t8_dline_bits.c
t8_schemes/t8_default/t8_default_prism/t8_default_prism_cxx.cxx
t8_schemes/t8_default/t8_default_prism/t8_dprism_bits.c
t8_schemes/t8_default/t8_default_quad/t8_default_quad_cxx.cxx
t8_schemes/t8_default/t8_default_quad/t8_dquad_bits.c
t8_schemes/t8_default/t8_default_tet/t8_default_tet_cxx.cxx
t8_schemes/t8_default/t8_default_tet/t8_dtet_bits.c
t8_schemes/t8_default/t8_default_tet/t8_dtet_connectivity.c
t8_schemes/t8_default/t8_default_tri/t8_default_tri_cxx.cxx
t8_schemes/t8_default/t8_default_tri/t8_dtri_bits.c
t8_schemes/t8_default/t8_default_tri/t8_dtri_connectivity.c
t8_schemes/t8_default/t8_default_vertex/t8_default_vertex_cxx.cxx
t8_schemes/t8_default/t8_default_vertex/t8_dvertex_bits.c
t8_schemes/t8_default/t8_default_pyramid/t8_default_pyramid_cxx.cxx
t8_schemes/t8_default/t8_default_pyramid/t8_dpyramid_bits.c
t8_schemes/t8_default/t8_default_pyramid/t8_dpyramid_connectivity.c
)

set( T8_PUBLIC_HEADERS
t8.h
t8_eclass.h
t8_mesh.h
t8_element_cxx.hxx
t8_element.h
t8_element_c_interface.h
t8_refcount.h
t8_cmesh.h t8_cmesh_triangle.h
t8_cmesh_tetgen.h t8_cmesh_readmshfile.h
t8_cmesh_vtk_writer.h
t8_cmesh_vtk_reader.hxx
t8_vec.h
t8_version.h
t8_vtk.h
t8_cmesh_netcdf.h
t8_forest_netcdf.h
t8_element_shape.h
t8_netcdf.h
t8_cmesh/t8_cmesh_testcases.h
t8_cmesh/t8_cmesh_save.h
t8_cmesh/t8_cmesh_examples.h
t8_cmesh/t8_cmesh_geometry.h
t8_cmesh/t8_cmesh_helpers.h
t8_cmesh/t8_cmesh_cad.hxx
t8_data/t8_shmem.h
t8_data/t8_containers.h
t8_forest/t8_forest.h
t8_forest/t8_forest_general.h
t8_forest/t8_forest_geometrical.h
t8_forest/t8_forest_profiling.h
t8_forest/t8_forest_io.h
t8_forest/t8_forest_adapt.h
t8_forest/t8_forest_vtk.h
t8_forest/t8_forest_to_vtkUnstructured.hxx
t8_forest/t8_forest_iterate.h
t8_forest/t8_forest_partition.h
t8_geometry/t8_geometry.h
t8_geometry/t8_geometry_base.hxx
t8_geometry/t8_geometry_base.h
t8_geometry/t8_geometry_with_vertices.hxx
t8_geometry/t8_geometry_with_vertices.h
t8_geometry/t8_geometry_helpers.h
t8_geometry/t8_geometry_implementations/t8_geometry_linear.h
t8_geometry/t8_geometry_implementations/t8_geometry_linear_axis_aligned.h
t8_geometry/t8_geometry_implementations/t8_geometry_analytic.hxx
t8_geometry/t8_geometry_implementations/t8_geometry_examples.h
t8_geometry/t8_geometry_implementations/t8_geometry_cad.h
t8_geometry/t8_geometry_implementations/t8_geometry_cad.hxx
t8_geometry/t8_geometry_implementations/t8_geometry_linear.hxx
t8_geometry/t8_geometry_implementations/t8_geometry_linear_axis_aligned.hxx
t8_geometry/t8_geometry_implementations/t8_geometry_examples.hxx
t8_geometry/t8_geometry_implementations/t8_geometry_zero.hxx
t8_vtk/t8_vtk_reader.hxx
t8_vtk/t8_vtk_types.h
)

install( FILES ${T8_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include )
install( TARGETS T8 DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )
2 changes: 2 additions & 0 deletions src/t8.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#define T8_H

/* include config headers */
#ifndef T8_CMAKE_BUILD
#include <t8_config.h>
#endif
#include <sc_config.h>
#if (defined(T8_ENABLE_MPI) && !defined(SC_ENABLE_MPI)) || (!defined(T8_ENABLE_MPI) && defined(SC_ENABLE_MPI))
#error "MPI configured differently in t8code and libsc"
Expand Down
2 changes: 2 additions & 0 deletions src/t8_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
#define T8_VERSION_H

#include <t8.h>
#ifndef T8_CMAKE_BUILD
#include <t8_config.h>
#endif

/* In order to convert a macro to a string, we
* need to pass it through these two helper macros. */
Expand Down
Loading

0 comments on commit 0405df3

Please sign in to comment.