#!/bin/sh
cd "${0%/*}" || exit                                # Run from this directory
. ${WM_PROJECT_DIR:?}/wmake/scripts/cmakeFunctions  # Require cmake functions
# -----------------------------------------------------------------------------

echo "======================================================================"
echo "${PWD##*/} : $PWD"

unset depend runTimePostProDebug

# If available, prefer use of ParaView MESA
if [ -d "$ParaView_MESA_DIR" ]
then
    export ParaView_DIR="$ParaView_MESA_DIR"
fi

if [ -d "$VTK_DIR" ]
then
    depend="VTK_DIR=$VTK_DIR"
elif [ -d "$ParaView_DIR" ]
then
    depend="ParaView_DIR=$ParaView_DIR"
fi

# Force use of dummy only
# unset depend

# For rebuilding (on error) instead of dropping back to dummy
# runTimePostProDebug=true

if [ "$targetType" = objects ]
then
    depend=ignore
elif [ -n "$depend" ]
then
    if command -v cmake >/dev/null
    then
        cmakeVersioned "$depend" $PWD || {
            echo
            echo "    WARNING: incomplete build of VTK-based post-processing"
            echo
            if [ -z "$runTimePostProDebug" ]
            then
                depend="dummy"
            fi
        }
    else
        echo "==> skip runTimePostProcessing (needs cmake)"
        depend="dummy"
    fi
else
    echo "WARNING: skip runTimePostProcessing (no VTK or ParaView)"
    echo "    - ParaView  : export the 'ParaView_DIR' variable"
    echo "    - VTK       : export the 'VTK_DIR'      variable"
fi

if [ "${depend:-dummy}" = dummy ]
then
    echo "==> dummy runTimePostProcessing"
    wmakeVersioned "vtk=dummy" $PWD dummy
fi

echo "======================================================================"

# -----------------------------------------------------------------------------
