makeVTK 8.37 KB
Newer Older
1 2 3 4 5
#!/bin/sh
#------------------------------------------------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
6
#   \\  /    A nd           | Copyright (C) 2016-2018 OpenCFD Ltd.
7 8 9
#    \\/     M anipulation  |
#------------------------------------------------------------------------------
# License
Mark Olesen's avatar
Mark Olesen committed
10 11
#     This file is part of OpenFOAM, licensed under GNU General Public License
#     <http://www.gnu.org/licenses/>.
12 13 14 15 16
#
# Script
#     makeVTK
#
# Description
17 18
#     Make and install VTK.
#     The VTK sources should be located under one of these locations:
19
#       - $WM_THIRD_PARTY_DIR/VTK-VERSION
20 21 22 23
#
#     To use the VTK source from the ParaView source tree, simply make an
#     appropriate link first. For example,
#
24
#         ln -s ParaView-v5.3.0/VTK VTK-7.1.0
25
#
26 27
# ----------------------------------------------
# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE
28
#------------------------------------------------------------------------------
29
# Run from third-party directory only
30
cd ${0%/*} && wmakeCheckPwd "$WM_THIRD_PARTY_DIR" 2>/dev/null || {
31 32
    echo "Error (${0##*/}) : not located in \$WM_THIRD_PARTY_DIR"
    echo "    Check your OpenFOAM environment and installation"
33 34 35 36 37 38
    exit 1
}
. etc/tools/ThirdPartyFunctions
. etc/tools/ParaViewFunctions
. etc/tools/vtkFunctions
#------------------------------------------------------------------------------
39

40
unset vtk_version mesa_version                           # Purge current values
41

42
# vtk version from OpenFOAM etc/config.sh file:
43
_foamConfig vtk
44

45 46 47 48 49 50 51 52 53
VTK_VERSION="$vtk_version"

case "$VTK_VERSION" in
[Vv]*)
    VTK_VERSION="${VTK_VERSION##*-}"        # Without "VTK-" prefix
    ;;
esac
VTK_VERSION="${VTK_VERSION%%-*}"            # Without suffix (eg, -mesa)

54 55

# New rendering backend (starting with vtk 7?).
56
withGL2=auto # auto-config based on version
57

58
#------------------------------------------------------------------------------
59 60 61 62 63
usage() {
    exec 1>&2
    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
    cat<<USAGE

64
usage: ${0##*/} [OPTION] [vtk-VERSION] [CMAKE-OPTION]
65
options:
66
  -gcc              force g++ instead of the value from \$WM_CXX
67
  -rebuild          for repeated builds (-make -install) *use with caution*
68
  -gl2              with new rendering backend (default: auto)
69
  -mesa             with mesa (if not already enabled)
70
  -mesa-prefix DIR  location of mesa installation
71 72
  -mesa-include DIR location of mesa headers (current: ${MESA_INCLUDE:-none})
  -mesa-lib PATH    path to mesa library     (current: ${MESA_LIBRARY:-none})
73
  -osmesa           with off-screen mesa only
74
  -mpi              with mpi
75
  -mpi=N            with max 'N' mpi processes. N=0 for no upper-limit.
76
  -cmake PATH       with cmake from the path given
77
  -verbose          verbose output in Makefiles
78
  -version VER      specify an alternative version (current: $VTK_VERSION)
79
  -buildType NAME   specify the build type (default: Release)
80
  -suffix NAME      specify a suffix to distinguish the build
81 82
  -help

83
The -no-FEATURE option can be used to forcibly disable these features:
84
  -no-gl2 | -no-mesa | -no-mpi
85 86 87

CMake options start with a capital letter and contain an '='.
For example,
88
    ${0##*/} BUILD_TESTING=ON
89 90 91
to add tests and avoid building documentation

For finer control, the build stages can be selected or deselected individually:
92
  -patch     -no-patch
93 94 95 96 97 98 99
  -config    -no-config
  -make      -no-make
  -install   -no-install


* Make and install VTK-$VTK_VERSION located under
      \$WM_THIRD_PARTY_DIR/VTK-$VTK_VERSION
100
  ->  \$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/VTK-$VTK_VERSION$BUILD_SUFFIX
101 102 103 104 105

USAGE
    exit 1
}
#------------------------------------------------------------------------------
106
exportCompiler          # Compiler info for CMake/configure
107

108
# Various building stages
109 110 111
unset runPATCH runCONFIG runMAKE runINSTALL
runDEFAULT=true

112
# Parse options
113 114 115
while [ "$#" -gt 0 ]
do
    case "$1" in
116 117 118 119
    '') ;;      # Ignore empty
    -h | -help) usage   ;;
    -gcc)       useGcc  ;;

120 121 122 123 124 125
    [0-9]* | vtk-[0-9]* | VTK-[0-9]*) # VTK version
        setVtkVersion "${1%%/}"
        ;;
    [A-Z]*=*)            # cmake variables
        addCMakeVariable "$1"
        ;;
