diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f1f44b9dd..89f5f284a7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -84,6 +84,11 @@ 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 ( 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} ) @@ -100,8 +105,26 @@ 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 () + # 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 ( T8_VTK_MAJOR_VERSION ) + unset ( T8_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 +271,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..7836836fa2 --- /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 T8_ENABLE_VTK +/** VTK major version number - Only defined if T8_ENABLE_VTK is 1 */ +#cmakedefine T8_VTK_MAJOR_VERSION @VTK_MAJOR_VERSION@ +/** 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 diff --git a/test/t8_gtest_vtk_linkage.cxx b/test/t8_gtest_vtk_linkage.cxx index d1fdf96b6d..69f4790549 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,13 +38,42 @@ #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 + * 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: T8_VTK_VERSION_USED is defined despite \ T8_ENABLE_VTK not being defined. #endif + +#ifdef T8_VTK_MAJOR_VERSION +#error Configuration error: T8_VTK_MAJOR_VERSION is defined despite \ + T8_ENABLE_VTK not being defined. +#endif + +#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 /* Check whether T8_VTK_VERSION_USED equals VTK_MAJOR_VERSION.VTK_MINOR_VERSION */ @@ -52,11 +82,17 @@ 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); + t8_debugf ("VTK Major version: %i\n", T8_VTK_MAJOR_VERSION); + t8_debugf ("VTK Minor version: %i\n", T8_VTK_MINOR_VERSION); } #endif }