From 4d061978f1a959c0e863525f25838211ae0f1f68 Mon Sep 17 00:00:00 2001 From: Johannes Holke Date: Fri, 28 Nov 2025 14:14:23 +0100 Subject: [PATCH 1/5] Add automatically generated header file with VTK version macros --- src/CMakeLists.txt | 20 ++++++++++++++++ src/t8_vtk/t8_vtk_linkage.hxx.in | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/t8_vtk/t8_vtk_linkage.hxx.in diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f1f44b9dd..ea37984bda 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -84,6 +84,9 @@ if ( T8CODE_ENABLE_MPI ) endif() if( T8CODE_ENABLE_VTK ) + # Define T8CODE_VTK_MAJOR/MINOR_VERSION to true, such that get defined in t8code_vtk_linkage.hxx + set ( T8CODE_VTK_MAJOR_VERSION 1 ) + set ( T8CODE_VTK_MINOR_VERSION 1 ) target_compile_definitions( T8 PUBLIC T8_VTK_VERSION_USED="${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" ) target_compile_definitions( T8 PUBLIC T8_ENABLE_VTK=1 ) target_include_directories( T8 PUBLIC ${VTK_INCLUDE_DIR} ) @@ -100,8 +103,24 @@ if( T8CODE_ENABLE_VTK ) t8_vtk/t8_with_vtk/t8_vtk_unstructured.hxx t8_vtk/t8_with_vtk/t8_vtk_reader.hxx DESTINATION include) + +else () + # Ensure that these macros are not set if T8CODE_ENABLE_VTK is not set. + unset ( T8CODE_VTK_MAJOR_VERSION ) + unset ( T8CODE_VTK_MINOR_VERSION ) endif() +# +# Setup the file t8_vtk_linkage.hxx and write macros for the VTK version +# +configure_file (t8_vtk/t8_vtk_linkage.hxx.in t8_vtk/t8_vtk_linkage.hxx @ONLY) + +# install the automatically created t8_vtk_linkage.hxx into the include/t8_vtk folder +install (FILES + ${CMAKE_CURRENT_BINARY_DIR}/t8_vtk/t8_vtk_linkage.hxx + DESTINATION include/t8_vtk +) + if( T8CODE_ENABLE_OCC ) target_compile_definitions( T8 PUBLIC T8_ENABLE_OCC=1 ) target_include_directories( T8 SYSTEM PUBLIC ${OpenCASCADE_INCLUDE_DIR} ) @@ -248,6 +267,7 @@ install( FILES TYPE INCLUDE ) + # Note: Some of the created install directories will be empty, for example t8_cmesh/t8_cmesh_internal # since none of the files in them should be installed. # However, CMake still creates the folder. It would be better if it did not do so. diff --git a/src/t8_vtk/t8_vtk_linkage.hxx.in b/src/t8_vtk/t8_vtk_linkage.hxx.in new file mode 100644 index 0000000000..f02bf023b0 --- /dev/null +++ b/src/t8_vtk/t8_vtk_linkage.hxx.in @@ -0,0 +1,39 @@ +/* + This file is part of t8code. + Copyright (C) 2025 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 3 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. +*/ + +/** + * \file t8_vtk_linkage.hxx + * Automatically generated from t8_vtk_linkage.hxx.in + * This file defines the macros + * \ref T8CODE_ENABLE_VTK - either 0 or 1 specifying if t8code links against VTK or not. + * \ref T8CODE_VTK_MAJOR_VERSION - If T8CODE_ENABLE_VTK The VTK major version number. + * \ref T8CODE_VTK_MINOR_VERSION - If T8CODE_ENABLE_VTK The VTK minor version number. + */ + +#ifndef T8CODE_VTK_LINKAGE_HXX +#define T8CODE_VTK_LINKAGE_HXX + +/** Macro that is 1 if we link against VTK on 0 if we don't. */ +#cmakedefine01 T8CODE_ENABLE_VTK +/** VTK major version number */ +#cmakedefine T8CODE_VTK_MAJOR_VERSION @VTK_MAJOR_VERSION@ +/** VTK minor version number */ +#cmakedefine T8CODE_VTK_MINOR_VERSION @VTK_MINOR_VERSION@ + +#endif // T8CODE_VTK_LINKAGE_HXX \ No newline at end of file From dbba10629c1dd4681f9e1ead8981e21da860d25f Mon Sep 17 00:00:00 2001 From: Johannes Holke Date: Fri, 28 Nov 2025 14:23:02 +0100 Subject: [PATCH 2/5] Change T8CODE to T8 prefix in macro names --- src/CMakeLists.txt | 4 ++++ src/t8_vtk/t8_vtk_linkage.hxx.in | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ea37984bda..32e6eaec12 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -84,6 +84,8 @@ if ( T8CODE_ENABLE_MPI ) endif() if( T8CODE_ENABLE_VTK ) + # Set link macro to 1 (will be used in t8_vtk_linkage.hxx) + set ( T8_ENABLE_VTK 1 ) # Define T8CODE_VTK_MAJOR/MINOR_VERSION to true, such that get defined in t8code_vtk_linkage.hxx set ( T8CODE_VTK_MAJOR_VERSION 1 ) set ( T8CODE_VTK_MINOR_VERSION 1 ) @@ -105,6 +107,8 @@ if( T8CODE_ENABLE_VTK ) DESTINATION include) else () + # Set link macro to 0 (will be used in t8_vtk_linkage.hxx) + set ( T8_ENABLE_VTK 0 ) # Ensure that these macros are not set if T8CODE_ENABLE_VTK is not set. unset ( T8CODE_VTK_MAJOR_VERSION ) unset ( T8CODE_VTK_MINOR_VERSION ) diff --git a/src/t8_vtk/t8_vtk_linkage.hxx.in b/src/t8_vtk/t8_vtk_linkage.hxx.in index f02bf023b0..5d6b0e765c 100644 --- a/src/t8_vtk/t8_vtk_linkage.hxx.in +++ b/src/t8_vtk/t8_vtk_linkage.hxx.in @@ -30,10 +30,10 @@ #define T8CODE_VTK_LINKAGE_HXX /** Macro that is 1 if we link against VTK on 0 if we don't. */ -#cmakedefine01 T8CODE_ENABLE_VTK +#cmakedefine01 T8_ENABLE_VTK /** VTK major version number */ -#cmakedefine T8CODE_VTK_MAJOR_VERSION @VTK_MAJOR_VERSION@ +#cmakedefine T8_VTK_MAJOR_VERSION @VTK_MAJOR_VERSION@ /** VTK minor version number */ -#cmakedefine T8CODE_VTK_MINOR_VERSION @VTK_MINOR_VERSION@ +#cmakedefine T8_VTK_MINOR_VERSION @VTK_MINOR_VERSION@ #endif // T8CODE_VTK_LINKAGE_HXX \ No newline at end of file From cd6fd0f1c37a8b1015f743c4a806a24ad6df39b2 Mon Sep 17 00:00:00 2001 From: Johannes Holke Date: Fri, 28 Nov 2025 14:23:18 +0100 Subject: [PATCH 3/5] Use new macros in test --- src/CMakeLists.txt | 8 ++++---- test/t8_gtest_vtk_linkage.cxx | 29 ++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 32e6eaec12..89f5f284a7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -87,8 +87,8 @@ if( T8CODE_ENABLE_VTK ) # Set link macro to 1 (will be used in t8_vtk_linkage.hxx) set ( T8_ENABLE_VTK 1 ) # Define T8CODE_VTK_MAJOR/MINOR_VERSION to true, such that get defined in t8code_vtk_linkage.hxx - set ( T8CODE_VTK_MAJOR_VERSION 1 ) - set ( T8CODE_VTK_MINOR_VERSION 1 ) + set ( T8_VTK_MAJOR_VERSION 1 ) + set ( T8_VTK_MINOR_VERSION 1 ) target_compile_definitions( T8 PUBLIC T8_VTK_VERSION_USED="${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" ) target_compile_definitions( T8 PUBLIC T8_ENABLE_VTK=1 ) target_include_directories( T8 PUBLIC ${VTK_INCLUDE_DIR} ) @@ -110,8 +110,8 @@ else () # Set link macro to 0 (will be used in t8_vtk_linkage.hxx) set ( T8_ENABLE_VTK 0 ) # Ensure that these macros are not set if T8CODE_ENABLE_VTK is not set. - unset ( T8CODE_VTK_MAJOR_VERSION ) - unset ( T8CODE_VTK_MINOR_VERSION ) + unset ( T8_VTK_MAJOR_VERSION ) + unset ( T8_VTK_MINOR_VERSION ) endif() # diff --git a/test/t8_gtest_vtk_linkage.cxx b/test/t8_gtest_vtk_linkage.cxx index d1fdf96b6d..edc0079805 100644 --- a/test/t8_gtest_vtk_linkage.cxx +++ b/test/t8_gtest_vtk_linkage.cxx @@ -30,6 +30,7 @@ */ #include #include +#include #if T8_ENABLE_VTK #include #include @@ -37,12 +38,22 @@ #endif /* Test correct macro dependencies. - * Will throw a compile time error if T8_VTK_VERSION_USED - * is defined but T8_ENABLE_VTK is not. */ -#ifndef T8_ENABLE_VTK -#ifdef T8_VTK_VERSION_USED -#error Configuration error: T8_VTK_VERSION_USED is defined despite \ - T8_ENABLE_VTK not being defined. + * Will throw a compile time error if T8CODE_ENABLE_VTK is O + * but T8CODE_VTK_VERSION_USED or T8CODE_VTK_MAJOR_VERSION or T8CODE_VTK_MINOR_VERSION is defined. */ +#if not T8CODE_ENABLE_VTK +#ifdef T8CODE_VTK_VERSION_USED +#error Configuration error: T8CODE_VTK_VERSION_USED is defined despite \ + T8CODE_ENABLE_VTK not being defined. +#endif + +#ifdef T8CODE_VTK_MAJOR_VERSION +#error Configuration error: T8CODE_VTK_MAJOR_VERSION is defined despite \ + T8CODE_ENABLE_VTK not being defined. +#endif + +#ifdef T8CODE_VTK_MINOR_VERSION +#error Configuration error: T8CODE_VTK_MINOR_VERSION is defined despite \ + T8CODE_ENABLE_VTK not being defined. #endif #endif @@ -52,9 +63,13 @@ TEST (t8_gtest_vtk_linkage, t8_test_vtk_version_number) #if T8_ENABLE_VTK char vtk_version[BUFSIZ]; snprintf (vtk_version, BUFSIZ, "%i.%i", VTK_MAJOR_VERSION, VTK_MINOR_VERSION); - ASSERT_FALSE (strcmp (T8_VTK_VERSION_USED, vtk_version)) + EXPECT_FALSE (strcmp (T8_VTK_VERSION_USED, vtk_version)) << "linked vtk version (" << vtk_version << ") does not equal the version t8code was configured with (" << T8_VTK_VERSION_USED << ").\n"; + // Check our internal version macros to match VTK version + EXPECT_EQ (T8_VTK_MAJOR_VERSION, VTK_MAJOR_VERSION); + EXPECT_EQ (T8_VTK_MINOR_VERSION, VTK_MINOR_VERSION); + if (!strcmp (T8_VTK_VERSION_USED, vtk_version)) { t8_debugf ("Using vtk version %s.\n", vtk_version); } From c201139fbbde4289e53c215d3baa2d85b41d848f Mon Sep 17 00:00:00 2001 From: Johannes Holke Date: Fri, 28 Nov 2025 14:31:04 +0100 Subject: [PATCH 4/5] Change prefix in test as well --- test/t8_gtest_vtk_linkage.cxx | 43 ++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/test/t8_gtest_vtk_linkage.cxx b/test/t8_gtest_vtk_linkage.cxx index edc0079805..69f4790549 100644 --- a/test/t8_gtest_vtk_linkage.cxx +++ b/test/t8_gtest_vtk_linkage.cxx @@ -38,22 +38,41 @@ #endif /* Test correct macro dependencies. - * Will throw a compile time error if T8CODE_ENABLE_VTK is O - * but T8CODE_VTK_VERSION_USED or T8CODE_VTK_MAJOR_VERSION or T8CODE_VTK_MINOR_VERSION is defined. */ -#if not T8CODE_ENABLE_VTK + * Will throw a compile time error if T8_ENABLE_VTK is O + * but T8CODE_VTK_VERSION_USED or T8_VTK_MAJOR_VERSION or T8_VTK_MINOR_VERSION is defined. */ +#if not T8_ENABLE_VTK #ifdef T8CODE_VTK_VERSION_USED -#error Configuration error: T8CODE_VTK_VERSION_USED is defined despite \ - T8CODE_ENABLE_VTK not being defined. +#error Configuration error: T8_VTK_VERSION_USED is defined despite \ + T8_ENABLE_VTK not being defined. #endif -#ifdef T8CODE_VTK_MAJOR_VERSION -#error Configuration error: T8CODE_VTK_MAJOR_VERSION is defined despite \ - T8CODE_ENABLE_VTK not being defined. +#ifdef T8_VTK_MAJOR_VERSION +#error Configuration error: T8_VTK_MAJOR_VERSION is defined despite \ + T8_ENABLE_VTK not being defined. #endif -#ifdef T8CODE_VTK_MINOR_VERSION -#error Configuration error: T8CODE_VTK_MINOR_VERSION is defined despite \ - T8CODE_ENABLE_VTK not being defined. +#ifdef T8_VTK_MINOR_VERSION +#error Configuration error: T8_VTK_MINOR_VERSION is defined despite \ + T8_ENABLE_VTK not being defined. +#endif +#endif + +/* Test correct macro dependencies. + * Will throw a compile time error if T8_ENABLE_VTK is 1 + * but one of T8CODE_VTK_VERSION_USED, T8_VTK_MAJOR_VERSION, T8_VTK_MINOR_VERSION is not defined. + */ +#if T8_ENABLE_VTK +#ifndef T8_VTK_VERSION_USED +#error Configuration error: T8_ENABLE_VTK is defined despite \ + T8CODE_VTK_VERSION_USED not being defined. +#endif +#ifndef T8_VTK_MAJOR_VERSION +#error Configuration error: T8_ENABLE_VTK is defined despite \ + T8_VTK_MAJOR_VERSION not being defined. +#endif +#ifndef T8_VTK_MINOR_VERSION +#error Configuration error: T8_ENABLE_VTK is defined despite \ + T8_VTK_MINOR_VERSION not being defined. #endif #endif @@ -72,6 +91,8 @@ TEST (t8_gtest_vtk_linkage, t8_test_vtk_version_number) if (!strcmp (T8_VTK_VERSION_USED, vtk_version)) { t8_debugf ("Using vtk version %s.\n", vtk_version); + t8_debugf ("VTK Major version: %i\n", T8_VTK_MAJOR_VERSION); + t8_debugf ("VTK Minor version: %i\n", T8_VTK_MINOR_VERSION); } #endif } From 7898be74e8b20845a574484b2dd9af1129590e5f Mon Sep 17 00:00:00 2001 From: Johannes Holke Date: Mon, 1 Dec 2025 11:20:15 +0100 Subject: [PATCH 5/5] improve documentation --- src/t8_vtk/t8_vtk_linkage.hxx.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/t8_vtk/t8_vtk_linkage.hxx.in b/src/t8_vtk/t8_vtk_linkage.hxx.in index 5d6b0e765c..7836836fa2 100644 --- a/src/t8_vtk/t8_vtk_linkage.hxx.in +++ b/src/t8_vtk/t8_vtk_linkage.hxx.in @@ -31,9 +31,9 @@ /** Macro that is 1 if we link against VTK on 0 if we don't. */ #cmakedefine01 T8_ENABLE_VTK -/** VTK major version number */ +/** VTK major version number - Only defined if T8_ENABLE_VTK is 1 */ #cmakedefine T8_VTK_MAJOR_VERSION @VTK_MAJOR_VERSION@ -/** VTK minor version number */ +/** VTK minor version number - Only defined if T8_ENABLE_VTK is 1 */ #cmakedefine T8_VTK_MINOR_VERSION @VTK_MINOR_VERSION@ #endif // T8CODE_VTK_LINKAGE_HXX \ No newline at end of file