Skip to content
Snippets Groups Projects
ParaViewFunctions 12.5 KiB
Newer Older
Henry's avatar
Henry committed
#---------------------------------*- sh -*-------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
#   \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
#    \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
Henry's avatar
Henry committed
#------------------------------------------------------------------------------
# License
Mark OLESEN's avatar
Mark OLESEN committed
#     This file is part of OpenFOAM, licensed under GNU General Public License
#     <http://www.gnu.org/licenses/>.
Henry's avatar
Henry committed
#
# File
#     etc/tools/ParaViewFunctions
#
# Description
#     ParaView make/install helper functions
#
#     Obtaining paths via 'python-config' is possible, but may not always
#     resolve properly:
#
#         python-config --includes
#         >>
#             -I/usr/include/python2.7 -I/usr/include/python2.7
#
#         python-config --libs
#         >>
#             -lpython2.7 -lpthread -ldl -lutil -lm
#
Henry's avatar
Henry committed
#------------------------------------------------------------------------------

# Variables referenced by the functions. Initialization at the end of the file.
unset CMAKE_VARIABLES
unset withVERBOSE
unset withMPI     MPI_MAX_PROCS
unset withQT      QT_VERSION      QMAKE_PATH
unset withMESA    MESA_INCLUDE    MESA_LIBRARY    withOSMESA
unset withPYTHON  PYTHON_INCLUDE  PYTHON_LIBRARY
unset withGL2
BUILD_TYPE=Release  # The cmake build type

