From 1609b7fd6f9295461ab11fbefd6561423911ecd2 Mon Sep 17 00:00:00 2001 From: Tu Nguyen Xuan Date: Wed, 14 Oct 2026 09:45:52 +0200 Subject: [PATCH 1/2] Added Version Match in linkage test, as well as OCC version macros --- src/CMakeLists.txt | 6 ++++++ src/config.cmake.in | 7 +++++++ test/t8_gtest_occ_linkage.cxx | 38 ++++++++++++++++++++++++++++++----- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5225ccc1a1..d1d1cf7292 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -91,6 +91,12 @@ if( T8CODE_ENABLE_VTK ) endif() if( T8CODE_ENABLE_OCC ) + string (REGEX MATCH "^[0-9]+\\.[0-9]+" + T8CODE_OCC_VERSION_USED "${OCC_VERSION_STRING}") + # Define T8_OCC_VERSION_USED for internal and external use in source files. + # Note, external libraries linking against t8code (i.e. using find_package ( T8CODE REQUIRED )) can + # use T8_OCC_VERSION_USED in source code and T8CODE_VTK_VERSION_USED (defined in config.cmake.in) in their CMake scripts. + target_compile_definitions( T8 PUBLIC T8_OCC_VERSION_USED="${T8CODE_OCC_VERSION_USED}" ) target_compile_definitions( T8 PUBLIC T8_ENABLE_OCC=1 ) target_include_directories( T8 SYSTEM PUBLIC ${OpenCASCADE_INCLUDE_DIR} ) target_link_libraries( T8 PUBLIC ${OpenCASCADE_LIBRARIES} ) diff --git a/src/config.cmake.in b/src/config.cmake.in index c8fa76969b..fd3d375151 100644 --- a/src/config.cmake.in +++ b/src/config.cmake.in @@ -25,6 +25,13 @@ if(T8CODE_ENABLE_VTK) set (T8CODE_VTK_VERSION_USED "@T8CODE_VTK_VERSION_USED@") endif() +if (T8CODE_ENABLE_OCC) + find_dependency(OCC) + # Expose the variable T8CODE_OCC_VERSION_USED to external CMake scripts linking against t8code + # for example with find_package ( T8CODE REQUIRED ) + set (T8CODE_OCC_VERSION_USED "@T8CODE_OCC_VERSION_USED@") +endif() + include( "${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake" ) check_required_components( @PROJECT_NAME@ ) diff --git a/test/t8_gtest_occ_linkage.cxx b/test/t8_gtest_occ_linkage.cxx index 1ab115ae4f..e83f41e73e 100644 --- a/test/t8_gtest_occ_linkage.cxx +++ b/test/t8_gtest_occ_linkage.cxx @@ -31,16 +31,44 @@ #include #if T8_ENABLE_OCC #include +#include #endif -/* Check whether we can successfully execute VTK code */ -TEST (t8_test_occ_linkage, test_gp_Pnt) +/* Test correct macro dependencies. + * Will throw a compile time error if T8_OCC_VERSION_USED + * is defined but T8_ENABLE_OCC is not. */ +#ifndef T8_ENABLE_OCC +#ifdef T8_OCC_VERSION_USED +#error Configuration error: T8_OCC_VERSION_USED is defined despite \ + T8_ENABLE_OCC not being defined. +#endif +#endif + +/* Check whether T8_OCC_VERSION_USED equals OCC_VERSION_STRING */ +TEST (t8_gtest_occ_linkage, t8_test_occ_version_number) { #if T8_ENABLE_OCC + /* Compare the macro generated at configuration time with the linked runtime string */ + ASSERT_FALSE (strcmp (T8_OCC_VERSION_USED, OCC_VERSION_STRING)) + << "Linked OCC version (" << OCC_VERSION_STRING << ") does not equal the version t8code was configured with (" + << T8_OCC_VERSION_USED << ").\n"; + + if (!strcmp (T8_OCC_VERSION_USED, OCC_VERSION_STRING)) { + t8_debugf ("Using OCC version %s.\n", OCC_VERSION_STRING); + } +#endif +} - EXPECT_NO_THROW (gp_Pnt pnt = gp_Pnt (); pnt.SetX (1);); - t8_global_productionf ("Successfully created occ gp_Pnt object.\n"); +/* Check whether we can successfully execute OCC code */ +TEST (t8_gtest_occ_linkage, test_gp_Pnt) +{ +#if T8_ENABLE_OCC + EXPECT_NO_THROW ({ + gp_Pnt pnt = gp_Pnt (); + pnt.SetX (1); + }); + t8_debugf ("Successfully created occ gp_Pnt object.\n"); #else - t8_global_productionf ("This version of t8code is not compiled with occ support.\n"); + t8_debugf ("This version of t8code is not compiled with occ support.\n"); #endif } From cd44e195480c03dec251bd7557bb52e016708dc4 Mon Sep 17 00:00:00 2001 From: Tu Nguyen Xuan Date: Fri, 16 Oct 2026 17:06:49 +0200 Subject: [PATCH 2/2] Applied requested changes --- src/CMakeLists.txt | 2 +- src/config.cmake.in | 3 ++- test/t8_gtest_occ_linkage.cxx | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d1d1cf7292..900a44a261 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -95,7 +95,7 @@ if( T8CODE_ENABLE_OCC ) T8CODE_OCC_VERSION_USED "${OCC_VERSION_STRING}") # Define T8_OCC_VERSION_USED for internal and external use in source files. # Note, external libraries linking against t8code (i.e. using find_package ( T8CODE REQUIRED )) can - # use T8_OCC_VERSION_USED in source code and T8CODE_VTK_VERSION_USED (defined in config.cmake.in) in their CMake scripts. + # use T8_OCC_VERSION_USED in source code and T8CODE_OCC_VERSION_USED (defined in config.cmake.in) in their CMake scripts. target_compile_definitions( T8 PUBLIC T8_OCC_VERSION_USED="${T8CODE_OCC_VERSION_USED}" ) target_compile_definitions( T8 PUBLIC T8_ENABLE_OCC=1 ) target_include_directories( T8 SYSTEM PUBLIC ${OpenCASCADE_INCLUDE_DIR} ) diff --git a/src/config.cmake.in b/src/config.cmake.in index fd3d375151..aa6d1c2c11 100644 --- a/src/config.cmake.in +++ b/src/config.cmake.in @@ -13,6 +13,7 @@ set( T8CODE_BUILD_MESH_HANDLE @T8CODE_BUILD_MESH_HANDLE@ ) set( T8CODE_ENABLE_MPI @T8CODE_ENABLE_MPI@ ) set( T8CODE_ENABLE_VTK @T8CODE_ENABLE_VTK@ ) +set( T8CODE_ENABLE_OCC @T8CODE_ENABLE_OCC@ ) set( T8CODE_USE_SYSTEM_SC @T8CODE_USE_SYSTEM_SC@ ) set( T8CODE_USE_SYSTEM_P4EST @T8CODE_USE_SYSTEM_P4EST@ ) @@ -26,7 +27,7 @@ if(T8CODE_ENABLE_VTK) endif() if (T8CODE_ENABLE_OCC) - find_dependency(OCC) + find_dependency(OpenCASCADE) # Expose the variable T8CODE_OCC_VERSION_USED to external CMake scripts linking against t8code # for example with find_package ( T8CODE REQUIRED ) set (T8CODE_OCC_VERSION_USED "@T8CODE_OCC_VERSION_USED@") diff --git a/test/t8_gtest_occ_linkage.cxx b/test/t8_gtest_occ_linkage.cxx index e83f41e73e..93788331e2 100644 --- a/test/t8_gtest_occ_linkage.cxx +++ b/test/t8_gtest_occ_linkage.cxx @@ -48,7 +48,7 @@ TEST (t8_gtest_occ_linkage, t8_test_occ_version_number) { #if T8_ENABLE_OCC - /* Compare the macro generated at configuration time with the linked runtime string */ + /* Compare the macro generated at configuration time with the linked compile time string */ ASSERT_FALSE (strcmp (T8_OCC_VERSION_USED, OCC_VERSION_STRING)) << "Linked OCC version (" << OCC_VERSION_STRING << ") does not equal the version t8code was configured with (" << T8_OCC_VERSION_USED << ").\n";