Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ project(
VERSION "${T8PROJECT_VERSION_MAJOR}.${T8PROJECT_VERSION_MINOR}.${T8PROJECT_VERSION_PATCH}"
)

option( T8PROJECT_ENABLE_VTK "Link against VTK. Must be used if t8code is linked against VTK." OFF )

#
# Enable "make test" to run all the tests
#
Expand All @@ -37,19 +35,13 @@ set(CMAKE_CXX_COMPILER mpicxx)
# -DSC_DIR=PATH,
find_package ( T8CODE REQUIRED)

#
# Find VTK library.
# If t8code is linked against VTK then t8project should link against it as well.
#
if( T8PROJECT_ENABLE_VTK )
find_package( VTK REQUIRED COMPONENTS
IOXML CommonExecutionModel CommonDataModel
IOGeometry IOXMLParser IOParallelXML IOPLY
ParallelMPI FiltersCore vtksys CommonCore zlib IOLegacy)
if(VTK_FOUND)
message("Found VTK")
endif (VTK_FOUND)
endif( T8PROJECT_ENABLE_VTK )
# if t8code is linked against VTK, this project will
# automatically detect it and link against VTK as well.
# We set T8PROJECT_ENABLE_VTK to 1 in order to define our own VTK dependent macros in src/CMakeLists.txt
if (T8CODE_ENABLE_VTK)
message ("t8code links against VTK with version ${T8CODE_VTK_VERSION_USED}")
set (T8PROJECT_ENABLE_VTK "1")
endif ()