# sourceBASE, buildBASE, installBASE and BUILD_SUFFIX
#   are defined in tools/ThirdPartyFunctions
#------------------------------------------------------------------------------
# Where things are or should be put
Henry's avatar
Henry committed
#   ParaView_VERSION and ParaView_MAJOR should already have been set
#
#   ParaView_SOURCE_DIR : location of the original sources
#   ParaView_BUILD_DIR  : location of the build
Henry's avatar
Henry committed
#   ParaView_DIR        : location of the installed program
#
Henry's avatar
Henry committed
{
    set -- "ParaView-$ParaView_VERSION" "ParaView-v$ParaView_VERSION"

    unset ParaView_SOURCE_DIR
    for i
    do
        ParaView_SOURCE_DIR="$sourceBASE/$i"
        [ -d "$ParaView_SOURCE_DIR" ] && break
    done
Henry's avatar
Henry committed

    [ -d "$ParaView_SOURCE_DIR" ] || {
        echo "Did not locate ParaView version:"
        while [ "$#" -ge 1 ]; do echo "    $1"; shift; done
        echo
        echo "In the directory:"
Henry's avatar
Henry committed
        echo
        echo "abort build"
        exit 1
    }

    ParaView_BUILD_DIR=$buildBASE/ParaView-$ParaView_VERSION$BUILD_SUFFIX
    ParaView_DIR=$installBASE/ParaView-$ParaView_VERSION$BUILD_SUFFIX
    export ParaView_SOURCE_DIR ParaView_BUILD_DIR ParaView_DIR
Henry's avatar
Henry committed

    echo
    echo "ParaView_SOURCE_DIR=$ParaView_SOURCE_DIR"
    echo "ParaView_BUILD_DIR=$ParaView_BUILD_DIR"
Henry's avatar
Henry committed
    echo "ParaView_DIR=$ParaView_DIR"
    export GIT_DIR=$ParaView_SOURCE_DIR/.git # Mask seeing our own git-repo
# Set ParaView_VERSION and adjust ParaView_MAJOR accordingly
Henry's avatar
Henry committed
#
# $1 can contain something something like 4.4.0, paraview-4.4.0, ParaView-4.0.0
#
setParaViewVersion()
Henry's avatar
Henry committed
{
        echo "Error: function setParaViewVersion() called without an argument"
    # The major version is "<digits>.<digits>"
Henry's avatar
Henry committed
    ParaView_MAJOR=$(echo $ParaView_VERSION | \
        sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/')

    export ParaView_VERSION ParaView_MAJOR
}


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

#
# Set CMake cache variables
Henry's avatar
Henry committed
#
addCMakeVariable()
{
Henry's avatar
Henry committed
    do
        [ -n "$i" ] && CMAKE_VARIABLES="$CMAKE_VARIABLES -D$i"
Henry's avatar
Henry committed
#
addVerbosity()
{
    if [ "${withVERBOSE:=false}" = true ]
    then
        addCMakeVariable "CMAKE_VERBOSE_MAKEFILE=TRUE"
# Define options for mpi support
Henry's avatar
Henry committed
#
addMpiSupport()
{
    if [ "${withMPI:=false}" != true ]
    then
        return
    fi

    addCMakeVariable "PARAVIEW_USE_MPI=ON" "VTK_USE_MPI=ON"
    if [ "${MPI_MAX_PROCS:=0}" -gt 1 ]
    then
        addCMakeVariable "VTK_MPI_MAX_NUMPROCS=$MPI_MAX_PROCS"
# Define options for python support
Henry's avatar
Henry committed
#
addPythonSupport()
{
    if [ "${withPYTHON:-false}" != true ]
    local pythonBin pythonConfig pythonMajor

    pythonBin=$(which python 2>/dev/null) || {
        echo "*** Error: python not found"
        echo "***        Deactivate python support by not using the -python "
        echo "***        option"
        exit 1
    }

    if [ -n "$PYTHON_LIBRARY" ]
Henry's avatar
Henry committed
    then

        # PYTHON_LIBRARY set:
        [ -e "$PYTHON_LIBRARY" ] || \
            echo "*** Error: libpython not found at location specified " \
                 "by -python-lib : PYTHON_LIBRARY=$PYTHON_LIBRARY"

    else

        # Fallback: get PYTHON_LIBRARY from dynamically linked binary

        PYTHON_LIBRARY=$(ldd $pythonBin | \
            sed -ne '/libpython/s/^.* => \(.*\) (.*/\1/p')
Henry's avatar
Henry committed

        [ -e "$PYTHON_LIBRARY" ] || {
            echo "*** Error: Unable to determine path to python library."
    [ -e "$PYTHON_LIBRARY" ] || {
        echo "    Please set the full path to the python library "
        echo "    (including libpython) using the -python-lib option, "
        echo "    or deactivate python support by not using the -python "
        echo "    option"
        exit 1
    }
    # Guess major from library
    pythonMajor=$(echo $PYTHON_LIBRARY | sed 's/.*libpython\(.*\)\.so.*/\1/')
    if [ -n "$PYTHON_INCLUDE" ]
    then

        # PYTHON_INCLUDE set:
        [ -d "$PYTHON_INCLUDE" -a -f "$PYTHON_INCLUDE/Python.h" ] || \
            echo "*** Error: Python.h not found at location specified " \
                 "by -python-include : PYTHON_INCLUDE=$PYTHON_INCLUDE"

    elif pythonConfig=$(which python-config 2>/dev/null)
    then
        # Guess from python-config
        # parse '-I/usr/include/python2.7 -I/usr/include/python2.7'
        # -> '/usr/include/python2.7'
        PYTHON_INCLUDE=$(python-config --includes | sed -ne 's/^-I\([^ ][^ ]*\).*$/\1/p')

        # Fallback to system headers
        PYTHON_INCLUDE=/usr/include/python$pythonMajor

Henry's avatar
Henry committed
    fi

    [ -d "$PYTHON_INCLUDE" -a -f "$PYTHON_INCLUDE/Python.h" ] || {
        echo "    No python headers found in $PYTHON_INCLUDE/"
        echo "    Please install python headers or deactivate "
        echo "    python support by not using the -python option"
        exit 1
    }

    addCMakeVariable "PARAVIEW_ENABLE_PYTHON=ON"
    addCMakeVariable "PYTHON_INCLUDE_DIRS=$PYTHON_INCLUDE"
    addCMakeVariable "PYTHON_LIBRARY=$PYTHON_LIBRARY"

    echo "----"
    echo "Python information:"
    echo "    executable     : $pythonBin"
    echo "    version        : $pythonMajor"
    echo "    include path   : $PYTHON_INCLUDE"
    echo "    library        : $PYTHON_LIBRARY"
# Define options for mesa support
Henry's avatar
Henry committed
#
addMesaSupport()
{
    if [ "${withMESA:=false}" != true ]
    then
Henry's avatar
Henry committed

    if [ -d "$MESA_INCLUDE" -a -f "$MESA_LIBRARY" ]
    then
        addCMakeVariable "VTK_OPENGL_HAS_OSMESA=ON"
        addCMakeVariable "OSMESA_INCLUDE_DIR=$MESA_INCLUDE"
        addCMakeVariable "OSMESA_LIBRARY=$MESA_LIBRARY"
        echo "*** Error: no MESA information found"
        echo "***   Deactivate MESA support by not using the -mesa option, "
        echo "***   or set the correct paths for:"
        echo "***       -mesa-include ($MESA_INCLUDE)"
        echo "***       -mesa-lib ($MESA_LIBRARY)"
        exit 1
#
# new rendering backend
#
addGL2Support()
{
    if [ "${withGL2:=false}" = true ]
    then
        addCMakeVariable "VTK_RENDERING_BACKEND=OpenGL2"
#
# Qt 4/5 support
#
Henry's avatar
Henry committed
addQtSupport()
{
    QT_VERSION=none
    : ${withQT:=true}  # default is on
    if [ "$withQT" = false ]
        # Explicitly disabled
        addCMakeVariable "PARAVIEW_BUILD_QT_GUI=OFF"
    local qmake qtLib
    # Check qmake can be found and handle version differences
    qmake=$(findQMake)
    if QT_VERSION=$($qmake -query QT_VERSION 2>/dev/null)
Henry's avatar
Henry committed
    then
        addCMakeVariable "PARAVIEW_BUILD_QT_GUI=ON"
        case "$QT_VERSION" in
        (3.* | 4.[0-4]*)
            # QT is too old
            cat <<ERROR
----
Error: ${0##*/}

QT version ($QT_VERSION) provided < 4.5
Please use the -qmake option to specify the location of a newer QT version
For example,
    ... -qmake /usr/local/qt-4.6.2/bin/qmake
    ... -qmake $installBASE/qt-4.6.2/bin/qmake
----
ERROR
Henry's avatar
Henry committed
            exit 1
        (4.*)
            # Default changed to Qt5 with paraview 5.2.1, so specify explicitly
            addCMakeVariable "PARAVIEW_QT_VERSION=4"

            # Non-system installation - specify location of qmake
            if [ "$qmake" != /usr/bin/qmake ]
            then
                addCMakeVariable "QT_QMAKE_EXECUTABLE=$qmake"
            fi
            ;;

        (5.*)
            # Default changed to Qt5 with paraview 5.2.1, so specify explicitly
            addCMakeVariable "PARAVIEW_QT_VERSION=5"

            # Non-system installation - find CMake config files
            if [ "$qmake" != /usr/bin/qmake ] \
               && qtLib="$($qmake -query QT_INSTALL_LIBS)/cmake/Qt5" \
               && [ -d "$qtLib" ]
            then
                addCMakeVariable "Qt5_DIR=$qtLib"
            fi
Henry's avatar
Henry committed
    else
        QT_VERSION=none
        echo "Error: cannot find qmake either at \$QMAKE_PATH or in current \$PATH"
        echo
#
# Apply source-code patch if possible
#
    applyPatch "paraview-$ParaView_VERSION" "$ParaView_SOURCE_DIR"
Henry's avatar
Henry committed
#
# Configure via cmake, but don't actually build anything
Henry's avatar
Henry committed
#
configParaView()
{
    local cmake=$(findCMake)
    # Remove any existing build folder and recreate
    if [ -d $ParaView_BUILD_DIR ]
Henry's avatar
Henry committed
    then
        echo "removing old build directory"
        echo "    $ParaView_BUILD_DIR"
        rm -rf $ParaView_BUILD_DIR
Henry's avatar
Henry committed
    fi
    mkdir -p $ParaView_BUILD_DIR
    addCMakeVariable "CMAKE_BUILD_TYPE=$BUILD_TYPE"
    cd $ParaView_BUILD_DIR || exit 1  # Change to build folder
Henry's avatar
Henry committed

    echo "----"
    echo "Configuring paraview-$ParaView_VERSION (major version: $ParaView_MAJOR)"
    echo "    MPI    support : ${withMPI:-false}"
    echo "    Python support : ${withPYTHON:-false}"
    echo "    MESA   support : ${withMESA:-false}"
    echo "    GL2  rendering : ${withGL2:-false}"
    echo "    QT dev support : ${withQT:-true}"
Henry's avatar
Henry committed
    echo "    Source         : $ParaView_SOURCE_DIR"
    echo "    Build          : $ParaView_BUILD_DIR"
Henry's avatar
Henry committed
    echo "    Target         : $ParaView_DIR"
    echo "    cmake          : $cmake"
    echo "    Build suffix   : ${BUILD_SUFFIX:-none}"
Henry's avatar
Henry committed
    echo "----"
    echo
        -DCMAKE_INSTALL_PREFIX=$ParaView_DIR \
Henry's avatar
Henry committed
        $CMAKE_VARIABLES \
        $ParaView_SOURCE_DIR
    echo
    echo "----"
    echo

    # Run cmake to create Makefiles
        -DCMAKE_INSTALL_PREFIX=$ParaView_DIR \
Henry's avatar
Henry committed
        $CMAKE_VARIABLES \
        $ParaView_SOURCE_DIR
}


#
Henry's avatar
Henry committed
# also link bin/ to lib/paraview-* for development without installation
#
makeParaView()
{
    cd $ParaView_BUILD_DIR || exit 1  # Change to build folder
Henry's avatar
Henry committed
    echo "    Starting make"
    time make -j $WM_NCOMPPROCS
    echo "    Done make"

    # Remove lib if it is a link
Henry's avatar
Henry committed
    # (how this was previously handled before 'make install' worked)
    if [ -L lib ]
    then
        rm lib 2>/dev/null
    fi
# Install the program
Henry's avatar
Henry committed
#
installParaView()
{
    cd $ParaView_BUILD_DIR || exit 1  # Change to build folder
Henry's avatar
Henry committed
    echo "    Installing ParaView to $ParaView_DIR"

    make install

    # System or non-system installation of QT?
    local qmake qtLib QT_VERSION
    if qmake=$(findQMake 2>/dev/null)
    then
        qtLib=$($qmake -query QT_INSTALL_LIBS)
        QT_VERSION=$($qmake -query QT_VERSION 2>/dev/null)
    fi
    /bin/cat<<INFO

====
Installation complete for paraview-$ParaView_VERSION with qt-${QT_VERSION:-none}
    ParaView_DIR=$ParaView_DIR

You may need to update the OpenFOAM environment by running:
    wmRefresh
INFO

    # Non-system installation of QT?
    case "$qtLib" in (/usr/lib | /usr/lib64) unset qtLib ;; esac

    if [ "$qmake" != /usr/bin/qmake -a -d "$qtLib" ]
    then

And adjust your LD_LIBRARY_PATH to include the following:
    $qtLib
Henry's avatar
Henry committed
INFO
Henry's avatar
Henry committed
}


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

# Start with these general settings
addCMakeVariable "BUILD_SHARED_LIBS=ON" "BUILD_TESTING=OFF"
# Include development files in "make install"
addCMakeVariable "PARAVIEW_INSTALL_DEVELOPMENT_FILES=ON"
#------------------------------------------------------------------------------