From 628b2445fc1e8a4d2c167c4fdb60bd3146f42729 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 29 Nov 2018 01:48:00 +0100 Subject: [PATCH] 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. --- .../graphics/PVReaders/Allwclean | 8 +- .../graphics/PVReaders/Allwmake | 36 ++-- .../PVFoamReader/CMakeLists-Project.txt | 2 +- .../PVblockMeshReader/CMakeLists-Project.txt | 2 +- .../graphics/PVReaders/foamPv/Make/options | 6 +- .../graphics/PVReaders/vtkPVFoam/Make/options | 8 +- .../PVReaders/vtkPVblockMesh/Make/options | 8 +- bin/paraFoam | 99 ++++----- etc/config.csh/paraview | 105 ++++++--- etc/config.sh/paraview | 142 +++++++----- .../graphics/runTimePostProcessing/Allwclean | 6 +- wmake/rules/General/paraview | 8 - wmake/scripts/cmakeFunctions | 91 +++----- wmake/scripts/paraviewFunctions | 202 ++++++++++++++++++ 14 files changed, 468 insertions(+), 255 deletions(-) delete mode 100644 wmake/rules/General/paraview create mode 100644 wmake/scripts/paraviewFunctions diff --git a/applications/utilities/postProcessing/graphics/PVReaders/Allwclean b/applications/utilities/postProcessing/graphics/PVReaders/Allwclean index 7a429617b8..f9777f02d2 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/Allwclean +++ b/applications/utilities/postProcessing/graphics/PVReaders/Allwclean @@ -1,10 +1,8 @@ #!/bin/sh -cd ${0%/*} || exit 1 # Run from this directory +cd ${0%/*} || exit 1 # Run from this directory +. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions # Source wmake functions -# Source the wmake functions -. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions - -# Cleanup OpenFOAM libraries +# Cleanup libraries wclean libso foamPv wclean libso vtkPVblockMesh wclean libso vtkPVFoam diff --git a/applications/utilities/postProcessing/graphics/PVReaders/Allwmake b/applications/utilities/postProcessing/graphics/PVReaders/Allwmake index ade3a26379..babf98f51a 100755 --- a/applications/utilities/postProcessing/graphics/PVReaders/Allwmake +++ b/applications/utilities/postProcessing/graphics/PVReaders/Allwmake @@ -2,7 +2,7 @@ cd ${0%/*} || exit 1 # Run from this directory export WM_CONTINUE_ON_ERROR=true # Optional unit . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments -. $WM_PROJECT_DIR/wmake/scripts/cmakeFunctions # The CMake functions +. $WM_PROJECT_DIR/wmake/scripts/paraviewFunctions # CMake and PV functions # ----------------------------------------------------------------------------- @@ -13,31 +13,19 @@ warnIncomplete() echo } -# major version as per paraview include directory: -# Eg, "PREFIX/include/paraview-5.0" -> "5.0" -major="${ParaView_INCLUDE_DIR##*-}" +if have_pvplugin_support +then +( + wmakeLibPv foamPv + wmakeLibPv vtkPVblockMesh + wmakeLibPv vtkPVFoam -case "$major" in -[45].[0-9]*) - if canBuildPlugin + if [ "$targetType" != objects ] then - ( - wmakeLibPv foamPv - wmakeLibPv vtkPVblockMesh - wmakeLibPv vtkPVFoam - - if [ "$targetType" != objects ] - then - cmakePv $PWD/PVblockMeshReader || warnIncomplete "BlockMesh" - cmakePv $PWD/PVFoamReader || warnIncomplete "OpenFOAM" - fi - ) + cmakePv $PWD/PVblockMeshReader || warnIncomplete "BlockMesh" + cmakePv $PWD/PVFoamReader || warnIncomplete "OpenFOAM" fi - ;; -*) - echo "==> skip build of ParaView plugins" - echo " include directory was for paraview major version '${major:-none}'" - ;; -esac +) +fi #------------------------------------------------------------------------------ diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/CMakeLists-Project.txt b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/CMakeLists-Project.txt index 0adeba5198..9b8673260d 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/CMakeLists-Project.txt +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/CMakeLists-Project.txt @@ -26,7 +26,7 @@ set(OPENFOAM_LIBRARIES # Set output library destination to plugin directory set( - LIBRARY_OUTPUT_PATH $ENV{PV_PLUGIN_PATH} + LIBRARY_OUTPUT_PATH $ENV{FOAM_PV_PLUGIN_LIBBIN} CACHE INTERNAL "Single output directory for building all libraries." ) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/CMakeLists-Project.txt b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/CMakeLists-Project.txt index 544f3a5478..1b35d22bbe 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/CMakeLists-Project.txt +++ b/applications/utilities/postProcessing/graphics/PVReaders/PVblockMeshReader/CMakeLists-Project.txt @@ -20,7 +20,7 @@ set(OPENFOAM_LIBRARIES # Set output library destination to plugin directory set( - LIBRARY_OUTPUT_PATH $ENV{PV_PLUGIN_PATH} + LIBRARY_OUTPUT_PATH $ENV{FOAM_PV_PLUGIN_LIBBIN} CACHE INTERNAL "Single output directory for building all libraries." ) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/options b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/options index bf52ca3659..b13d6d0a9c 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/options +++ b/applications/utilities/postProcessing/graphics/PVReaders/foamPv/Make/options @@ -1,11 +1,9 @@ -sinclude $(GENERAL_RULES)/paraview - EXE_INC = \ ${c++LESSWARN} \ -I$(LIB_SRC)/conversion/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \ - -I$(ParaView_INCLUDE_DIR) \ - -I$(ParaView_INCLUDE_DIR)/vtkkwiml + -I$(PARAVIEW_INC_DIR) \ + -I$(PARAVIEW_INC_DIR)/vtkkwiml LIB_LIBS = \ $(GLIBS) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/Make/options b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/Make/options index ec74dc17d9..1d993b65d7 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/Make/options +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/Make/options @@ -1,5 +1,3 @@ -sinclude $(GENERAL_RULES)/paraview - EXE_INC = \ ${c++LESSWARN} \ -I$(LIB_SRC)/meshTools/lnInclude \ @@ -9,8 +7,8 @@ EXE_INC = \ -I$(LIB_SRC)/lagrangian/basic/lnInclude \ -I$(LIB_SRC)/fileFormats/lnInclude \ -I$(LIB_SRC)/conversion/lnInclude \ - -I$(ParaView_INCLUDE_DIR) \ - -I$(ParaView_INCLUDE_DIR)/vtkkwiml \ + -I$(PARAVIEW_INC_DIR) \ + -I$(PARAVIEW_INC_DIR)/vtkkwiml \ -I../foamPv \ -I../PVFoamReader @@ -20,5 +18,5 @@ LIB_LIBS = \ -lconversion \ -lgenericPatchFields \ -llagrangian \ - -L$(FOAM_LIBBIN) -lfoamPv-pv${ParaView_MAJOR} \ + -L$(FOAM_LIBBIN) -lfoamPv-pv$(PARAVIEW_MAJMIN) \ $(GLIBS) diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/Make/options b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/Make/options index dc1999774a..c06b4bb3de 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/Make/options +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/Make/options @@ -1,18 +1,16 @@ -sinclude $(GENERAL_RULES)/paraview - EXE_INC = \ ${c++LESSWARN} \ -I$(LIB_SRC)/fileFormats/lnInclude \ -I$(LIB_SRC)/conversion/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/mesh/blockMesh/lnInclude \ - -I$(ParaView_INCLUDE_DIR) \ - -I$(ParaView_INCLUDE_DIR)/vtkkwiml \ + -I$(PARAVIEW_INC_DIR) \ + -I$(PARAVIEW_INC_DIR)/vtkkwiml \ -I../foamPv \ -I../PVblockMeshReader LIB_LIBS = \ -lmeshTools \ -lblockMesh \ - -L$(FOAM_LIBBIN) -lfoamPv-pv${ParaView_MAJOR} \ + -L$(FOAM_LIBBIN) -lfoamPv-pv$(PARAVIEW_MAJMIN) \ $(GLIBS) diff --git a/bin/paraFoam b/bin/paraFoam index 93a95e69ec..5a82bd5807 100755 --- a/bin/paraFoam +++ b/bin/paraFoam @@ -88,37 +88,32 @@ do -block*) extension=blockMesh plugin=PVblockMeshReader - shift ;; -vtk | -built*) extension=foam unset plugin - shift ;; -case) [ "$#" -ge 2 ] || die "'$1' option requires an argument" cd "$2" 2>/dev/null || die "directory does not exist: '$2'" - shift 2 + shift ;; -region) [ "$#" -ge 2 ] || die "'$1' option requires an argument" regionName=$2 - shift 2 + shift ;; -touch) optTouch=true unset plugin - shift ;; -touch-all | -touchAll) optTouch=all unset plugin - shift ;; -touch-proc*) optTouch=processor unset plugin - shift ;; --) shift @@ -130,59 +125,65 @@ do exit 1 # This should not have happened ;; --*) - break # Stop here, treat this and balance as paraview options + break # Stop here, treat _this_ and balance as paraview options ;; *) - die "unknown option/argument: '$1'" + die "Unknown option/argument: '$1'" ;; esac + shift done -# If a reader module is needed, check that it exists -[ -z "$plugin" ] || [ -f "$PV_PLUGIN_PATH/lib${plugin}_SM.so" ] || { - cat<< BUILDREADER 1>&2 - -ERROR: ParaView reader module library ($plugin) does not exist -Please build the reader module before continuing: +if [ -n "$plugin" ] +then + pluginError="Cannot use ParaView reader module library ($plugin)" + # Check if requested reader module exists + if [ -z "$PV_PLUGIN_PATH" ] + then + echo "$pluginError" 1>&2 + echo "The PV_PLUGIN_PATH environment value is not set" 1>&2 + elif [ -f "$PV_PLUGIN_PATH/lib${plugin}_SM.so" ] + then + unset pluginError + else + echo "$pluginError - not built?" 1>&2 + cat<< NO_PLUGIN 1>&2 +Consider building the reader module cd \$WM_PROJECT_DIR/applications/utilities/postProcessing/graphics/PVReaders ./Allwclean ./Allwmake - -BUILDREADER - - # Fallback to native reader, if possible - if [ "$extension" = OpenFOAM ] - then - extension=foam - echo "Using the native VTK/OpenFOAM reader instead" 1>&2 - else - exit 1 +NO_PLUGIN fi -} + + if [ -n "$pluginError" ] + then + # Fallback to native reader, if possible + if [ "$plugin" = PVFoamReader ] + then + echo 1>&2 + echo "Continuing with builtin reader: paraFoam -vtk" 1>&2 + echo 1>&2 + extension=foam + else + echo 1>&2 + exit 1 + fi + unset plugin + fi +fi # Check for --data=... argument -hasDataArg() -{ - hasData=false - while [ "$#" -gt 0 ] - do - case "$1" in - (--data=*) - hasData=true - break - ;; - esac - shift - done -} - -hasDataArg "$@" +unset hasData +for i +do + case "$i" in (--data=*) hasData=true; break;; esac +done # Get a sensible caseName from the directory name -caseName=${PWD##*/} +caseName="${PWD##*/}" caseFile="$caseName.$extension" fvControls="system" @@ -211,14 +212,14 @@ all) do if [ -d "$region" ] && [ -d "$region/polyMesh" ] then - regionName=${region##*/} + regionName="${region##*/}" touch "$caseName{$regionName}.$extension" echo "Created '$caseName{$regionName}.$extension'" 1>&2 fi done exit 0 ;; -processor) +proc*) for i in processor* do ( @@ -286,8 +287,8 @@ else # Check existence of essential files warn=false - case "$extension" in - blockMesh) + case "$plugin" in + PVblockMeshReader) blockMeshDict=system/blockMeshDict if [ -f constant/polyMesh/blockMeshDict ] then @@ -297,7 +298,7 @@ else hasFiles system/controlDict "$blockMeshDict" || warn=true ;; - OpenFOAM) + PVFoamReader) hasFiles \ system/controlDict \ "$fvControls/fvSchemes" \ @@ -312,7 +313,7 @@ else exit } - # Only create/remove caseFile if it didn't already exist + # Only create/remove caseFile if it did not previously exist [ -e "$caseFile" ] || { trap "rm -f $caseFile 2>/dev/null; exit 0" EXIT TERM INT touch "$caseFile" diff --git a/etc/config.csh/paraview b/etc/config.csh/paraview index 4ff0163fee..e8acdadc63 100644 --- a/etc/config.csh/paraview +++ b/etc/config.csh/paraview @@ -16,25 +16,30 @@ # Description # Setup for PARAVIEW (partially cmake, qt too) # -# For system-wide cmake: cmake_version=cmake-system -# For system-wide qt: ParaView_QT=qt-system +# To disable use of the PV_PLUGIN_PATH: +# ParaView_VERSION=none +# +# For system-wide installations: +# cmake_version=cmake-system +# ParaView_QT=qt-system +# ParaView_VERSION=system [EXPERIMENTAL] # # Note # The following env. variables are required for building plugins: # ParaView_DIR -# ParaView_INCLUDE_DIR # PV_PLUGIN_PATH +# The OpenFOAM plugin must be the first in PV_PLUGIN_PATH and have +# paraview-major.minor version encoded in its name. # # For central installations not located under ThirdParty, the environment # values must be set manually. For example, # -# setenv ParaView_DIR /opt/paraview/paraview-5.5.0 -# setenv ParaView_INCLUDE_DIR $ParaView_DIR/include/paraview-5.5 -# setenv PV_PLUGIN_PATH $FOAM_LIBBIN/paraview-5.5 +# setenv ParaView_DIR /opt/paraview/paraview-5.6.0 +# setenv PV_PLUGIN_PATH $FOAM_LIBBIN/paraview-5.6 # # setenv PATH $ParaView_DIR/bin:${PATH} # setenv LD_LIBRARY_PATH $ParaView_DIR/lib:$LD_LIBRARY_PATH -# unsetenv ParaView_VERSION # avoid using ThirdParty settings +# unsetenv ParaView_VERSION # skip ThirdParty settings # # In paraview-5.4 and earlier, the libraries were in the sub-directory: # @@ -43,8 +48,8 @@ #------------------------------------------------------------------------------ # USER EDITABLE PART: Changes made here may be lost with the next upgrade -setenv ParaView_VERSION 5.6.0 -set ParaView_QT=qt-system +set ParaView_VERSION=5.6.0 +set ParaView_QT=qt-system set cmake_version=cmake-system # END OF (NORMAL) USER EDITABLE PART @@ -62,10 +67,10 @@ eval `$WM_PROJECT_DIR/bin/foamCleanPath -csh-env=PATH "$ParaView_DIR $archDir/Pa eval `$WM_PROJECT_DIR/bin/foamCleanPath -csh-env=LD_LIBRARY_PATH "$ParaView_DIR $archDir/ParaView- $archDir/qt-"` # ThirdParty cmake -set cmake=$archDir/$cmake_version -if ( -r $cmake/bin/cmake ) then +set cmake="$archDir/$cmake_version" +if ( -r "$cmake/bin/cmake" ) then # _foamAddPath not available when foamPV alias is used - setenv PATH $cmake/bin:${PATH} + setenv PATH "$cmake/bin:${PATH}" endif # Evaluate command-line parameters for ParaView @@ -79,10 +84,47 @@ while ( $#argv > 0 ) shift end +if (! $?ParaView_VERSION ) set ParaView_VERSION='' -# Require that ParaView_VERSION has not been unset. -# Avoids conflict with an alternative (non-ThirdParty) installation. -if ( $?ParaView_VERSION ) then +switch ("$ParaView_VERSION") +case "": + # empty - do nothing + setenv ParaView_DIR # Defined but empty (used by foamPV alias) + breaksw + +case "none": + unsetenv PV_PLUGIN_PATH + setenv ParaView_DIR # Defined but empty (used by foamPV alias) + + if ($?FOAM_VERBOSE && $?prompt) then + echo "Using paraview (disabled)" + endif + breaksw + +case "system": + # Obtain major.minor from `paraview --version` + set pv_api=`paraview --version | \ + sed -ne 's/^[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/p'` + + if ( "${%pv_api}" ) then + setenv PV_PLUGIN_PATH "$FOAM_LIBBIN/paraview-$pv_api" + else + unsetenv ParaView_DIR PV_PLUGIN_PATH + endif + + if ($?FOAM_VERBOSE && $?prompt) then + echo "Using paraview (disabled)" + if ( $?PV_PLUGIN_PATH ) then + echo "Using paraview (system)" + echo " PV_PLUGIN_PATH : $PV_PLUGIN_PATH" + else + echo "system paraview (not found)" + endif + endif + breaksw + +default: + # ParaView_VERSION set and non-empty # Set API to correspond to VERSION # pv_api is . from ParaView_VERSION @@ -94,20 +136,21 @@ if ( $?ParaView_VERSION ) then case [0-9]*: # Extract API from VERSION - set pv_api=`echo ${ParaView_VERSION} | \ - sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/'` + set pv_api=`echo "$ParaView_VERSION" | \ + sed -ne 's/^[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/p'` breaksw endsw - setenv ParaView_DIR $archDir/ParaView-$ParaView_VERSION + setenv ParaView_DIR "$archDir/ParaView-$ParaView_VERSION" # Set paths if binaries are present - if ( -r $ParaView_DIR ) then - setenv PATH ${ParaView_DIR}/bin:${PATH} - setenv ParaView_INCLUDE_DIR $ParaView_DIR/include/paraview-$pv_api - setenv PV_PLUGIN_PATH $FOAM_LIBBIN/paraview-$pv_api + if ( -r "$ParaView_DIR" ) then + # The OpenFOAM plugin directory must be the first in PV_PLUGIN_PATH + # and have paraview-major.minor encoded in its name + setenv PV_PLUGIN_PATH "$FOAM_LIBBIN/paraview-$pv_api" - set pvLibDir=${ParaView_DIR}/lib/paraview-$pv_api + setenv PATH "${ParaView_DIR}/bin:${PATH}" + set pvLibDir="${ParaView_DIR}/lib/paraview-$pv_api" #OBSOLETE? set pvPython=$ParaView_DIR/Utilities/VTKPythonWrapping #OBSOLETE? # Python libraries as required @@ -115,7 +158,7 @@ if ( $?ParaView_VERSION ) then #OBSOLETE? if ($?PYTHONPATH) then #OBSOLETE? setenv PYTHONPATH ${PYTHONPATH}:${pvPython}:$pvLibDir #OBSOLETE? else - #OBSOLETE? setenv PYTHONPATH ${pvPython}:$pvLibDir + #OBSOLETE? setenv PYTHONPATH ${pvPython}:${pvLibDir} #OBSOLETE? endif #OBSOLETE? endif @@ -125,9 +168,9 @@ if ( $?ParaView_VERSION ) then set qtDir="$archDir/$ParaView_QT" if ( -d "$qtDir" ) then - switch ($ParaView_QT) + switch ("$ParaView_QT") case *-5*: - setenv Qt5_DIR $qtDir + setenv Qt5_DIR "$qtDir" breaksw endsw foreach qtLibDir ("$qtDir/lib$WM_COMPILER_LIB_ARCH" "$qtDir/lib") @@ -143,17 +186,16 @@ if ( $?ParaView_VERSION ) then # - 5.5 and later: lib/ switch ("$pv_api") case 5.[0-4]*: - setenv LD_LIBRARY_PATH $pvLibDir:${LD_LIBRARY_PATH} + setenv LD_LIBRARY_PATH "${pvLibDir}:${LD_LIBRARY_PATH}" breaksw default: - setenv LD_LIBRARY_PATH ${ParaView_DIR}/lib:${LD_LIBRARY_PATH} + setenv LD_LIBRARY_PATH "${ParaView_DIR}/lib:${LD_LIBRARY_PATH}" breaksw endsw if ($?FOAM_VERBOSE && $?prompt) then echo "Using paraview" echo " ParaView_DIR : $ParaView_DIR" - echo " ParaView_INCLUDE_DIR : $ParaView_INCLUDE_DIR" echo " library dir : $pvLibDir" echo " PV_PLUGIN_PATH : $PV_PLUGIN_PATH" endif @@ -163,11 +205,12 @@ if ( $?ParaView_VERSION ) then echo " ParaView_DIR : $ParaView_DIR" endif - unsetenv ParaView_INCLUDE_DIR PV_PLUGIN_PATH + unsetenv PV_PLUGIN_PATH setenv ParaView_DIR # Defined but empty (used by foamPV alias) endif + breaksw -endif +endsw unset cleaned archDir unset cmake cmake_version diff --git a/etc/config.sh/paraview b/etc/config.sh/paraview index 4b7c8ad4f2..b909281d98 100644 --- a/etc/config.sh/paraview +++ b/etc/config.sh/paraview @@ -16,25 +16,30 @@ # Description # Setup for PARAVIEW (partially cmake, qt too) # -# For system-wide cmake: cmake_version=cmake-system -# For system-wide qt: ParaView_QT=qt-system +# To disable use of the PV_PLUGIN_PATH: +# ParaView_VERSION=none +# +# For system-wide installations: +# cmake_version=cmake-system +# ParaView_QT=qt-system +# ParaView_VERSION=system [EXPERIMENTAL] # # Note # The following env. variables are required for building plugins: # ParaView_DIR -# ParaView_INCLUDE_DIR # PV_PLUGIN_PATH +# The OpenFOAM plugin must be the first in PV_PLUGIN_PATH and have +# paraview-major.minor encoded in its name. # # For central installations not located under ThirdParty, the environment # values must be set manually. For example, # -# export ParaView_DIR=/opt/paraview/paraview-5.5.0 -# export ParaView_INCLUDE_DIR=$ParaView_DIR/include/paraview-5.5 -# export PV_PLUGIN_PATH=$FOAM_LIBBIN/paraview-5.5 +# export ParaView_DIR=/opt/paraview/paraview-5.6.0 +# export PV_PLUGIN_PATH=$FOAM_LIBBIN/paraview-5.6 # # export PATH=$ParaView_DIR/bin:$PATH # export LD_LIBRARY_PATH=$ParaView_DIR/lib:$LD_LIBRARY_PATH -# unset ParaView_VERSION # avoid using ThirdParty settings +# unset ParaView_VERSION # skip ThirdParty settings # # In paraview-5.4 and earlier, the libraries were in the sub-directory: # @@ -75,52 +80,82 @@ then fi # Evaluate command-line parameters for ParaView -_foamParaviewEval() -{ - while [ $# -gt 0 ] - do - case "$1" in - ParaView*=*) - # name=value -> export name=value - eval "export $1" - ;; - esac - shift - done -} +for i +do + case "$i" in + (ParaView*=*) + # name=value -> export name=value + eval "export $i" + ;; + esac +done -# Evaluate command-line parameters -_foamParaviewEval $@ +case "$ParaView_VERSION" in +('') + # empty - do nothing + ;; -# Require that ParaView_VERSION has not been unset. -# Avoids conflict with an alternative (non-ThirdParty) installation. -if [ -n "$ParaView_VERSION" ] -then +(none) + unset ParaView_DIR PV_PLUGIN_PATH + + if [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] + then + echo "Using paraview (disabled)" 1>&2 + fi + ;; + +(system) + # Obtain major.minor from `paraview --version` + pv_api="$(paraview --version 2>/dev/null | \ + sed -ne 's/^[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/p')" + + if [ -n "$pv_api" ] + then + export PV_PLUGIN_PATH="$FOAM_LIBBIN/paraview-$pv_api" + else + unset ParaView_DIR PV_PLUGIN_PATH + fi + + if [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] + then + if [ -n "$PV_PLUGIN_PATH" ] + then + echo "Using paraview (system)" 1>&2 + echo " PV_PLUGIN_PATH : $PV_PLUGIN_PATH" 1>&2 + else + echo "system paraview (not found)" 1>&2 + fi + fi + ;; + +(*) + # ParaView_VERSION set and non-empty # Set API to correspond to VERSION # pv_api is . from ParaView_VERSION case "$ParaView_VERSION" in - "$pv_api".* ) + ("$pv_api".*) # API and VERSION appear to correspond ;; - [0-9]*) + ([0-9]*) # Extract API from VERSION - pv_api=$(echo $ParaView_VERSION | \ - sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/') + pv_api=$(echo "$ParaView_VERSION" | \ + sed -ne 's/^[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/p') ;; esac - export ParaView_DIR=$archDir/ParaView-$ParaView_VERSION + export ParaView_DIR="$archDir/ParaView-$ParaView_VERSION" # Set paths if binaries are present - if [ -r $ParaView_DIR ] + if [ -r "$ParaView_DIR" ] then - export PATH=$ParaView_DIR/bin:$PATH - export ParaView_INCLUDE_DIR=$ParaView_DIR/include/paraview-$pv_api - export PV_PLUGIN_PATH=$FOAM_LIBBIN/paraview-$pv_api + # The OpenFOAM plugin directory must be the first in PV_PLUGIN_PATH + # and have paraview-major.minor encoded in its name + export PV_PLUGIN_PATH="$FOAM_LIBBIN/paraview-$pv_api" - pvLibDir=$ParaView_DIR/lib/paraview-$pv_api + export PATH="$ParaView_DIR/bin:$PATH" + pvLibDir="$ParaView_DIR/lib/paraview-$pv_api" #OBSOLETE? pvPython=$ParaView_DIR/Utilities/VTKPythonWrapping #OBSOLETE? # Python libraries as required @@ -135,15 +170,15 @@ then if [ -d "$qtDir" ] then case "$ParaView_QT" in - *-5*) - export Qt5_DIR=$qtDir + (*-5*) + export Qt5_DIR="$qtDir" ;; esac - for qtLibDir in $qtDir/lib$WM_COMPILER_LIB_ARCH $qtDir/lib + for qtLibDir in "$qtDir/lib$WM_COMPILER_LIB_ARCH" "$qtDir/lib" do if [ -d "$qtLibDir" ] then - export LD_LIBRARY_PATH=$qtLibDir:$LD_LIBRARY_PATH + export LD_LIBRARY_PATH="$qtLibDir:$LD_LIBRARY_PATH" break fi done @@ -153,33 +188,32 @@ then # - 5.4 and earlier: lib/paraview-X.X # - 5.5 and later: lib/ case "$pv_api" in - 5.[0-4]*) - export LD_LIBRARY_PATH=$pvLibDir:$LD_LIBRARY_PATH + (5.[0-4]*) + export LD_LIBRARY_PATH="$pvLibDir:$LD_LIBRARY_PATH" ;; - *) - export LD_LIBRARY_PATH=$ParaView_DIR/lib:$LD_LIBRARY_PATH + (*) + export LD_LIBRARY_PATH="$ParaView_DIR/lib:$LD_LIBRARY_PATH" ;; esac if [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] then - echo "Using paraview" - echo " ParaView_DIR : $ParaView_DIR" - echo " ParaView_INCLUDE_DIR : $ParaView_INCLUDE_DIR" - echo " library dir : $pvLibDir" - echo " PV_PLUGIN_PATH : $PV_PLUGIN_PATH" + echo "Using paraview" 1>&2 + echo " ParaView_DIR : $ParaView_DIR" 1>&2 + echo " library dir : $pvLibDir" 1>&2 + echo " PV_PLUGIN_PATH : $PV_PLUGIN_PATH" 1>&2 fi else if [ "$FOAM_VERBOSE" -a "$PS1" ] then - echo "No paraview found" - echo " ParaView_DIR : $ParaView_DIR" + echo "No paraview found" 1>&2 + echo " ParaView_DIR : $ParaView_DIR" 1>&2 fi - unset ParaView_DIR ParaView_INCLUDE_DIR PV_PLUGIN_PATH + unset ParaView_DIR PV_PLUGIN_PATH fi - -fi + ;; +esac unset -f _foamParaviewEval 2> /dev/null unset cleaned archDir diff --git a/src/functionObjects/graphics/runTimePostProcessing/Allwclean b/src/functionObjects/graphics/runTimePostProcessing/Allwclean index 7a118a4349..e3340097cf 100755 --- a/src/functionObjects/graphics/runTimePostProcessing/Allwclean +++ b/src/functionObjects/graphics/runTimePostProcessing/Allwclean @@ -1,8 +1,6 @@ #!/bin/sh -cd ${0%/*} || exit 1 # Run from this directory - -# Source the wmake functions -. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions +cd ${0%/*} || exit 1 # Run from this directory +. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions # Source wmake functions # Cleanup library rm -f $FOAM_LIBBIN/librunTimePostProcessing* 2>/dev/null diff --git a/wmake/rules/General/paraview b/wmake/rules/General/paraview deleted file mode 100644 index 1df6ded1bc..0000000000 --- a/wmake/rules/General/paraview +++ /dev/null @@ -1,8 +0,0 @@ -#-------------------------------*- makefile -*--------------------------------- -# paraview values - -# major.minor: eg, /path/paraview-5.0 -> 5.0 -# -ParaView_MAJOR := $(shell echo $(ParaView_INCLUDE_DIR) | sed -e 's/^.*-//') - -#------------------------------------------------------------------------------ diff --git a/wmake/scripts/cmakeFunctions b/wmake/scripts/cmakeFunctions index 327fc873ed..a1b9e5e5d1 100644 --- a/wmake/scripts/cmakeFunctions +++ b/wmake/scripts/cmakeFunctions @@ -15,9 +15,7 @@ # Description # Helper functions for CMake #------------------------------------------------------------------------------ - -# Source the wmake functions -. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions +. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions # Require some wmake functions # Ensure CMake gets the correct C/C++ compilers [ -n "$WM_CC" ] && export CC="$WM_CC" @@ -39,7 +37,7 @@ sameDependency() objectsDir=$(findObjectDir "$sourceDir") || exit 1 # Fatal sentinel="$objectsDir/ThirdParty" - echo $sentinel + echo "$sentinel" if read -r prev 2>/dev/null < $sentinel then @@ -75,10 +73,16 @@ _cmake() # CMake into objectsDir with external dependency # - use sentinel file(s) to handle paraview/vtk version changes +# +# 1 - depend +# 2 - sourceDir +# 3... optional cmake defines +# cmakeVersioned() { local depend="$1" local sourceDir="$2" + shift 2 local objectsDir sentinel # Where generated files are stored @@ -88,76 +92,35 @@ cmakeVersioned() sentinel=$(sameDependency "$depend" "$sourceDir") || \ rm -rf "$objectsDir" > /dev/null 2>&1 - mkdir -p $objectsDir \ - && (cd $objectsDir && _cmake $sourceDir && make) \ + mkdir -p "$objectsDir" \ + && (cd "$objectsDir" && _cmake "$@" "$sourceDir" && make) \ && echo "$depend" >| "${sentinel:-/dev/null}" } -# 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" -} - - +# CMake into objectsDir with external dependency # -# Build library - use sentinel file(s) to handle paraview version changes +# 1 - depend +# 2 - sourceDir +# 3... optional cmake defines # -wmakeLibPv() +cmakeVersionedInstall() { - local depend="ParaView_DIR=$ParaView_DIR" - local sentinel + local depend="$1" + local sourceDir="$2" + shift 2 + local objectsDir sentinel - for libName - do - sentinel=$(sameDependency "$depend" $libName) || \ - wclean $libName + # Where generated files are stored + objectsDir=$(findObjectDir "$sourceDir") || exit 1 # Fatal - wmake $targetType $libName \ - && echo "$depend" > ${sentinel:-/dev/null} - done -} + # Version changed + sentinel=$(sameDependency "$depend" "$sourceDir") || \ + rm -rf "$objectsDir" > /dev/null 2>&1 - -# -# There are several prerequisites for building plugins -# -canBuildPlugin() -{ - [ -d "$ParaView_DIR" -a -r "$ParaView_DIR" ] || { - echo "==> cannot build ParaView plugins without paraview directory" - echo " ParaView_DIR=$ParaView_DIR" - return 1 - } - - [ -n "$PV_PLUGIN_PATH" ] || { - echo "==> ${PWD##*/} : invalid PV_PLUGIN_PATH for building ParaView plugins" - echo " PV_PLUGIN_PATH=${PV_PLUGIN_PATH:-unset}" - return 1 - } - - [ -d "$ParaView_INCLUDE_DIR" ] && \ - [ -f "$ParaView_INCLUDE_DIR/pqServerManagerModel.h" ] || { - echo "==> cannot build ParaView plugins without an include directory" - echo " ... or without GUI support" - echo " ParaView_INCLUDE_DIR=$ParaView_INCLUDE_DIR" - return 1 - } - - command -v cmake > /dev/null 2>&1 || { - echo "==> cannot build ParaView plugins without cmake" - return 1 - } - - return 0 # success + mkdir -p "$objectsDir" \ + && (cd "$objectsDir" && _cmake "$@" "$sourceDir" && make install) \ + && echo "$depend" >| "${sentinel:-/dev/null}" } diff --git a/wmake/scripts/paraviewFunctions b/wmake/scripts/paraviewFunctions new file mode 100644 index 0000000000..4e2a8106dd --- /dev/null +++ b/wmake/scripts/paraviewFunctions @@ -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 +# . +# +# 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 + +#------------------------------------------------------------------------------