# Recurse into the "test" subdirectory. This does not actually
# cause another cmake executable to run. The same process will walk through
Expand Down
28 changes: 9 additions & 19 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ install( FILES

# VTK dependent settings.
if( T8PROJECT_ENABLE_VTK )
# Define T8PROJECT_VTK_MAJOR/MINOR_VERSION to true, such that get defined in t8project_vtk_linkage.hxx
set ( T8PROJECT_VTK_MAJOR_VERSION 1 )
set ( T8PROJECT_VTK_MINOR_VERSION 1 )
set ( T8PROJECT_VTK_VERSION_USED "${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" )
if (NOT ${T8PROJECT_VTK_VERSION_USED} STREQUAL ${T8CODE_VTK_VERSION_USED})
message (FATAL_ERROR "VTK version mismatch. t8code uses ${T8CODE_VTK_VERSION_USED} and this project uses ${T8PROJECT_VTK_VERSION_USED}.")
endif ()
# Set CMake variables for lib target
target_compile_definitions( t8project PUBLIC T8PROJECT_VTK_VERSION_USED="${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" )

# Define T8PROJECT_VTK_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 T8PROJECT_VTK_VERSION_USED in source code and in CMake scripts (triggered by config.cmake.in).
target_compile_definitions( t8project PUBLIC T8PROJECT_VTK_VERSION_USED="${T8PROJECT_VTK_VERSION_USED}" )
target_compile_definitions( t8project PUBLIC T8PROJECT_ENABLE_VTK=1 )
target_include_directories( t8project PUBLIC ${VTK_INCLUDE_DIR} )
target_link_libraries( t8project PUBLIC ${VTK_LIBRARIES} )
Expand All @@ -39,23 +44,8 @@ if( T8PROJECT_ENABLE_VTK )
# install( FILES
# put/header/file/here
# DESTINATION include)
else ()
unset ( T8PROJECT_VTK_MAJOR_VERSION )
unset ( T8PROJECT_VTK_MINOR_VERSION )
endif()

#
# Setup the file t8project_vtk_linkage.hxx and write macros for the VTK version
#
configure_file (t8project_vtk_linkage.hxx.in t8project_vtk_linkage.hxx @ONLY)


# install the automatically created t8project_vtk_linkage.hxx into the include folder
install (FILES
${CMAKE_CURRENT_BINARY_DIR}/t8project_vtk_linkage.hxx
DESTINATION include
)

# Make this package available as a cmake install package, so
# that other projects can find it with find_package.
include( CMakePackageConfigHelpers )
Expand Down
7 changes: 7 additions & 0 deletions src/config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ find_dependency( T8CODE CONFIG )
find_dependency( P4EST CONFIG )
find_dependency( SC CONFIG )

if(T8PROJECT_ENABLE_VTK)
find_dependency(VTK)
# Expose the variable T8PROJECT_VTK_VERSION_USED to external CMake scripts linking against t8code
# for example with find_package ( T8PROJECT REQUIRED )
set (T8PROJECT_VTK_VERSION_USED "@T8PROJECT_VTK_VERSION_USED@")
endif()

include( "${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake" )

check_required_components( @PROJECT_NAME@ )
31 changes: 0 additions & 31 deletions src/t8project_vtk_linkage.hxx.in

This file was deleted.

65 changes: 15 additions & 50 deletions test/t8project_gtest_vtk_linkage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,55 +29,12 @@
* does nothing and is always passed.
*/
#include <iostream>
#include <t8_vtk/t8_vtk_linkage.hxx>
#include <gtest/gtest.h>
#include <t8project_vtk_linkage.hxx>
#if T8PROJECT_ENABLE_VTK
#include <vtkUnstructuredGrid.h>
#include <vtkVersionMacros.h>
#include <vtkNew.h>
#endif

/* Test correct macro dependencies.
* Will throw a compile time error if T8PROJECT_ENABLE_VTK is O
* but T8PROJECT_VTK_VERSION_USED or T8PROJECT_VTK_MAJOR_VERSION or T8PROJECT_VTK_MINOR_VERSION is defined. */
#if not T8PROJECT_ENABLE_VTK
#ifdef T8PROJECT_VTK_VERSION_USED
#error Configuration error: T8PROJECT_VTK_VERSION_USED is defined despite \
T8PROJECT_ENABLE_VTK not being defined.
#endif

#ifdef T8PROJECT_VTK_MAJOR_VERSION
#error Configuration error: T8PROJECT_VTK_MAJOR_VERSION is defined despite \
T8PROJECT_ENABLE_VTK not being defined.
#endif

#ifdef T8PROJECT_VTK_MINOR_VERSION
#error Configuration error: T8PROJECT_VTK_MINOR_VERSION is defined despite \
T8PROJECT_ENABLE_VTK not being defined.
#endif
#endif


/* Test correct macro dependencies.
* Will throw a compile time error if T8PROJECT_ENABLE_VTK is 1
* but one of T8PROJECT_VTK_VERSION_USED, T8PROJECT_VTK_MAJOR_VERSION, T8PROJECT_VTK_MINOR_VERSION is not defined.
*/
#if T8PROJECT_ENABLE_VTK
#ifndef T8PROJECT_VTK_VERSION_USED
#error Configuration error: T8PROJECT_ENABLE_VTK is defined despite \
T8PROJECT_VTK_VERSION_USED not being defined.
#endif
#ifndef T8PROJECT_VTK_MAJOR_VERSION
#error Configuration error: T8PROJECT_ENABLE_VTK is defined despite \
T8PROJECT_VTK_MAJOR_VERSION not being defined.
#endif
#ifndef T8PROJECT_VTK_MINOR_VERSION
#error Configuration error: T8PROJECT_ENABLE_VTK is defined despite \
T8PROJECT_VTK_MINOR_VERSION not being defined.
#endif
#endif

/* Check whether T8PROJECT_VTK_VERSION_USED equals VTK_MAJOR_VERSION.VTK_MINOR_VERSION */
TEST (t8project_gtest_vtk_linkage, t8project_test_vtk_version_number)
{
Expand All @@ -90,20 +47,28 @@ TEST (t8project_gtest_vtk_linkage, t8project_test_vtk_version_number)
if (!strcmp (T8PROJECT_VTK_VERSION_USED, vtk_version)) {
std::cout << "Using vtk version " << vtk_version << std::endl;
}
EXPECT_EQ (T8PROJECT_VTK_MAJOR_VERSION, VTK_MAJOR_VERSION);
EXPECT_EQ (T8PROJECT_VTK_MINOR_VERSION, VTK_MINOR_VERSION);
#endif
}

/* Check whether T8PROJECT_VTK_VERSION_USED equals VTK_MAJOR_VERSION.VTK_MINOR_VERSION */
TEST (t8project_gtest_vtk_linkage, t8code_compatibility)
/* Check whether T8PROJECT_VTK_VERSION_USED equals T8_VTK_VERSION_USED */
TEST (t8project_gtest_vtk_linkage, t8project_and_t8code_use_same_vtk_version)
{
#if T8_ENABLE_VTK
EXPECT_EQ (T8PROJECT_VTK_MAJOR_VERSION, T8_MAJOR_VERSION) << "VTK version mismatch. t8code uses a different VTK major version.\n";
EXPECT_EQ (T8PROJECT_VTK_MINOR_VERSION, T8_MINOR_VERSION) << "VTK version mismatch. t8code uses a different VTK major version.\n";
#if T8PROJECT_ENABLE_VTK
EXPECT_FALSE (strcmp (T8PROJECT_VTK_VERSION_USED, T8_VTK_VERSION_USED))
<< "linked vtk version (" << T8PROJECT_VTK_VERSION_USED << ") does not equal the version t8code was configured with ("
<< T8_VTK_VERSION_USED << ").\n";
#endif
}

TEST (t8project_gtest_vtk_linkage, t8project_uses_vtk_if_t8code_does)
{
#if T8_ENABLE_VTK
#if !T8PROJECT_ENABLE_VTK
ASSERT_FALSE (true) << "t8code was linked against VTK but t8project was not.";
#endif
#endif
}

/* Check whether we can successfully execute VTK code */
TEST (t8project_gtest_vtk_linkage, t8project_test_vtk_linkage)
{
Expand Down