Upgraded the ParaView build scripts to version 3.3-cvs.
[OpenFOAM-1.5.x.git] / bin / tools / buildParaViewFunctions
blobf1da2c0e3e23f87cf17c380e056d71a90e07ae83
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     [ "$VERBOSE" = ON ] && addCMakeVariable  CMAKE_VERBOSE_MAKEFILE=TRUE
61 # define options for mpi support
63 addMpiSupport()
65     [ "$WITH_MPI" = ON ] || 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     [ "$WITH_PYTHON" = ON ] || 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 WITH_PYTHON=OFF"
109             exit 1
110         }
112         pythonMajor=$(echo $PYTHON_LIBRARY | sed 's/.*libpython\(.*\)\.so.*/\1/')
113         pythonInclude=/usr/include/python$pythonMajor
115         [ -e "$PYTHON_LIBRARY" ] || {
116             echo "    Please set the variable PYTHON_LIBRARY to the full"
117             echo "    path to (and including) libpython, or deactivate"
118             echo "    python support by setting WITH_PYTHON=OFF"
119             exit 1
120         }
122         # note - we could also allow for a PYTHON_INCLUDE variable ...
123         [ -e "$pythonInclude" ] || {
124             echo "    No python include headers found"
125             echo "    Please install python headers or deactivate "
126             echo "    python support by setting WITH_PYTHON=OFF"
127             exit 1
128         }
130         addCMakeVariable  PARAVIEW_ENABLE_PYTHON=ON
131         addCMakeVariable  PYTHON_INCLUDE_PATH=$pythonInclude
132         addCMakeVariable  PYTHON_LIBRARY=$PYTHON_LIBRARY
134         echo "----"
135         echo "Python information:"
136         echo "    executable     : $pythonBin"
137         echo "    version        : $pythonMajor"
138         echo "    include path   : $pythonInclude"
139         echo "    library        : $PYTHON_LIBRARY"
141         unset pythonBin pythonInclude pythonMajor
142     else
143         echo "*** Error: python not installed"
144         echo "***        Deactivate python support by setting WITH_PYTHON=OFF"
145         exit 1
146     fi
151 # define options for mesa support
153 addMesaSupport()
155     [ "$WITH_MESA" = ON ] || return
157     if [ -d "$MESA_INCLUDE_DIR" -a -f "$MESA_LIBRARY" ]
158     then
159         OBJ_ADD="$OBJ_ADD-mesa"
161         addCMakeVariable  VTK_OPENGL_HAS_OSMESA=ON
162         addCMakeVariable  OSMESA_INCLUDE_DIR=$MESA_INCLUDE_DIR
163         addCMakeVariable  OSMESA_LIBRARY=$MESA_LIBRARY
165     else
166        echo "*** Error: no MESA information found"
167        echo "***        Deactivate MESA support by setting WITH_MESA=OFF, or"
168        echo "***        correct paths given by:"
169        echo "***        - MESA_INCLUDE_DIR ($MESA_INCLUDE_DIR)"
170        echo "***        - MESA_LIBRARY ($MESA_LIBRARY)"
171        exit 1
172     fi
177 # discover where things are or should be put
179 getPaths()
181     # set paraview environment
182     for i in $PWD $WM_THIRD_PARTY_DIR
183     do
184         ParaView_INST_DIR=$i/$PARAVIEW_SRC
185         [ -d $ParaView_INST_DIR ] && break
186     done
188     if [ ! -d "$ParaView_INST_DIR" ]
189     then
190         # last chance: maybe already in the paraview directory
191         [ "${PWD##*/}" = $PARAVIEW_SRC ] && ParaView_INST_DIR=$PWD
193         [ -d "$ParaView_INST_DIR" ] || {
194             echo "did not find $PARAVIEW_SRC in these directories:"
195             echo "  PWD=$PWD"
196             echo "  WM_THIRD_PARTY_DIR=$WM_THIRD_PARTY_DIR"
197             echo "abort build"
198             exit 1
199         }
200     fi
202     # ParaView_DIR=$ParaView_INST_DIR/platforms/$WM_ARCH$WM_COMPILER$OBJ_ADD
203     ParaView_DIR=$ParaView_INST_DIR/platforms/$WM_ARCH$WM_COMPILER
204     echo "ParaView_DIR=$ParaView_DIR"
209 # configure via cmake, but don't actually build anything
211 configParaView()
213     # remove any existing build folder and recreate
214     if [ -d $ParaView_DIR ]
215     then
216         echo "removing old build/install directory"
217         rm -rf $ParaView_DIR
218     fi
219     mkdir -p $ParaView_DIR
221     cd $ParaView_DIR
223     echo "----"
224     echo "Configuring $PARAVIEW_SRC"
225     echo "    MPI support    : $WITH_MPI"
226     echo "    Python support : $WITH_PYTHON"
227     echo "    MESA support   : $WITH_MESA"
228     echo "    Source         : $ParaView_INST_DIR"
229     echo "    Target         : $ParaView_DIR"
230     echo "----"
231     echo
232     echo cmake \
233         -DCMAKE_INSTALL_PREFIX:PATH=$ParaView_DIR \
234         $CMAKE_VARIABLES \
235         ../..
236     echo
237     echo "----"
238     echo
240     # run cmake to create Makefiles
241     cmake \
242         -DCMAKE_INSTALL_PREFIX:PATH=$ParaView_DIR \
243         $CMAKE_VARIABLES \
244         ../..
250 # invoke make
251 # also link bin/ to lib/paraview-* for development without installation
253 makeParaView()
255     cd $ParaView_DIR || exit 1  # change to build folder
256     echo "    Starting make"
258     if [ -r /proc/cpuinfo ]
259     then
260         WM_NCOMPPROCS=$(egrep "^processor" /proc/cpuinfo | wc -l)
261         [ $WM_NCOMPPROCS -le 8 ] || WM_NCOMPPROCS=8
263         time make -j $WM_NCOMPPROCS
264     else
265         time make
266     fi
267     echo "    Done make"
269     echo "    For quicker development, linking lib/paraview-$PARAVIEW_MAJOR_VERSION/ -> bin/"
270     rm -rf lib/paraview-$PARAVIEW_MAJOR_VERSION
271     mkdir lib 2>/dev/null
272     ( cd lib && ln -s ../bin paraview-$PARAVIEW_MAJOR_VERSION )
277 # adjust hard-links (internal function)
278 # Note: use loop with grep to avoid touching too many files
280 fixHardLinks()
282     envName=$1
283     string=$2
284     shift 2
286     echo "-- Replacing path hard links for \$$envName"
288     for fileSpec
289     do
290         echo -n "   $fileSpec: "
291         for i in $(find . -type f -iname "$fileSpec")
292         do
293             if grep -q "$string" $i
294             then
295                 echo -n "#"
296                 sed -i "s,$string,\$ENV{$envName},g" $i
297             fi
298         done
299         echo
300     done
305 # replace absolute paths with environment variables
306 # This triggers a partial (or even a full) rebuild, but might let us
307 # find our files later if we relocate the build
309 fixCMakeFiles()
311     cd $ParaView_DIR || exit 1  # change to build folder
313     # Replace path with env variable: ParaView_DIR
314     fixHardLinks ParaView_DIR "$ParaView_DIR" '*.cmake'
316     # Replace path with env variable: ParaView_INST_DIR
317     fixHardLinks ParaView_INST_DIR "$ParaView_INST_DIR" '*.cmake'
319     # Replace path with env variable: MPI_ARCH_PATH
320     if [ "$WITH_MPI" = ON ]
321     then
322         fixHardLinks MPI_ARCH_PATH "$MPI_ARCH_PATH" '*.cmake'
323     fi
325     # Replace path with env variable: CMAKE_HOME
326     if [ -r "$CMAKE_HOME" ]
327     then
328         fixHardLinks CMAKE_HOME "$CMAKE_HOME" '*cmake*'
329     fi
331     # Replace path with env variable: WM_COMPILER_DIR
332     # (include cmake.check_cache)
333     # This triggers a complete rebuild (with cmake-2.6.2), but is likely
334     # needed when redistributing files
335     fixHardLinks WM_COMPILER_DIR "$WM_COMPILER_DIR" '*cmake*'
340 # make html documentation (mostly just for the readers/writers)
342 makeDocs()
344     cd $ParaView_DIR || exit 1  # change to build folder
345     echo "    Creating html documentation"
347     make HTMLDocumentation
352 # actually install the program
354 installParaView()
356     cd $ParaView_DIR || exit 1  # change to build folder
357     echo "    Installing ParaView to $ParaView_DIR"
359     echo "disabled 'make install' for now, just use links"
361     # about.txt may be missing
362     paraviewLibDir="$ParaView_DIR/lib/paraview-$PARAVIEW_MAJOR_VERSION"
363     if [ -d "$paraviewLibDir" -a ! -e "$paraviewLibDir/about.txt" ]
364     then
365         echo "paraview-$PARAVIEW_MAJOR_VERSION installed - $(date)" > $paraviewLibDir/about.txt
366     fi
368 cat<< INFO
369     ---
370     Installation complete
371     Set environment variables:
373         export ParaView_INST_DIR=$ParaView_INST_DIR
374         export ParaView_DIR=$ParaView_DIR
375         export PV_PLUGIN_PATH=$FOAM_LIBBIN
376         export PATH=\$ParaView_DIR/bin:\$PATH
377     ---
378 INFO
382 # clear all the variables used before using any of the functions
383 unset VERBOSE
384 unset WITH_MPI WITH_MESA
385 unset WITH_PYTHON PYTHON_LIBRARY
386 unset CMAKE_VARIABLES
387 unset OBJ_ADD
389 # start with these general settings
390 addCMakeVariable  VTK_USE_TK=FALSE
391 addCMakeVariable  BUILD_SHARED_LIBS:BOOL=ON VTK_USE_RPATH:BOOL=OFF
392 addCMakeVariable  CMAKE_BUILD_TYPE:STRING=Release
394 # include development files in "make install"
395 addCMakeVariable  PARAVIEW_INSTALL_DEVELOPMENT:BOOL=ON
397 # ----------------------------------------------------------------- end-of-file