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 ...@@ -3,10 +3,17 @@ cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/wmake/scripts/wmakeFunctions # Require wmake functions . ${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 # This cleanup handles both cmake runTimePostProcessing and the dummy version
rm -f $FOAM_LIBBIN/librunTimePostProcessing*
# Cleanup generated files - remove entire top-level # Cleanup generated files - remove entire top-level
removeObjectDir "$PWD" 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") message(FATAL_ERROR " VTK version is too old - requires VTK6 or newer")
endif() 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) 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") if (${OLDVTK_NO_MODULES})
set(FOAM_USING_VTK_MPI TRUE) # No modules for older VTK. Reuse for MPI handling
endif() unset(PROJECT_REQUIRED_MODULES)
elseif (${VTK_VERSION} LESS 8.90)
# Older way to test for VTK MPI message("Manual test for VTK MPI (old vtk version)")
set(test_file ${CMAKE_CURRENT_BINARY_DIR}/check_mpi.cxx)
set(test_file ${CMAKE_CURRENT_BINARY_DIR}/check_mpi.cxx) file(WRITE ${test_file}
file(WRITE ${test_file} "#include <vtkMPICommunicator.h>\n"
"#include <vtkMPICommunicator.h>\n" "int main(){auto* p = vtkMPICommunicator::New(); p->Delete(); return 0;}"
"int main() {\n" )
" vtkMPICommunicator* p = vtkMPICommunicator::New();\n" try_compile(FOAM_USING_VTK_MPI
" p->Delete();\n" ${CMAKE_CURRENT_BINARY_DIR} ${test_file}
" return 0;\n" LINK_LIBRARIES vtkParallelMPI
"}" CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${VTK_INCLUDE_DIRS}"
) )
try_compile(FOAM_USING_VTK_MPI
${CMAKE_CURRENT_BINARY_DIR} ${test_file} if (FOAM_USING_VTK_MPI)
LINK_LIBRARIES vtkParallelMPI set(PROJECT_REQUIRED_MODULES vtkParallelMPI)
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${VTK_INCLUDE_DIRS}" include(vtkMPI)
) endif()
endif()
if (FOAM_USING_VTK_MPI)
include(vtkMPI) if (TARGET VTK::ParallelMPI)
set(LINK_LIBRARIES vtkParallelMPI) set(FOAM_USING_VTK_MPI TRUE)
endif()
elseif (${ParaView_VERSION} LESS_EQUAL 0)
#TODO if (TARGET "ParallelMPI")
#TODO set(FOAM_USING_VTK_MPI TRUE)
#TODO endif()
endif() endif()
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Build directly into library target. FOAM_MPI env for some versioning
set(FOAM_TARGET_LIBDIR lib)
if (FOAM_USING_VTK_MPI) if (FOAM_USING_VTK_MPI)
add_definitions(-DFOAM_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() else()
message(WARNING "==== Building without VTK MPI ====") message(WARNING "==== Building without VTK MPI ====")
endif() endif()
message("...")
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
...@@ -99,18 +119,26 @@ set_target_properties( ...@@ -99,18 +119,26 @@ set_target_properties(
runTimePostProcessing runTimePostProcessing
PROPERTIES PROPERTIES
VERSION ${VTK_VERSION} 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( target_link_libraries(
runTimePostProcessing runTimePostProcessing
PRIVATE
${PROJECT_REQUIRED_MODULES}
${VTK_LIBRARIES} ${VTK_LIBRARIES}
${LINK_LIBRARIES}
${OPENFOAM_LIBNAMES} ${OPENFOAM_LIBNAMES}
) )
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION ${FOAM_TARGET_LIBDIR})
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION lib)
## Record VTK version for general bookkeeping ## Record VTK version for general bookkeeping
# file(WRITE # file(WRITE
......
...@@ -10,19 +10,25 @@ set(OPENFOAM_INCLUDE_DIRS ...@@ -10,19 +10,25 @@ set(OPENFOAM_INCLUDE_DIRS
${LIB_SRC}/OpenFOAM/include ${LIB_SRC}/OpenFOAM/include
${LIB_SRC}/OpenFOAM/lnInclude ${LIB_SRC}/OpenFOAM/lnInclude
${LIB_SRC}/OSspecific/${WM_OSTYPE}/lnInclude ${LIB_SRC}/OSspecific/${WM_OSTYPE}/lnInclude
${LIB_SRC}/finiteVolume/lnInclude
${LIB_SRC}/fileFormats/lnInclude ${LIB_SRC}/fileFormats/lnInclude
${LIB_SRC}/surfMesh/lnInclude ${LIB_SRC}/surfMesh/lnInclude
${LIB_SRC}/meshTools/lnInclude
${LIB_SRC}/conversion/lnInclude ${LIB_SRC}/conversion/lnInclude
${LIB_SRC}/finiteArea/lnInclude
${LIB_SRC}/finiteVolume/lnInclude
${LIB_SRC}/sampling/lnInclude
) )
# OpenFOAM libraries (from FOAM_LIBBIN) # OpenFOAM libraries (from FOAM_LIBBIN)
set(OPENFOAM_LIBNAMES set(OPENFOAM_LIBNAMES
OpenFOAM OpenFOAM
finiteVolume
fileFormats fileFormats
surfMesh surfMesh
meshTools
conversion conversion
finiteArea
finiteVolume
sampling
) )
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
...@@ -12,70 +12,89 @@ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) ...@@ -12,70 +12,89 @@ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
"In-source builds disallowed. Use a separate build directory") "In-source builds disallowed. Use a separate build directory")
endif() 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 # Simple discovery and sanity checks
set(ParaView_VERSION 0) set(ParaView_VERSION 0)
unset(VTK_VERSION) set(VTK_VERSION 0)
unset(VTK_VERSION_MAJOR)
if (EXISTS "$ENV{VTK_DIR}") if (EXISTS "$ENV{VTK_DIR}")
message("Building with VTK from $ENV{VTK_DIR}") message("Building with VTK from $ENV{VTK_DIR}")
find_package(VTK REQUIRED) find_package(VTK REQUIRED)
elseif (EXISTS "$ENV{ParaView_DIR}") elseif (EXISTS "$ENV{ParaView_DIR}")
message("Building with Paraview from $ENV{ParaView_DIR}") message("Building with Paraview from $ENV{ParaView_DIR}")
find_package(ParaView REQUIRED) find_package(ParaView REQUIRED)
if (${ParaView_VERSION} VERSION_GREATER_EQUAL 5.7)
find_package(ParaView REQUIRED
OPTIONAL_COMPONENTS VTK::ParallelMPI)
endif()
else() else()
message(FATAL_ERROR "VTK not found using VTK_DIR or ParaView_DIR") message(FATAL_ERROR "VTK not found using VTK_DIR or ParaView_DIR")
endif() endif()
if (VTK_USE_FILE) #-----------------------------------------------------------------------------
message("VTK from ${VTK_USE_FILE}") # Earlier versions without modules and/or VTK_VERSION
include(${VTK_USE_FILE}) #
# 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() 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) # New ParaView/VTK: load optional MPI via VTK
# Newer VTK - try to load optional MPI? # Old ParaView/VTK: has VTK_USE_FILE, manually detect ParallelMPI
if (${VTK_VERSION} GREATER 8.2)
find_package(VTK REQUIRED OPTIONAL_COMPONENTS 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() 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() endif()
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
include(GNUInstallDirs)
message("================") message("================")
message("Using OpenFOAM = $ENV{WM_PROJECT_DIR}") message("Using OpenFOAM = $ENV{WM_PROJECT_DIR}")
if (${ParaView_VERSION} GREATER 0) if (${ParaView_VERSION})
message("Using ParaView = ${ParaView_VERSION} (VTK ${VTK_VERSION})") message("Using ParaView = ${ParaView_VERSION} (VTK ${VTK_VERSION})")
else() else()
message("Using VTK ${VTK_VERSION}") message("Using VTK ${VTK_VERSION}")
endif() endif()
if (${MPI_C_FOUND})
message("MPI include-dir= ${MPI_C_INCLUDE_DIRS}")
endif()
include(CMakeLists-OpenFOAM.txt) include(CMakeLists-OpenFOAM.txt)
include(CMakeLists-library.txt) include(CMakeLists-library.txt)
......
runTimePostProcessingDummy.C 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 = EXE_INC =
LIB_LIBS = 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