ENH: improve setup for paraview

- removed reliance on ParaView_INCLUDE_DIR variable for conveying the
  major.minor version information when compiling. This can be somewhat
  fragile and also adds variable that is an unnecessary when running
  (only used when compiling).

  Instead use `have_pvplugin_support` function in paraviewFunctions
  wmake script to determine the maj.min from the PV_PLUGIN_PATH
  since we have already defined the output path there with paraview
  maj.min numbering.

  Can now build with paraview from the operating system,
  provided that it has develop headers available.

      ParaView_VERSION=system

  In the etc/config.sh/paraview setup, the maj.min is taken from
  the corresponding `paraview --version` output and used when
  defining the PV_PLUGIN_PATH.

  During the build, the include path taken from `paraview-config`
  for a system installation, from the guess installation root
  of the paraview binary, or ParaView_DIR otherwise.

NB: using a system ParaView for building runTimePostProcessing is unsupported.

- these types of builds appear to have various library resolution issues
  (eg, libexpat not being loaded). Additionally, the build logic does
  not yet cover this type of use case.
This commit is contained in:
Mark Olesen
2018-11-29 01:48:00 +01:00
parent e4b8fedeb1
commit 628b2445fc
14 changed files with 468 additions and 255 deletions

View File

@ -0,0 +1,202 @@
#----------------------------------*-sh-*--------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
# \\/ M anipulation |
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
#
# Script
# paraviewFunctions
#
# Description
# Helper functions for CMake with ParaView.
# Setup of variables for creating ParaView plugins
#
# Requires
# ParaView_DIR (unless system)
# PV_PLUGIN_PATH
#
# Provides Functions
# have_pvplugin_support, no_paraview, echo_paraview
# cmakeVtk, cmakePv
#
# Variables on success
# HAVE_PVPLUGIN_SUPPORT
# FOAM_PV_PLUGIN_LIBBIN
# PARAVIEW_INC_DIR
# PARAVIEW_MAJMIN
#
# Note
# The OpenFOAM plugin must be the first in PV_PLUGIN_PATH and have
# paraview-major.minor encoded in its name.
#
#------------------------------------------------------------------------------
. $WM_PROJECT_DIR/wmake/scripts/sysFunctions # General system functions
. $WM_PROJECT_DIR/wmake/scripts/cmakeFunctions # Require cmake functions
#------------------------------------------------------------------------------
# Reset variables
no_paraview()
{
unset HAVE_PVPLUGIN_SUPPORT FOAM_PV_PLUGIN_LIBBIN
unset PARAVIEW_INC_DIR PARAVIEW_MAJMIN
return 0
}
# Report
echo_paraview()
{
echo "paraview=${HAVE_PVPLUGIN_SUPPORT:-false}"
echo "root=$ParaView_DIR"
echo "include=$PARAVIEW_INC_DIR"
echo "plugin=$FOAM_PV_PLUGIN_LIBBIN"
echo "ver=$PARAVIEW_MAJMIN"
}
# CMake into objectsDir with VTK_DIR dependency
cmakeVtk()
{
cmakeVersioned "VTK_DIR=$VTK_DIR" "$1"
}
# CMake into objectsDir with ParaView_DIR dependency
cmakePv()
{
cmakeVersioned "ParaView_DIR=$ParaView_DIR" "$1"
}
#
# Build library - use sentinel file(s) to handle paraview version changes
#
wmakeLibPv()
{
local depend="ParaView_DIR=$ParaView_DIR"
local sentinel
for libName
do
sentinel=$(sameDependency "$depend" $libName) || \
wclean $libName
wmake $targetType $libName \
&& echo "$depend" > ${sentinel:-/dev/null}
done
}
# Test if a ParaView plugin can be built.
# On success, return 0 and export variables
# -> HAVE_PVPLUGIN_SUPPORT, FOAM_PV_PLUGIN_LIBBIN,
# PARAVIEW_INC_DIR, PARAVIEW_MAJMIN
#
# There are several prerequisites for building plugins
#
have_pvplugin_support()
{
local header settings warn majmin installDir binDir includeDir targetDir
warn="==> skip paraview-plugin"
# Trivial check
command -v cmake > /dev/null 2>&1 || {
echo "$warn (no cmake)"
return 1
}
# The OpenFOAM plugin must be the first in PV_PLUGIN_PATH
# and must have the paraview major+minor version encoded in its name!
# Eg, PV_PLUGIN_PATH="$FOAM_LIBBIN/paraview-5.5"
# Get the first entry from PV_PLUGIN_PATH=dir1;dir2;...
targetDir="${PV_PLUGIN_PATH##;}"
targetDir="${targetDir%%;*}"
# Extract the paraview major+minor version from the directory name
# From /path/paraview-5.6 -> 5.6
majmin=$(echo "${targetDir##*/}" | \
sed -n -e 's/^[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/p')
[ -n "$targetDir" ] || {
echo "$warn (could determine target)"
echo " PV_PLUGIN_PATH=${PV_PLUGIN_PATH:-???}"
return 1
}
[ -n "$majmin" ] || {
echo "$warn (could determine major.minor version)"
return 1
}
# Header/library names
header="pqServerManagerModel.h"
if [ -n "$ParaView_DIR" ]
then
# ParaView_DIR defined. Look for include/
header=$(findFirstFile \
"$ParaView_DIR/include/paraview-$majmin/$header" \
"$ParaView_DIR/include/paraview/$header"
)
else
# No ParaView_DIR defined
# - use location of 'paraview' to guess an equivalent ParaView_DIR
# - assume we can use paraview-config
binDir="$(command -v paraview 2>/dev/null)"
binDir="${binDir%/*}" # Eg, /usr/bin/paraview -> /usr/bin
installDir="${binDir%/*}" # Eg, /usr/bin -> /usr
case "$installDir" in
(/*) # An absolute path
includeDir="$installDir/include" # Eg, /usr -> /usr/include
;;
esac
header=$(findFirstFile \
"$(paraview-config --include 2>/dev/null |sed -ne 's/^ *-I//p')/$header"\
"${includeDir:+$includeDir/paraview-$majmin/$header}" \
"${includeDir:+$includeDir/paraview/$header}" \
/usr/local/include/"paraview-$majmin/$header" \
/usr/local/include/paraview/"$header" \
/usr/include/"paraview-$majmin/$header" \
/usr/include/paraview/"$header" \
)
fi
# Header found?
[ -n "$header" ] || {
[ -n "$warn" ] && echo "$warn (no header)"
return 2
}
export HAVE_PVPLUGIN_SUPPORT=true
export FOAM_PV_PLUGIN_LIBBIN="$targetDir"
export PARAVIEW_INC_DIR="${header%/*}" # Basename
export PARAVIEW_MAJMIN="$majmin"
return 0 # success
}
# Force reset of old variables
no_paraview
# Testing
if [ "$1" = "-test" ]
then
have_pvplugin_support
echo_paraview
fi
#------------------------------------------------------------------------------