From dec8bd46c33e7804ef769ea202bbc7e10eb32bae Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Mon, 28 Nov 2016 15:35:27 +0100
Subject: [PATCH] BUG: _foamAddPath not available when foamPV alias/function is
 used

STYLE: only use paraview settings when actually available

- this means executing makeParaView prior to building OpenFOAM itself,
  but is consistent with the instructions given by makeParaView,
  and elminates anticipating the source location from the paraview
  config file, which increases the build flexibilty for ThirdParty
---
 etc/config.csh/example/paraview |  2 +-
 etc/config.csh/mpi              |  6 ++++++
 etc/config.csh/paraview         | 17 +++++++++++------
 etc/config.sh/mpi               |  7 +++++++
 etc/config.sh/paraview          | 24 +++++++++++++++++++-----
 5 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/etc/config.csh/example/paraview b/etc/config.csh/example/paraview
index 47747cafad7..b65dd6a07dc 100644
--- a/etc/config.csh/example/paraview
+++ b/etc/config.csh/example/paraview
@@ -35,7 +35,7 @@
 #------------------------------------------------------------------------------
 
 #
-# Use other (shipped) paraview.csh with a different ParaView_VERSION
+# Use other (shipped) paraview with a different ParaView_VERSION
 #
 
 set foamFile=`$WM_PROJECT_DIR/bin/foamEtcFile -mode o config.csh/paraview`
diff --git a/etc/config.csh/mpi b/etc/config.csh/mpi
index 876357d4357..b0395884861 100644
--- a/etc/config.csh/mpi
+++ b/etc/config.csh/mpi
@@ -60,6 +60,12 @@ case OPENMPI:
     # Tell OpenMPI where to find its install directory
     setenv OPAL_PREFIX $MPI_ARCH_PATH
 
+    if ($?FOAM_VERBOSE && $?prompt) then
+        echo "Using OPENMPI:"
+        echo "    OPAL_PREFIX : $OPAL_PREFIX"
+        echo "    FOAM_MPI    : $FOAM_MPI"
+    endif
+
     _foamAddPath    $MPI_ARCH_PATH/bin
     _foamAddLib     $MPI_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH
     _foamAddMan     $MPI_ARCH_PATH/share/man
diff --git a/etc/config.csh/paraview b/etc/config.csh/paraview
index 50973a93d47..65209feb570 100644
--- a/etc/config.csh/paraview
+++ b/etc/config.csh/paraview
@@ -66,7 +66,8 @@ if ( $status == 0 ) setenv PATH $cleaned
 # ThirdParty cmake
 set cmake=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cmake_version
 if ( -r $cmake/bin/cmake ) then
-    _foamAddPath $cmake/bin
+    # _foamAddPath not available when foamPV alias is used
+    setenv PATH $cmake/bin:${PATH}
 endif
 
 # Evaluate command-line parameters for ParaView
@@ -101,12 +102,11 @@ if ( $?ParaView_VERSION ) then
 
     set pvName=ParaView-$ParaView_VERSION
     set pvMajor=paraview-$ParaView_MAJOR
-    set pvSrcDir=$WM_THIRD_PARTY_DIR/$pvName
 
     setenv ParaView_DIR $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$pvName
 
-    # Set paths if binaries or source are present
-    if ( -r $ParaView_DIR || -r $pvSrcDir ) then
+    # Set paths if binaries are present
+    if ( -r $ParaView_DIR ) then
         set pvLibDir=${ParaView_DIR}/lib/$pvMajor
         set pvPython=$ParaView_DIR/Utilities/VTKPythonWrapping
 
@@ -132,13 +132,18 @@ if ( $?ParaView_VERSION ) then
             echo "    PV_PLUGIN_PATH       : $PV_PLUGIN_PATH"
         endif
     else
+        if ($?FOAM_VERBOSE && $?prompt) then
+            echo "No paraview found"
+            echo "    ParaView_DIR         : $ParaView_DIR"
+        endif
+
         unsetenv ParaView_INCLUDE_DIR PV_PLUGIN_PATH
         setenv ParaView_DIR   # Defined but empty (used by foamPV alias)
     endif
 
 endif
 
