Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,17 @@ endif()

if ( T8CODE_BUILD_TUTORIALS )
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/tutorials )
if ( CMAKE_SYSTEM_NAME MATCHES "Linux" ) # post-install tests currently limited to our main development OS
add_custom_target(post_install_tests # notice that add_test() would not be appropriate for this test
COMMAND rm -fR post_install_tests_dir # we perform the test out of this cmake tree
COMMAND mkdir post_install_tests_dir
COMMAND cd post_install_tests_dir && cmake ${CMAKE_INSTALL_PREFIX}/share/doc/T8CODE/cmake_examples/ && make VERBOSE=1 && make VERBOSE=1 tests
COMMAND rm -fR post_install_tests_dir
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
VERBATIM
COMMENT "Post-install tests' target. It creates, uses, and deletes temporary directory 'post_install_tests_dir'. It assumes running under Linux."
)
endif()
Comment on lines +284 to +294

@sandro-elsweijer sandro-elsweijer Jul 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to translate this to cmake commands as good as possible. This way cmake peserves the used generator, build type, etc. and it is also OS agnostic.
The BINARY_DIR could be extracted from the (PROJECT_BINARY_DIR)[PROJECT_BINARY_DIR] cmake variable and passed to the test in the CMakeLists calling this build script.

Suggested change
if ( CMAKE_SYSTEM_NAME MATCHES "Linux" ) # post-install tests currently limited to our main development OS
add_custom_target(post_install_tests # notice that add_test() would not be appropriate for this test
COMMAND rm -fR post_install_tests_dir # we perform the test out of this cmake tree
COMMAND mkdir post_install_tests_dir
COMMAND cd post_install_tests_dir && cmake ${CMAKE_INSTALL_PREFIX}/share/doc/T8CODE/cmake_examples/ && make VERBOSE=1 && make VERBOSE=1 tests
COMMAND rm -fR post_install_tests_dir
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
VERBATIM
COMMENT "Post-install tests' target. It creates, uses, and deletes temporary directory 'post_install_tests_dir'. It assumes running under Linux."
)
endif()
# Remove any previous build directory.
file(REMOVE_RECURSE "${BINARY_DIR}/post_install_tests")
file(MAKE_DIRECTORY "${BINARY_DIR}")
set(EXAMPLE_DIR
"${INSTALL_PREFIX}/path_to_dir"
)
# Run configure step
execute_process(
COMMAND
${CMAKE_COMMAND}
-S "${EXAMPLE_DIR}"
-B "${BINARY_DIR/post_install_tests}"
RESULT_VARIABLE result
)
if(NOT result EQUAL 0)
message(FATAL_ERROR "Failed to configure installed example.")
endif()
# Run build step
execute_process(
COMMAND
${CMAKE_COMMAND}
--build "${BINARY_DIR/post_install_tests}"
RESULT_VARIABLE result
)
if(NOT result EQUAL 0)
message(FATAL_ERROR "Failed to build installed example.")
endif()
# Run tests
execute_process(
COMMAND
${CMAKE_COMMAND}
--build "${BINARY_DIR/post_install_tests}"
--target tests
RESULT_VARIABLE result
)
if(NOT result EQUAL 0)
message(FATAL_ERROR "Installed example tests failed.")
endif()
file(REMOVE_RECURSE "${BINARY_DIR/post_install_tests}")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You removed the post_install_tests target along the way. We want to have that.

@sandro-elsweijer sandro-elsweijer Jul 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, I added it back

endif()

if ( T8CODE_BUILD_EXAMPLES )
Expand Down
1 change: 1 addition & 0 deletions doc/author_martone.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I place my contributions to t8code under the FreeBSD license. Michele Martone <michelemartone@users.sourceforge.net>
37 changes: 37 additions & 0 deletions doc/cmake_examples/CMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This file is part of t8code.
# t8code is a C library to manage a collection (a forest) of multiple
# connected adaptive space-trees of general element types in parallel.
#
# Copyright (C) 2026 the developers
#
# t8code is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# t8code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with t8code; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

