From 7d1a135ef89c13e5b658302ea8d4bb5bf0102a7d Mon Sep 17 00:00:00 2001 From: Michele Martone Date: Mon, 6 Jul 2026 14:10:06 +0200 Subject: [PATCH] add post-installation test (answer issue #2361) Address issue #2361 by adding a post-installation test goal (`post_install_tests`). This works by: - generating a top-level CMakeLists.txt file with hardcoded paths reflecting the installation directories and installing it in a directory with documentation - installing two simple CMakeLists.txt files meant as t8code use examples; the two are located in respective sub-directories, both containing the same sample t8code program (the first tutorial program actually) - ensuring that the top-level CMakeLists.txt file is be usable from anywhere without further configuration, and uses the two CMakeLists.txt files to build two executables and run them (via the `tests` target) - having a `post_install_tests` target, to build the above two programs in the temporary `post_install_tests_dir` directory for test purposes - assuming the `post_install_tests` target to only work after `install` - keeping the test to be basic - the goal is to have detection of the t8code library to work, as well as build and execution of the two test programs Current shortcomings: - test limited to Linux - not documented anywhere ( ideal would be in this files' tree, but current t8code practice uses t8code.wiki, which is separate ) - it may assume that the two MPI-enabled executables can be ran straight-ahead - installation happens in a documentation directory, but to be enabled, this feature relies on T8CODE_BUILD_TUTORIALS, not T8CODE_BUILD_DOCUMENTATION p.s.: Since this is my first contribution to t8code, I'm including my authorization to treat this contribution under the "FreeBSD License" and I'm signing (at least) this commit with my usual GPG key. --- CMakeLists.txt | 11 +++++++ doc/author_martone.txt | 1 + doc/cmake_examples/CMakeLists.txt.in | 37 ++++++++++++++++++++++++ doc/cmake_examples/a/CMakeLists.txt | 29 +++++++++++++++++++ doc/cmake_examples/b/CMakeLists.txt | 43 ++++++++++++++++++++++++++++ tutorials/CMakeLists.txt | 10 +++++++ 6 files changed, 131 insertions(+) create mode 100644 doc/author_martone.txt create mode 100644 doc/cmake_examples/CMakeLists.txt.in create mode 100644 doc/cmake_examples/a/CMakeLists.txt create mode 100644 doc/cmake_examples/b/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e425bc63c..7e78762bef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() endif() if ( T8CODE_BUILD_EXAMPLES ) diff --git a/doc/author_martone.txt b/doc/author_martone.txt new file mode 100644 index 0000000000..c43319f7e8 --- /dev/null +++ b/doc/author_martone.txt @@ -0,0 +1 @@ +I place my contributions to t8code under the FreeBSD license. Michele Martone diff --git a/doc/cmake_examples/CMakeLists.txt.in b/doc/cmake_examples/CMakeLists.txt.in new file mode 100644 index 0000000000..da872f44e9 --- /dev/null +++ b/doc/cmake_examples/CMakeLists.txt.in @@ -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() diff --git a/doc/cmake_examples/a/CMakeLists.txt b/doc/cmake_examples/a/CMakeLists.txt new file mode 100644 index 0000000000..956b1d7e9a --- /dev/null +++ b/doc/cmake_examples/a/CMakeLists.txt @@ -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) +target_link_libraries(test_a PRIVATE T8CODE::T8) +add_custom_target(tests_a COMMAND ./test_a) diff --git a/doc/cmake_examples/b/CMakeLists.txt b/doc/cmake_examples/b/CMakeLists.txt new file mode 100644 index 0000000000..334a99a9a2 --- /dev/null +++ b/doc/cmake_examples/b/CMakeLists.txt @@ -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) +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) diff --git a/tutorials/CMakeLists.txt b/tutorials/CMakeLists.txt index 4c21e232db..29308b1752 100644 --- a/tutorials/CMakeLists.txt +++ b/tutorials/CMakeLists.txt @@ -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/ ) endfunction() function( add_mesh_handle_tutorial ) @@ -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() + if( T8CODE_BUILD_MESH_HANDLE ) add_mesh_handle_tutorial( NAME t8_mesh_element_data SOURCES mesh_handle/t8_mesh_element_data.cxx ) endif()