Commit 53a6d8cd authored by Mark Olesen's avatar Mark Olesen
Browse files

COMP: fix VTK9 module linkage for runTimePostProcessing

- simpler version checks

- compile into mpi-specific target directories for better support of
  different MPI vendors

- use MPI hint from MPI_ARCH_PATH and OSMESA hint from MESA_ARCH_PATH.
  Set internally as env variable to allow further override via a CMake
  variable.
parent 7b639ccf
......@@ -3,10 +3,17 @@ cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/wmake/scripts/wmakeFunctions # Require wmake functions
#------------------------------------------------------------------------------
# This cleanup handles both cmake runTimePostProcessing and the dummy version
# Remove library files (including dummy)
# - regular and mpi-specific locations
for libDir in "" "$FOAM_MPI"
do
rm -f "$FOAM_LIBBIN/$libDir"/librunTimePostProcessing*
rm -f "$FOAM_SITE_LIBBIN/$libDir"/librunTimePostProcessing*
rm -f "$FOAM_USER_LIBBIN/$libDir"/librunTimePostProcessing*
done
# Cleanup library files with .so version endings
rm -f $FOAM_LIBBIN/librunTimePostProcessing*
# This cleanup handles both cmake runTimePostProcessing and the dummy version
# Cleanup generated files - remove entire top-level
removeObjectDir "$PWD"
......
#-----------------------------------------------------------------------------
if(${VTK_VERSION_MAJOR} LESS 6)
if(${VTK_MAJOR_VERSION} LESS 6)
message(FATAL_ERROR " VTK version is too old - requires VTK6 or newer")
endif()
#------------------------------------------------------------------------------
unset(FOAM_USING_VTK_MPI)
# Modules required by this project
set(PROJECT_REQUIRED_MODULES
VTK::FiltersCore
VTK::FiltersGeometry
VTK::FiltersSources
VTK::IOGeometry
VTK::IOImage
VTK::IOLegacy
VTK::IOXML
VTK::ParallelCore
VTK::ParallelMPI
VTK::RenderingAnnotation
VTK::RenderingCore
VTK::RenderingParallel
)
#-----------------------------------------------------------------------------
unset(LINK_LIBRARIES)
unset(FOAM_USING_VTK_MPI)
# Test some characteristics
# Required VTK modules/libraries
unset(PROJECT_VTK_MODULES)
if (${ParaView_VERSION} VERSION_GREATER_EQUAL 5.7)
if (TARGET "VTK::ParallelMPI")
set(FOAM_USING_VTK_MPI TRUE)
endif()
elseif (${VTK_VERSION} LESS 8.90)
# Older way to test for VTK MPI
if (${OLDVTK_NO_MODULES})
# No modules for older VTK. Reuse for MPI handling
unset(PROJECT_REQUIRED_MODULES)
message("Manual test for VTK MPI (old vtk version)")
set(test_file ${CMAKE_CURRENT_BINARY_DIR}/check_mpi.cxx)
file(WRITE ${test_file}
"#include <vtkMPICommunicator.h>\n"
"int main() {\n"
" vtkMPICommunicator* p = vtkMPICommunicator::New();\n"
" p->Delete();\n"
" return 0;\n"
"}"
"int main(){auto* p = vtkMPICommunicator::New(); p->Delete(); return 0;}"
)
try_compile(FOAM_USING_VTK_MPI
${CMAKE_CURRENT_BINARY_DIR} ${test_file}
......@@ -33,23 +46,30 @@ elseif (${VTK_VERSION} LESS 8.90)
)
if (FOAM_USING_VTK_MPI)
set(PROJECT_REQUIRED_MODULES vtkParallelMPI)
include(vtkMPI)
set(LINK_LIBRARIES vtkParallelMPI)
endif()
elseif (${ParaView_VERSION} LESS_EQUAL 0)
#TODO if (TARGET "ParallelMPI")
#TODO set(FOAM_USING_VTK_MPI TRUE)
#TODO endif()
endif()
if (TARGET VTK::ParallelMPI)
set(FOAM_USING_VTK_MPI TRUE)
endif()
#-----------------------------------------------------------------------------
# Build directly into library target. FOAM_MPI env for some versioning
set(FOAM_TARGET_LIBDIR lib)
if (FOAM_USING_VTK_MPI)
add_definitions(-DFOAM_USING_VTK_MPI)
message("Building with VTK MPI")
if (DEFINED ENV{FOAM_MPI})
set(FOAM_TARGET_LIBDIR "lib/$ENV{FOAM_MPI}")
endif()
message("Library target = ${FOAM_TARGET_LIBDIR} (building with VTK MPI)")
else()
message(WARNING "==== Building without VTK MPI ====")
endif()
message("...")
#-----------------------------------------------------------------------------
......@@ -99,18 +119,26 @@ set_target_properties(
runTimePostProcessing
PROPERTIES
VERSION ${VTK_VERSION}
SOVERSION ${VTK_VERSION_MAJOR}
SOVERSION ${VTK_MAJOR_VERSION}
)
if (NOT ${OLDVTK_NO_MODULES})
vtk_module_autoinit(
TARGETS runTimePostProcessing
MODULES
${PROJECT_REQUIRED_MODULES}
)
endif()
target_link_libraries(
runTimePostProcessing
PRIVATE
${PROJECT_REQUIRED_MODULES}
${VTK_LIBRARIES}
${LINK_LIBRARIES}
${OPENFOAM_LIBNAMES}
)
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION lib)
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION ${FOAM_TARGET_LIBDIR})
## Record VTK version for general bookkeeping
# file(WRITE
......
......@@ -10,19 +10,25 @@ set(OPENFOAM_INCLUDE_DIRS
${LIB_SRC}/OpenFOAM/include
${LIB_SRC}/OpenFOAM/lnInclude
${LIB_SRC}/OSspecific/${WM_OSTYPE}/lnInclude
${LIB_SRC}/finiteVolume/lnInclude
${LIB_SRC}/fileFormats/lnInclude
${LIB_SRC}/surfMesh/lnInclude
${LIB_SRC}/meshTools/lnInclude
${LIB_SRC}/conversion/lnInclude
${LIB_SRC}/finiteArea/lnInclude
${LIB_SRC}/finiteVolume/lnInclude
${LIB_SRC}/sampling/lnInclude
)
# OpenFOAM libraries (from FOAM_LIBBIN)
set(OPENFOAM_LIBNAMES
OpenFOAM
finiteVolume
fileFormats
surfMesh
meshTools
conversion
finiteArea
finiteVolume
sampling
)
#-----------------------------------------------------------------------------
......@@ -12,70 +12,89 @@ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
"In-source builds disallowed. Use a separate build directory")
endif()
# MPI hint: prefer same MPI that OpenFOAM is using
if (IS_DIRECTORY "$ENV{MPI_ARCH_PATH}")
set(ENV{MPI_HOME} "$ENV{MPI_ARCH_PATH}")
endif()
# Take OSMESA hint from OpenFOAM MESA_ARCH_PATH
if (IS_DIRECTORY "$ENV{MESA_ARCH_PATH}")
set(ENV{OSMESA_ROOT} "$ENV{MESA_ARCH_PATH}")
endif()
#-----------------------------------------------------------------------------
# Simple discovery and sanity checks
set(ParaView_VERSION 0)
unset(VTK_VERSION)
unset(VTK_VERSION_MAJOR)
set(VTK_VERSION 0)
if (EXISTS "$ENV{VTK_DIR}")
message("Building with VTK from $ENV{VTK_DIR}")
find_package(VTK REQUIRED)
elseif (EXISTS "$ENV{ParaView_DIR}")
message("Building with Paraview from $ENV{ParaView_DIR}")
find_package(ParaView REQUIRED)
if (${ParaView_VERSION} VERSION_GREATER_EQUAL 5.7)
find_package(ParaView REQUIRED
OPTIONAL_COMPONENTS VTK::ParallelMPI)
endif()
else()
message(FATAL_ERROR "VTK not found using VTK_DIR or ParaView_DIR")
endif()
if (VTK_USE_FILE)
message("VTK from ${VTK_USE_FILE}")
include(${VTK_USE_FILE})
#-----------------------------------------------------------------------------
# Earlier versions without modules and/or VTK_VERSION
#
# ParaView = 5.6.3 (VTK equiv 8.2.0)
# ParaView = 5.7.0 (VTK 8.90.0)
# ParaView = 5.8.1 (VTK 8.90.0)
# ParaView = 5.9.0 (VTK 9.0.1)
# VTK has modules yes/no.
# Added in VTK9 but also in VTK-8.90 (paraview flavour for 5.7, 5.8)
set(OLDVTK_NO_MODULES FALSE)
if (("${VTK_MAJOR_VERSION}" LESS 8) OR
(("${VTK_MAJOR_VERSION}" EQUAL 8) AND ("${VTK_MINOR_VERSION}" LESS 10)))
set(OLDVTK_NO_MODULES TRUE)
endif()
include(GNUInstallDirs)
if (VTK_MAJOR_VERSION AND NOT VTK_VERSION)
set(VTK_VERSION
"${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}.${VTK_BUILD_VERSION}")
message("Synthesized VTK version: ${VTK_VERSION}")
endif()
#-----------------------------------------------------------------------------
# Handle name changes (eg, VTK_MAJOR_VERSION to VTK_VERSION_MAJOR etc.)
if (VTK_MAJOR_VERSION AND NOT VTK_VERSION_MAJOR)
message("Found older VTK version naming")
set(VTK_VERSION_MAJOR ${VTK_MAJOR_VERSION})
set(VTK_VERSION_MINOR ${VTK_MINOR_VERSION})
set(VTK_VERSION_PATCH ${VTK_BUILD_VERSION})
if (NOT VTK_VERSION)
set(
VTK_VERSION
"${VTK_VERSION_MAJOR}.${VTK_VERSION_MINOR}.${VTK_VERSION_PATCH}"
)
message("Synthesized VTK version: " ${VTK_VERSION})
endif()
endif()
if (${ParaView_VERSION} GREATER 0)
# Newer VTK - try to load optional MPI?
if (${VTK_VERSION} GREATER 8.2)
find_package(VTK REQUIRED OPTIONAL_COMPONENTS ParallelMPI)
# New ParaView/VTK: load optional MPI via VTK
# Old ParaView/VTK: has VTK_USE_FILE, manually detect ParallelMPI
if ("${OLDVTK_NO_MODULES}")
# No modules etc - use old method for loading things
if (VTK_USE_FILE)
message("VTK from ${VTK_USE_FILE}")
include(${VTK_USE_FILE})
endif()
else()
# Load optional components via modules
if (${ParaView_VERSION})
find_package(ParaView REQUIRED
OPTIONAL_COMPONENTS VTK::ParallelMPI)
else()
find_package(VTK REQUIRED
OPTIONAL_COMPONENTS ParallelMPI)
endif()
endif()
#-----------------------------------------------------------------------------
include(GNUInstallDirs)
message("================")
message("Using OpenFOAM = $ENV{WM_PROJECT_DIR}")
if (${ParaView_VERSION} GREATER 0)
if (${ParaView_VERSION})
message("Using ParaView = ${ParaView_VERSION} (VTK ${VTK_VERSION})")
else()
message("Using VTK ${VTK_VERSION}")
endif()
if (${MPI_C_FOUND})
message("MPI include-dir= ${MPI_C_INCLUDE_DIRS}")
endif()
include(CMakeLists-OpenFOAM.txt)
include(CMakeLists-library.txt)
......
runTimePostProcessingDummy.C
LIB = $(FOAM_LIBBIN)/librunTimePostProcessing
LIB = $(FOAM_MODULE_LIBBIN)/librunTimePostProcessing
sinclude $(GENERAL_RULES)/module-path-user
/* Failsafe - user location */
ifeq (,$(strip $(FOAM_MODULE_LIBBIN)))
FOAM_MODULE_LIBBIN = $(FOAM_USER_LIBBIN)
endif
EXE_INC =
LIB_LIBS =
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment