Added output of the patch area magnitude and the integral over the patch area magnitude.
[OpenFOAM-1.5.x.git] / bin / tools / buildParaViewFunctions
blob62c108f39ad799f5194a95e1a74c0f8ca4e6568b
1 #---------------------------------*- sh -*-------------------------------------
2 # =========                 |
3 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4 #  \\    /   O peration     |
5 #   \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6 #    \\/     M anipulation  |
7 #------------------------------------------------------------------------------
8 # License
9 #     This file is part of OpenFOAM.
11 #     OpenFOAM is free software; you can redistribute it and/or modify it
12 #     under the terms of the GNU General Public License as published by the
13 #     Free Software Foundation; either version 2 of the License, or (at your
14 #     option) any later version.
16 #     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 #     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 #     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19 #     for more details.
21 #     You should have received a copy of the GNU General Public License
22 #     along with OpenFOAM; if not, write to the Free Software Foundation,
23 #     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 # Script
26 #     buildParaViewFunctions
28 # Description
29 #     ParaView build/install helper functions
31 #------------------------------------------------------------------------------
33 # ParaView_INST_DIR  : location of the original sources
34 # ParaView_DIR       : location of the build (for the ParaViewConfig.cmake)
35 #                      and the installed program
39 # set CMake cache variables
41 addCMakeVariable()
43     while [ -n "$1" ]
44     do
45         CMAKE_VARIABLES="$CMAKE_VARIABLES -D$1"
46         shift
47     done
52 # verbose makefiles
54 addVerbosity()
56     [ "$withVERBOSE" = true ] && addCMakeVariable  CMAKE_VERBOSE_MAKEFILE=TRUE
61 # define options for mpi support
63 addMpiSupport()
65     [ "${withMPI:=false}" = true ] || return
66     OBJ_ADD="$OBJ_ADD-mpi"
68     addCMakeVariable  PARAVIEW_USE_MPI=ON VTK_USE_MPI=ON
69     addCMakeVariable  MPI_INCLUDE_PATH=$MPI_ARCH_PATH/include
70     addCMakeVariable  MPI_LIBRARY=$MPI_ARCH_PATH/lib/libmpi.so
71     addCMakeVariable  VTK_MPIRUN_EXE=$MPI_ARCH_PATH/bin/mpirun
72     addCMakeVariable  VTK_MPI_MAX_NUMPROCS=$MPI_MAX_PROCS
77 # define options for python support
79 addPythonSupport()
81     [ "${withPYTHON:=false}" = true ] || return
82     OBJ_ADD="$OBJ_ADD-py"
84     if pythonBin=$(which python 2>/dev/null)
85     then
86         if [ -n "$PYTHON_LIBRARY" ]
87         then
88             # check $PYTHON_LIBRARY if it has been set
89             if [ ! -e "$PYTHON_LIBRARY" ]
90             then
91                 echo "*** Error: libpython not found at location specified " \
92                      "by PYTHON_LIBRARY=$PYTHON_LIBRARY"
93             fi
94         else
95             # Try to get $PYTHON_LIBRARY from dynamically linked binary
96             PYTHON_LIBRARY=$(ldd $pythonBin | \
97                 sed -ne '/libpython/s/.* => \(.*\) (.*/\1/p')
99            if [ ! -e "$PYTHON_LIBRARY" ]
100            then
101                echo "*** Error: Unable to determine path to python library."
102            fi
103         fi
105         [ -e "$PYTHON_LIBRARY" ] || {
106             echo "    Please set the variable PYTHON_LIBRARY to the full"
107             echo "    path to (and including) libpython, or deactivate"
108             echo "    python support by setting withPYTHON=false"
109             exit 1
110         }
112         pythonMajor=$(echo $PYTHON_LIBRARY | sed 's/.*libpython\(.*\)\.so.*/\1/')
113         pythonInclude=/usr/include/python$pythonMajor
115         # note - we could also allow for a PYTHON_INCLUDE variable ...
116         [ -d "$pythonInclude" ] || {
117             echo "    No python headers found in $pythonInclude/"
118             echo "    Please install python headers or deactivate "
119             echo "    python support by setting withPYTHON=false"
120             exit 1
121         }
123         addCMakeVariable  PARAVIEW_ENABLE_PYTHON=ON
124         addCMakeVariable  PYTHON_INCLUDE_PATH=$pythonInclude
125         addCMakeVariable  PYTHON_LIBRARY=$PYTHON_LIBRARY
127         echo "----"
128         echo "Python information:"
129         echo "    executable     : $pythonBin"
130         echo "    version        : $pythonMajor"
131         echo "    include path   : $pythonInclude"
132         echo "    library        : $PYTHON_LIBRARY"
134         unset pythonBin pythonInclude pythonMajor
135     else
136         echo "*** Error: python not found"
137         echo "***        Deactivate python support by setting withPYTHON=false"
138         exit 1
139     fi
144 # define options for mesa support
146 addMesaSupport()
148     [ "${withMESA:=false}" = true ] || return
150     if [ -d "$MESA_INCLUDE" -a -f "$MESA_LIBRARY" ]
151     then
152         OBJ_ADD="$OBJ_ADD-mesa"
154         addCMakeVariable  VTK_OPENGL_HAS_OSMESA=ON
155         addCMakeVariable  OSMESA_INCLUDE_DIR=$MESA_INCLUDE
156         addCMakeVariable  OSMESA_LIBRARY=$MESA_LIBRARY
158     else
159        echo "*** Error: no MESA information found"
160        echo "***        Deactivate MESA support by setting withMESA=false, or"
161        echo "***        correct the paths given by:"
162        echo "***        - MESA_INCLUDE ($MESA_INCLUDE)"
163        echo "***        - MESA_LIBRARY ($MESA_LIBRARY)"
164        exit 1
165     fi
168 addQtSupport()
170     [ "${withQTSUPPORT:=false}" = true ] || return
172     addCMakeVariable "PARAVIEW_BUILD_QT_GUI=ON"
174     if [ -n "$QMAKE_PATH" ]
175     then
176         addCMakeVariable QT_QMAKE_EXECUTABLE:FILEPATH=$QMAKE_PATH
177     fi
182 # discover where things are or should be put
184 getPaths()
186     if [ ! -n "$ParaView_INST_DIR" ]
187     then
188         # set paraview environment
189         for i in $PWD $WM_THIRD_PARTY_DIR
190         do
191             ParaView_INST_DIR=$i/paraview-$ParaView_VERSION
192             [ -d $ParaView_INST_DIR ] && break
193         done
194     fi
196     if [ ! -d "$ParaView_INST_DIR" ]
197     then
198         # last chance: maybe already in the paraview directory
199         if [ "${PWD##*/}" = "paraview-$ParaView_VERSION" ]
200         then
201             ParaView_INST_DIR=$PWD
202         fi
204         [ -d "$ParaView_INST_DIR" ] || {
205             echo "did not find paraview-$ParaView_VERSION in these directories:"
206             echo "  PWD=$PWD"
207             echo "  WM_THIRD_PARTY_DIR=$WM_THIRD_PARTY_DIR"
208             echo
209             echo "abort build"
210             exit 1
211         }
212     fi
214     # set the major version "<digits>.<digits>"
215     ParaView_MAJOR_VERSION=$(echo $ParaView_VERSION | \
216         sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/')
218     # ParaView_DIR=$ParaView_INST_DIR/platforms/$WM_ARCH$WM_COMPILER$OBJ_ADD
219     ParaView_DIR=$ParaView_INST_DIR/platforms/$WM_ARCH$WM_COMPILER
220     echo "ParaView_DIR=$ParaView_DIR"
225 # configure via cmake, but don't actually build anything
227 configParaView()
229     # remove any existing build folder and recreate
230     if [ -d $ParaView_DIR ]
231     then
232         echo "removing old build/install directory"
233         rm -rf $ParaView_DIR
234     fi
235     mkdir -p $ParaView_DIR
237     cd $ParaView_DIR
239     echo "----"
240     echo "Configuring paraview-$ParaView_VERSION (major version: $ParaView_MAJOR_VERSION)"
241     echo "    MPI    support : ${withMPI:-false}"
242     echo "    Python support : ${withPYTHON:-false}"
243     echo "    MESA   support : ${withMESA:-false}"
244     echo "    Qt dev support : ${withQTSUPPORT:-false}"
245     echo "    Source         : $ParaView_INST_DIR"
246     echo "    Target         : $ParaView_DIR"
247     echo "----"
248     echo
249     echo cmake \
250         -DCMAKE_INSTALL_PREFIX:PATH=$ParaView_DIR \
251         $CMAKE_VARIABLES \
252         ../..
253     echo
254     echo "----"
255     echo
257     # run cmake to create Makefiles
258     cmake \
259         -DCMAKE_INSTALL_PREFIX:PATH=$ParaView_DIR \
260         $CMAKE_VARIABLES \
261         ../..
267 # invoke make
268 # also link bin/ to lib/paraview-* for development without installation
270 makeParaView()
272     cd $ParaView_DIR || exit 1  # change to build folder
273     echo "    Starting make"
275     if [ -r /proc/cpuinfo ]
276     then
277         WM_NCOMPPROCS=$(egrep "^processor" /proc/cpuinfo | wc -l)
278         [ $WM_NCOMPPROCS -le 8 ] || WM_NCOMPPROCS=8
280         time make -j $WM_NCOMPPROCS
281     else
282         time make
283     fi
284     echo "    Done make"
286     echo "    For quicker development, linking lib/paraview-$ParaView_MAJOR_VERSION/ -> bin/"
287     rm -rf lib/paraview-$ParaView_MAJOR_VERSION
288     mkdir lib 2>/dev/null
289     ( cd lib && ln -s ../bin paraview-$ParaView_MAJOR_VERSION )
294 # adjust hard-links (internal function)
295 # Note: use loop with grep to avoid touching too many files
297 fixHardLinks()
299     envName=$1
300     string=$2
301     shift 2
303     echo "-- Replacing path hard links for \$$envName"
305     for fileSpec
306     do
307         echo -n "   $fileSpec: "
308         for i in $(find . -type f -iname "$fileSpec")
309         do
310             if grep -q "$string" $i
311             then
312                 echo -n "#"
313                 sed -i "s,$string,\$ENV{$envName},g" $i
314             fi
315         done
316         echo
317     done
322 # replace absolute paths with environment variables
323 # This triggers a partial (or even a full) rebuild, but might let us
324 # find our files later if we relocate the build
326 fixCMakeFiles()
328     cd $ParaView_DIR || exit 1  # change to build folder
330     # Replace path with env variable: ParaView_DIR
331     fixHardLinks ParaView_DIR "$ParaView_DIR" '*.cmake'
333     # Replace path with env variable: ParaView_INST_DIR
334     fixHardLinks ParaView_INST_DIR "$ParaView_INST_DIR" '*.cmake'
336     # Replace path with env variable: MPI_ARCH_PATH
337     if [ "${withMPI:=false}" = true ]
338     then
339         fixHardLinks MPI_ARCH_PATH "$MPI_ARCH_PATH" '*.cmake'
340     fi
342     # Replace path with env variable: CMAKE_HOME
343     if [ -r "$CMAKE_HOME" ]
344     then
345         fixHardLinks CMAKE_HOME "$CMAKE_HOME" '*cmake*'
346     fi
348     # Replace path with env variable: WM_COMPILER_DIR
349     # (include cmake.check_cache)
350     # This triggers a complete rebuild (with cmake-2.6.2), but is likely
351     # needed when redistributing files
352     fixHardLinks WM_COMPILER_DIR "$WM_COMPILER_DIR" '*cmake*'
357 # make html documentation (mostly just for the readers/writers)
359 makeDocs()
361     cd $ParaView_DIR || exit 1  # change to build folder
362     echo "    Creating html documentation"
364     make HTMLDocumentation
369 # actually install the program
371 installParaView()
373     cd $ParaView_DIR || exit 1  # change to build folder
374     echo "    Installing ParaView to $ParaView_DIR"
376     echo "disabled 'make install' for now, just use links"
378     # about.txt may be missing
379     paraviewLibDir="$ParaView_DIR/lib/paraview-$ParaView_MAJOR_VERSION"
380     if [ -d "$paraviewLibDir" -a ! -e "$paraviewLibDir/about.txt" ]
381     then
382         echo "paraview-$ParaView_MAJOR_VERSION installed - $(date)" > $paraviewLibDir/about.txt
383     fi
385 cat<< INFO
386     ---
387     Installation complete
388     Set environment variables:
390         export ParaView_INST_DIR=$ParaView_INST_DIR
391         export ParaView_DIR=$ParaView_DIR
392         export PV_PLUGIN_PATH=$FOAM_LIBBIN
393         export PATH=\$ParaView_DIR/bin:\$PATH
394     ---
395 INFO
399 # clear all the variables used before using any of the functions
400 unset withMPI withQTSUPPORT withVERBOSE
401 unset withMESA   MESA_INCLUDE   MESA_LIBRARY
402 unset withPYTHON PYTHON_INCLUDE PYTHON_LIBRARY
403 unset CMAKE_VARIABLES
404 unset OBJ_ADD
406 # start with these general settings
407 addCMakeVariable  VTK_USE_TK=FALSE
408 addCMakeVariable  BUILD_SHARED_LIBS:BOOL=ON VTK_USE_RPATH:BOOL=OFF
409 addCMakeVariable  CMAKE_BUILD_TYPE:STRING=Release
411 # include development files in "make install"
412 addCMakeVariable  PARAVIEW_INSTALL_DEVELOPMENT:BOOL=ON
414 # ----------------------------------------------------------------- end-of-file