cmake_minimum_required( VERSION 3.2 )
project(
T8CODE_DOC_CMAKE_EXAMPLES
DESCRIPTION "A CMakeLists.txt file to test installed CMakeLists.txt example files (which can be ran independently anyways). The idea is to use this after installing T8CODE."
)

# The two following lines stem from the user-provided installation directories.
# You can test the subdirectories individually by specifying them yourself via -D...
set(T8TEST_ROOT @CMAKE_INSTALL_PREFIX@)
set(CMAKE_PREFIX_PATH @CMAKE_INSTALL_PREFIX@)

file(GLOB T8CODE_CMAKE_EXAMPLES RELATIVE "${CMAKE_CURRENT_LIST_DIR}" "${CMAKE_CURRENT_LIST_DIR}/?") # for each single-character directory; notice there's no explicit listing here
add_custom_target(tests)
foreach(_dir IN LISTS T8CODE_CMAKE_EXAMPLES)
add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/${_dir} )
add_dependencies( tests tests_${_dir} )
endforeach()
29 changes: 29 additions & 0 deletions doc/cmake_examples/a/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file is part of t8code.
# t8code is a C library to manage a collection (a forest) of multiple
# connected adaptive space-trees of general element types in parallel.
#
# Copyright (C) 2026 the developers
#
# t8code is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# t8code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with t8code; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# A CMakeLists.txt example file showing a way of detecting an installed instance of T8CODE and using it in program test.cxx.
# This example relies on what is being declared in files installed by T8CODE.

cmake_minimum_required(VERSION 3.22.0)
project(t8test DESCRIPTION "t8code test program (requires CMAKE_PREFIX_PATH to point to T8CODE's package files are)" LANGUAGES CXX)
find_package(T8CODE)
add_executable(test_a test.cxx)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please avoid using single letter file names, variable names, etc.?

target_link_libraries(test_a PRIVATE T8CODE::T8)
add_custom_target(tests_a COMMAND ./test_a)
43 changes: 43 additions & 0 deletions doc/cmake_examples/b/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This file is part of t8code.
# t8code is a C library to manage a collection (a forest) of multiple
# connected adaptive space-trees of general element types in parallel.
#
# Copyright (C) 2026 the developers
#
# t8code is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# t8code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with t8code; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# A CMakeLists.txt file showing a way of detecting an installed instance of T8CODE for use in program test.cxx.
# This example does not rely on what is being declared in files installed by T8CODE.

