diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 04a172f568..c40a3130fb 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_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} ) target_link_libraries( T8 PUBLIC ${OpenCASCADE_LIBRARIES} ) diff --git a/src/config.cmake.in b/src/config.cmake.in index c8fa76969b..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@ ) @@ -25,6 +26,13 @@ if(T8CODE_ENABLE_VTK) set (T8CODE_VTK_VERSION_USED "@T8CODE_VTK_VERSION_USED@") endif() +if (T8CODE_ENABLE_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@") +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..93788331e2 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 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"; + + 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 }