-unset cleaned cmake cmake_version pvName pvMajor pvSrcDir pvLibDir pvPython
-unsetenv ParaView_VERSION ParaView_MAJOR
+unset cleaned cmake cmake_version pvName pvMajor pvLibDir pvPython
+unsetenv ParaView_MAJOR ParaView_VERSION
 
 #------------------------------------------------------------------------------
diff --git a/etc/config.sh/mpi b/etc/config.sh/mpi
index d8872685888..9e648038387 100644
--- a/etc/config.sh/mpi
+++ b/etc/config.sh/mpi
@@ -63,6 +63,13 @@ OPENMPI)
     # Tell OpenMPI where to find its install directory
     export OPAL_PREFIX=$MPI_ARCH_PATH
 
+    if [ "$FOAM_VERBOSE" -a "$PS1" ]
+    then
+        echo "Using OPENMPI:" 1>&2
+        echo "    OPAL_PREFIX : $OPAL_PREFIX" 1>&2
+        echo "    FOAM_MPI    : $FOAM_MPI" 1>&2
+    fi
+
     _foamAddPath    $MPI_ARCH_PATH/bin
     _foamAddLib     $MPI_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH
     _foamAddMan     $MPI_ARCH_PATH/share/man
diff --git a/etc/config.sh/paraview b/etc/config.sh/paraview
index 99a379422c7..1ae361d8bf6 100644
--- a/etc/config.sh/paraview
+++ b/etc/config.sh/paraview
@@ -49,6 +49,9 @@
 #         export LD_LIBRARY_PATH=$ParaView_DIR/lib/paraview-5.2:$LD_LIBRARY_PATH
 #         unset ParaView_VERSION        # avoid using ThirdParty settings
 #
+# Note
+#     When _foamAddLib is unset (eg, called from makeParaView or from foamPV):
+#         - the ParaView_VERSION variable is retained.
 #------------------------------------------------------------------------------
 
 ParaView_VERSION=5.2.0
@@ -70,7 +73,8 @@ cleaned=$($WM_PROJECT_DIR/bin/foamCleanPath "$PATH" \
 cmake=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cmake_version
 if [ -r $cmake/bin/cmake ]
 then
-    _foamAddPath $cmake/bin
+    # _foamAddPath not available when foamPV function is used
+    PATH=$cmake/bin:$PATH
 fi
 
 # Evaluate command-line parameters for ParaView
@@ -112,12 +116,11 @@ then
 
     pvName=ParaView-$ParaView_VERSION
     pvMajor=paraview-$ParaView_MAJOR
-    pvSrcDir=$WM_THIRD_PARTY_DIR/$pvName
 
     export ParaView_DIR=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$pvName
 
     # Set paths if binaries or source are present
-    if [ -r $ParaView_DIR -o -r $pvSrcDir ]
+    if [ -r $ParaView_DIR ]
     then
         pvLibDir=$ParaView_DIR/lib/$pvMajor
         pvPython=$ParaView_DIR/Utilities/VTKPythonWrapping
@@ -147,13 +150,24 @@ then
             echo "    PV_PLUGIN_PATH       : $PV_PLUGIN_PATH"
         fi
     else
+        if [ "$FOAM_VERBOSE" -a "$PS1" ]
+        then
+            echo "No paraview found"
+            echo "    ParaView_DIR         : $ParaView_DIR"
+        fi
+
         unset ParaView_DIR ParaView_INCLUDE_DIR PV_PLUGIN_PATH
     fi
 
 fi
 
 unset -f _foamParaviewEval
-unset cleaned cmake cmake_version pvName pvMajor pvSrcDir pvLibDir pvPython
-unset ParaView_VERSION ParaView_MAJOR
+unset cleaned cmake cmake_version pvName pvMajor pvLibDir pvPython
+unset ParaView_MAJOR
+
+if type _foamAddLib > /dev/null 2>&1    # normal sourcing
+then
+    unset ParaView_VERSION
+fi
 
 #------------------------------------------------------------------------------
-- 
GitLab