126 127 128 129 130 131 132
    -patch)              # stage 0: patch sources
        runPATCH=true
        unset runDEFAULT
        ;;
    -no-patch)
        runPATCH=false
        ;;
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
    -config)             # stage 1: config only
        runCONFIG=true
        unset runDEFAULT
        ;;
    -no-config)
        runCONFIG=false
        ;;
    -make)               # stage 2: make only
        runMAKE=true
        unset runDEFAULT
        ;;
    -no-make)
        runMAKE=false
        ;;
    -install)            # stage 3: install only
        runINSTALL=true
        unset runDEFAULT
        ;;
    -no-install)
        runINSTALL=false
        ;;
    -rebuild)            # shortcut for rebuilding
        runMAKE=true
        runINSTALL=true
        unset runDEFAULT
        ;;
    -gl2)
        withGL2=true
        ;;
    -no-gl2)
        withGL2=false
        ;;
    -mesa)
        withMESA=true
        ;;
    -osmesa)
        withMESA=true
        withOSMESA=true
        ;;
    -no-mesa)
        withMESA=false
        withOSMESA=false
        ;;
    -mesa-prefix)
        [ "$#" -ge 2 ] || die "'$1' option requires an argument"
        withMESA=true
        MESA_INCLUDE="${2%%/}/include"
180
        # Could be under (lib64 | lib)
181
        MESA_LIBRARY="${2%%/}/lib$WM_COMPILER_LIB_ARCH/libOSMesa.so"
182
        [ -f "$MESA_LIBRARY" ] || MESA_LIBRARY="${2%%/}/lib/libOSMesa.so"
183 184 185 186
        shift
        ;;
    -mesa-include)
        [ "$#" -ge 2 ] || die "'$1' option requires an argument"
187
        withMESA=true
188 189 190 191 192
        MESA_INCLUDE="${2%%/}"
        shift
        ;;
    -mesa-lib)
        [ "$#" -ge 2 ] || die "'$1' option requires an argument"
193
        withMESA=true
194 195 196
        MESA_LIBRARY="${2%%/}"
        shift
        ;;
197 198 199 200 201 202 203 204 205 206
    -mpi)
        withMPI=true
        ;;
    -mpi=[0-9]*) # mpi and max mpi processes
        withMPI=true
        MPI_MAX_PROCS="${1##*=}"
        ;;
    -no-mpi)
        withMPI=false
        ;;
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
    -cmake)
        [ "$#" -ge 2 ] || die "'$1' option requires an argument"
        CMAKE_PATH="${2%%/}"
        shift
        ;;
    -verbose)
        withVERBOSE=true
        ;;
    -version)
        [ "$#" -ge 2 ] || die "'$1' option requires an argument"
        setVtkVersion "${2%%/}"
        VTK_VERSION="${2%%/}"
        shift
        ;;
    -buildType)
        [ "$#" -ge 2 ] || die "'$1' option requires an argument"
223
        BUILD_TYPE="$2"
224 225
        shift
        ;;
226 227 228 229 230
    -suffix)
        [ "$#" -ge 2 ] || die "'$1' option requires an argument"
        setBuildSuffix "$2"
        shift
        ;;
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
    *)
        die "unknown option/argument: '$1'"
        ;;
    esac
    shift
done

[ -n "$VTK_VERSION" ] || die "The vtk-VERSION was not specified"

# Version-specific adjustments
if [ "$withGL2" = auto ]
then
    if [ "${VTK_VERSION%%.*}" -lt 7 ]
    then
        withGL2=false
    else
        withGL2=true
    fi
fi


if [ "$runDEFAULT" = true ]
then
    : ${runPATCH:=true}
    : ${runCONFIG:=true}
    : ${runMAKE:=true}
    : ${runINSTALL:=true}
fi


# Set configure options
#~~~~~~~~~~~~~~~~~~~~~~
addVerbosity        # verbose makefiles
264
addMpiSupport       # set MPI-specific options
265 266 267
addMesaSupport      # set MESA-specific options
addGL2Support       # new rendering backend

268
# Set off-screen options
269 270
if [ "$withOSMESA" = true ]
then
271
    addCMakeVariable "VTK_USE_X=OFF"
272 273 274
    addCMakeVariable "OPENGL_INCLUDE_DIR=$MESA_INCLUDE"
    addCMakeVariable "OPENGL_gl_LIBRARY=$MESA_LIBRARY"
    addCMakeVariable "OPENGL_glu_LIBRARY=$MESA_LIBRARY"
275
    addCMakeVariable "OPENGL_xmesa_INCLUDE_DIR=$MESA_INCLUDE"
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
fi

setVtkDirs          # where things are or should be put


# Build and install
# ~~~~~~~~~~~~~~~~~
cat<<SUMMARY

Build stages selected
---------------------
    -patch    ${runPATCH:-false}
    -config   ${runCONFIG:-false}
    -make     ${runMAKE:-false}
    -install  ${runINSTALL:-false}
---------------------
Features selected
    mesa      ${withMESA:-false}
294
    mpi       ${withMPI:-false}
295 296
---------------------
Version information
297
    vtk       ${VTK_VERSION:-unknown}
298
    build     ${BUILD_TYPE:-unknown}
299 300 301 302 303 304 305 306 307 308 309 310
---------------------
SUMMARY

[ "$runPATCH"   = true ] && patchVTK
[ "$runCONFIG"  = true ] && configVTK
[ "$runMAKE"    = true ] && makeVTK
[ "$runINSTALL" = true ] && installVTK

echo
echo Done

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