cmake_minimum_required(VERSION 3.22)
include(CheckIncludeFileCXX)
include(CheckLibraryExists)
project(t8test DESCRIPTION "t8code test program (needs T8TEST_ROOT to contain relevant include and lib directories and CMAKE_PREFIX_PATH to point to T8CODE's package files are.)" LANGUAGES CXX)
option(T8TEST_ROOT "Custom directory containing t8code's include, lib, ..." "")
find_library(T8CODE_LIBRARY t8 REQUIRED) # one may have done this in the if conditional construct after check_library_exists
CHECK_LIBRARY_EXISTS(t8 t8_init "${T8TEST_ROOT}/lib" HAVE_T8) # check_library_exists looks for a library and sets one variable accordingly
if(NOT HAVE_T8)
message(FATAL_ERROR "no t8 library found!")
else()
message("t8 library found in ${T8TEST_ROOT}/lib")
endif()
find_path(SC_INCLUDE_DIR sc.h REQUIRED)
find_path(T8CODE_INCLUDE_DIR t8.h REQUIRED)
add_executable(test_b test.cxx)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to have the directories under doc/cmake_examples easily enumerable via globbing from elsewhere -- i.e. with no need to know their identifier in other places. The current scheme was "single letter". I could introduce a prefix (e.g. example_mini and example_midi); that would be an epsilon more informative (not worth the cognitive effort IMO) but would be introducing redundancy (which I'm striving to reduce). Would you still prefer that way (say example_mini and example_midi) ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about post_installation_check_1 and post_installation_check_2?
There is nothing against using enumerations of any sort, but test_b and test.cxx are not really descriptive and it could mean anything.

target_include_directories(test_b PUBLIC "${SC_INCLUDE_DIR}" )
target_include_directories(test_b PUBLIC "${T8CODE_INCLUDE_DIR}" )
target_link_directories(test_b PUBLIC "${T8TEST_ROOT}/lib" )
target_link_libraries(test_b PRIVATE t8 sc)
add_custom_target(tests_b COMMAND ./test_b)
10 changes: 10 additions & 0 deletions tutorials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function( add_t8_tutorial )
endif( T8CODE_EXPORT_COMPILE_COMMANDS )

install( TARGETS ${ADD_T8_TUTORIAL_NAME} RUNTIME )
install( FILES ${ADD_T8_TUTORIAL_SOURCES} DESTINATION ${CMAKE_INSTALL_DOCDIR}/tutorials/general/ )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a new configuration argument to do this and place this in its own cmake file inside the test folder? We want to keep all directories true to their purpose and the tutorial folder is just for tutorials. Same for the documentation folder.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you suggesting a new configuration variable? test/CMakeLists.txt depends on T8CODE_BUILD_TESTS, which is an already existing configuration variable.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think he meant that it should not be installed in ${ADD_T8_TUTORIAL_SOURCES}.

@sandro-elsweijer sandro-elsweijer Jul 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I meant that this is a post installation test and that it does not have anything to do with the tutorials. Yes, it uses a tutorial source file as test subject, but as a user i would not expect a post installation test in the tutorial folder. I would expect this to be in the test folder.

Also, I would not expect this post installation test to be dependent on the T8CODE_BUILD_TUTORIALS option since, as i already explained, it is a test.

endfunction()

function( add_mesh_handle_tutorial )
Expand Down Expand Up @@ -81,6 +82,15 @@ copy_tutorial_file (features/t8_features_curved_meshes_generate_cmesh_quad.geo)
copy_tutorial_file (features/t8_features_curved_meshes_generate_cmesh_tet.geo)
copy_tutorial_file (features/t8_features_curved_meshes_generate_cmesh_tri.geo)

# notice that in the following, we install files from doc/ and tutorials/ together:
file(GLOB T8CODE_CMAKE_EXAMPLES RELATIVE "${PROJECT_SOURCE_DIR}/doc/cmake_examples/" "${PROJECT_SOURCE_DIR}/doc/cmake_examples/?") # for each single-character directory; notice there's no explicit listing here
configure_file( ${PROJECT_SOURCE_DIR}/doc/cmake_examples/CMakeLists.txt.in ${CMAKE_BINARY_DIR}/doc/cmake_examples/CMakeLists.txt @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/doc/cmake_examples/CMakeLists.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/cmake_examples/ RENAME CMakeLists.txt) # reminder that we may want to name this differently (yet, no necessity for .in)
foreach(_dir IN LISTS T8CODE_CMAKE_EXAMPLES)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/doc/cmake_examples/${_dir} DESTINATION ${CMAKE_INSTALL_DOCDIR}/cmake_examples/) # notice we take directories from doc...
install(FILES ${PROJECT_SOURCE_DIR}/tutorials/general/t8_step0_helloworld.cxx DESTINATION ${CMAKE_INSTALL_DOCDIR}/cmake_examples/${_dir}/ RENAME test.cxx) #... and add the same sample tutorial program as a test
endforeach()
Comment on lines +85 to +92

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can happily re-use the tutorial files as test source code, but the actual testing should stay outside the tutorial folder

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand your comment. Testing happens anyway in a post_install_tests_dir directory.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant, that the main purpose of this whole PR is to introduce a software test. Therefore, everything should be located in the test folder. The PR is not meant as documentation and also not as a tutorial. Yes, users could look at this to inspire them, but the main purpose is still that this is a software test.


if( T8CODE_BUILD_MESH_HANDLE )
add_mesh_handle_tutorial( NAME t8_mesh_element_data SOURCES mesh_handle/t8_mesh_element_data.cxx )
endif()