Skip to content
Snippets Groups Projects
buildParaViewFunctions 7.89 KiB
Newer Older
  • Learn to ignore specific revisions
  • #!/bin/sh
    #------------------------------------------------------------------------------
    # =========                 |
    # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    #  \\    /   O peration     |
    #   \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
    #    \\/     M anipulation  |
    #------------------------------------------------------------------------------
    # License
    #     This file is part of OpenFOAM.
    #
    #     OpenFOAM is free software; you can redistribute it and/or modify it
    #     under the terms of the GNU General Public License as published by the
    #     Free Software Foundation; either version 2 of the License, or (at your
    #     option) any later version.
    #
    #     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    #     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    #     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    #     for more details.
    #
    #     You should have received a copy of the GNU General Public License
    #     along with OpenFOAM; if not, write to the Free Software Foundation,
    #     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    #
    # Script
    #     buildParaViewFunctions
    #
    # Description
    #     ParaView build/install helper functions
    #
    #------------------------------------------------------------------------------
    
    
    andy's avatar
    andy committed
    addCMakeVariable ()
    
    andy's avatar
    andy committed
        while [ -n "$1" ]
        do
            CMAKE_VARIABLES="$CMAKE_VARIABLES -D$1"
            shift
        done
    
    andy's avatar
    andy committed
    initialiseVariables ()
    
    henry's avatar
    henry committed
        unset CMAKE_VARIABLES OBJ_ADD
    
    andy's avatar
    andy committed
        if [ "$VERBOSE" = ON ]; then
            addCMakeVariable "CMAKE_VERBOSE_MAKEFILE=TRUE"
        fi
    
    }
    
    
    addMpiSupport ()
    {
    
    andy's avatar
    andy committed
        [ "$INCLUDE_MPI" = ON ] || return
    
    
        MPI_LIBRARY=$MPI_ARCH_PATH/lib/libmpi.so
    
        MPI_INCLUDE_PATH=$MPI_ARCH_PATH/include
        MPI_RUN=$MPI_ARCH_PATH/bin/mpirun
    
    
    andy's avatar
    andy committed
        OBJ_ADD="$OBJ_ADD-mpi"
        addCMakeVariable "VTK_USE_MPI=ON"
        addCMakeVariable "PARAVIEW_USE_MPI=ON"
        addCMakeVariable "MPI_INCLUDE_PATH=$MPI_INCLUDE_PATH"
        addCMakeVariable "MPI_LIBRARY=$MPI_LIBRARY"
        addCMakeVariable "VTK_MPIRUN_EXE=$MPI_RUN"
        addCMakeVariable "VTK_MPI_MAX_NUMPROCS=$MPI_MAX_PROCS"
    
    }
    
    
    addPythonSupport ()
    {
    
    andy's avatar
    andy committed
        [ "$INCLUDE_PYTHON" = ON ] || return
    
    
        WHICH_PYTHON=`which python`
        if [ -n "$WHICH_PYTHON" ]; then
            OBJ_ADD="$OBJ_ADD-py"
    
            if [ -n "$PYTHON_LIBRARY" ]; then
                # check $PYTHON_LIBRARY if it has been set
                if [ ! -e "$PYTHON_LIBRARY" ]; then
                    echo "*** Error: libpython not found at location specified " \
                         "by PYTHON_LIBRARY: $PYTHON_LIBRARY"
                    echo "    Please set the variable PYTHON_LIBRARY to the full"
                    echo "    path to (and including) libpython, or deactivate"
                    echo "    python support by setting INCLUDE_PYTHON=OFF"
                    exit 1
                fi
            else
                # Try to obtain $PYTHON_LIBRARY if not set
                # - assumes dynamically linked
                PYTHON_LIBRARY=`ldd $WHICH_PYTHON | grep libpython | \
                    sed 's/.* => \(.*\) (.*/\1/'`
            fi
    
            if [ ! -n "$PYTHON_LIBRARY" ]; then
                echo "*** Error: Unable to determine path to python library."
                echo "    Please set the variable PYTHON_LIBRARY to the full"
                echo "    path to (and including) libpython, or deactivate"
                echo "    python support by setting INCLUDE_PYTHON=OFF"
                exit 1
            fi
            PYTHON_MAJOR_VERSION=`echo $PYTHON_LIBRARY | \
                sed 's/.*libpython\(.*\).so.*/\1/'`
            PYTHON_INCLUDE_DIR=/usr/include/python$PYTHON_MAJOR_VERSION
    
            addCMakeVariable "PARAVIEW_ENABLE_PYTHON=ON"
            addCMakeVariable "PYTHON_INCLUDE_PATH=$PYTHON_INCLUDE_DIR"
            addCMakeVariable "PYTHON_LIBRARY=$PYTHON_LIBRARY"
        else
            echo "*** Error: python not installed"
            echo "***        De-activate python support by setting " \
                 "INCLUDE_PYTHON=OFF"
            exit 1
        fi
    }
    
    
    addMesaSupport ()
    {
    
    andy's avatar
    andy committed
        [ "$INCLUDE_MESA" = ON ] || return
    
    
        MESA_INCLUDE_DIR=/usr/include/GL
        MESA_LIBRARY=/usr/lib$WM_COMPILER_LIB_ARCH/libOSMesa.so
    
    
        if [ -d "$MESA_INCLUDE_DIR" -a -f "$MESA_LIBRARY" ]; then
            OBJ_ADD="$OBJ_ADD-mesa"
            addCMakeVariable "VTK_OPENGL_HAS_OSMESA=ON"
            addCMakeVariable "OSMESA_INCLUDE_DIR=$MESA_INCLUDE_DIR"
            addCMakeVariable "OSMESA_LIBRARY=$MESA_LIBRARY"
        else
            echo "*** Error: no MESA information found"
            exit 1
        fi
    
    }
    
    
    buildParaView ()
    {
        # set general options
    
    andy's avatar
    andy committed
        addCMakeVariable "BUILD_SHARED_LIBS:BOOL=ON"
    
    
        # set paraview environment
    
    andy's avatar
    andy committed
        unset PARAVIEW_SRC_DIR
    
        for i in $PWD $WM_THIRD_PARTY_DIR
    
    andy's avatar
    andy committed
        do
           if [ -d $i/$PARAVIEW_SRC ]
           then
              PARAVIEW_SRC_DIR=$i/$PARAVIEW_SRC
              break
           fi
        done
    
        [ -d "$PARAVIEW_SRC_DIR" ] || {
           echo "did not find $PARAVIEW_SRC in these directories:"
           echo "  PWD=$PWD"
    
           echo "  WM_THIRD_PARTY_DIR=$WM_THIRD_PARTY_DIR"
    
    andy's avatar
    andy committed
           echo "abort build"
           exit 1
        }
    
        # PARAVIEW_OBJ_DIR=$PARAVIEW_SRC_DIR/platforms/$WM_OPTIONS/obj$OBJ_ADD
    
        PARAVIEW_OBJ_DIR=$PARAVIEW_SRC_DIR/platforms/$WM_ARCH$WM_COMPILER
    
    andy's avatar
    andy committed
        # provide a shortcut for repeated builds - use with caution
        if [ "$CMAKE_SKIP" = YES ]
        then
    
           # change to build folder
           cd $PARAVIEW_OBJ_DIR || exit 1
    
    andy's avatar
    andy committed
        else
    
           # remove existing build folder if present
           if [ -e "$PARAVIEW_OBJ_DIR" ]; then
               rm -rf $PARAVIEW_OBJ_DIR
           fi
    
           # create paraview build folder
           mkdir -p $PARAVIEW_OBJ_DIR
           cd $PARAVIEW_OBJ_DIR
    
           echo "Building $PARAVIEW_SRC"
           echo "    MPI support    : $INCLUDE_MPI"
           echo "    Python support : $INCLUDE_PYTHON"
           echo "    MESA support   : $INCLUDE_MESA"
           echo "    Source         : $PARAVIEW_SRC_DIR"
           echo "    Target         : $PARAVIEW_OBJ_DIR"
    
           # make paraview
           cmake \
               -DCMAKE_INSTALL_PREFIX=$PARAVIEW_APP_DIR \
               $CMAKE_VARIABLES \
               $PARAVIEW_SRC_DIR
    
    
        if [ -r /proc/cpuinfo ]; then
            WM_NCOMPPROCS=`egrep "^processor" /proc/cpuinfo | wc -l`
    
            if [ $WM_NCOMPPROCS -gt 8 ]; then
                WM_NCOMPPROCS=8
            fi
    
            make -j $WM_NCOMPPROCS
        else
            make
        fi
    }
    
    
    installParaView ()
    {
        if [ -e "$PARAVIEW_OBJ_DIR/bin/paraview" ]; then
            echo "    Build complete"
    
            cd $PARAVIEW_OBJ_DIR
    
    
            # Replace PARAVIEW_SRC_DIR path with ParaView_INST_DIR
            # environment variables
    
            echo "    Replacing path hard links"
            find . -iname \*.cmake -execdir sed -i \
                "s,$PARAVIEW_SRC_DIR,\$ENV{ParaView_INST_DIR},g" {} ';' \
                -print
    
    
            # Replace local MPI_ARCH_PATH path with MPI_ARCH_PATH
    
            if [ "$INCLUDE_MPI" = ON ]; then
                find . -iname \*.cmake -execdir sed -i \
    
                    "s,$MPI_ARCH_PATH,\$ENV{MPI_ARCH_PATH},g" {} ';' \
    
            # create a softlink to the $PARAVIEW_OBJ_DIR/bin folder
    
    andy's avatar
    andy committed
            # - workaround for chosen install location
    
            echo "    Creating paraview $PARAVIEW_MAJOR_VERSION soft link to /bin"
    
    andy's avatar
    andy committed
            (  mkdir lib && cd lib && ln -s ../bin \
                paraview-$PARAVIEW_MAJOR_VERSION  )
    
    
            # info on symlinks to screen
            echo ""
            echo "    ---"
            echo "    Installation complete"
            echo "    Set environment variables:"
            echo "    - ParaView_INST_DIR to $PARAVIEW_SRC_DIR"
            echo "    - ParaView_DIR to $PARAVIEW_OBJ_DIR"
            echo "    - PV_PLUGIN_PATH to $FOAM_LIBBIN"
            echo "    Add $PARAVIEW_OBJ_DIR/bin to PATH"
    
    andy's avatar
    andy committed
            # echo "   Add $ParaView_INST_DIR/lib to LD_LIBRARY_PATH"
    
            echo "    ---"
        fi
    }
    
    andy's avatar
    andy committed
    
    
    # for good measure - clear a few variables before using any of the functions
    
    unset VERBOSE INCLUDE_MPI INCLUDE_PYTHON INCLUDE_MESA PYTHON_LIBRARY
    unset CMAKE_VARIABLES OBJ_ADD
    unset CMAKE_SKIP
    
    
    henry's avatar
    henry committed
    
    # ----------------------------------------------------------------- end-of-file