]> Creatis software - cpPlugins.git/blob - third_party_installers/cpPlugins_Install_VTK.sh
0812809a93ab0b6645a0308785c2fa8980f99749
[cpPlugins.git] / third_party_installers / cpPlugins_Install_VTK.sh
1 #!/bin/bash
2
3 function abspath()
4 {
5     pushd . > /dev/null
6     if [ -d "$1" ]; then
7         cd "$1"
8         dirs -l +0
9     else
10         cd "`dirname \"$1\"`"
11         cur_dir=`dirs -l +0`
12         if [ "$cur_dir" == "/" ]; then
13             echo "$cur_dir`basename \"$1\"`"
14         else
15             echo "$cur_dir/`basename \"$1\"`"
16         fi
17     fi
18     popd > /dev/null
19 }
20
21 ## Some configuration variables
22 number_of_processes="-j4"
23 comp_type=Debug
24
25 ## Locate cmake executable
26 cmake_locations=("/usr/bin" "/usr/local/bin" "${HOME}/local/bin")
27 cmake_exec=""
28 cmake_ver=""
29 for loc in ${cmake_locations[@]}; do
30     cmake_file="$loc/cmake"
31     if [ -x $cmake_file ]; then
32         str=`$cmake_file --version | grep version`
33         version=${str:14}
34         if [ "$cmake_ver" \< "$version" ]; then
35             cmake_ver=$version
36             cmake_exec=$cmake_file
37         fi
38     fi
39 done
40 if [ ! -x $cmake_exec ]; then
41     echo "$0: modify this script to put the correct location of cmake."
42     exit 1
43 fi
44
45 ## Locate qmake executable
46 qmake_locations=("/usr/bin" "/usr/local/bin" "${HOME}/local/bin")
47 qmake_exec=""
48 for loc in ${qmake_locations[@]}; do
49     qmake_file="$loc/qmake"
50     if [ -x $qmake_file ]; then
51         str=`$qmake_file --version | grep Using\ Qt\ version`
52         version=`expr substr "$str" 18 3`
53         if [ "$version" == "4.8" ]; then
54             qmake_exec=$qmake_file
55         fi
56     fi
57 done
58 if [ ! -x $qmake_exec ]; then
59     echo "$0: modify this script to put the correct location of qmake."
60     exit 1
61 fi
62
63 ## Check input parameters and process inputs (if needed)
64 if [ "$#" -eq 1 ]; then
65     valid_extensions=("zip" "tar" "tar.gz" "tar.bz2")
66     actual_ext=""
67     for ext in ${valid_extensions[@]}; do
68         if [ `basename $1 $ext` != $1 ]; then
69             actual_ext=$ext
70         fi
71     done
72     if [ "x$actual_ext" == "x" ]; then
73         echo "$0: Invalid file type."
74         exit 1
75     fi
76     canonical_path=`abspath $1`
77     source_dir=`dirname $canonical_path`/`basename $1 .$actual_ext`
78     build_dir=`dirname $canonical_path`/`basename $1 .$actual_ext`-build
79     echo -n "Cleaning directories... "
80     rm -rf $source_dir
81     rm -rf $build_dir
82     echo "done."
83     echo -n "Creating directories... "
84     mkdir -p $source_dir
85     mkdir -p $build_dir
86     echo "done."
87     echo -n "Extracting sources... "
88     if [ "$actual_ext" == "zip" ]; then
89         echo unzip $canonical_path
90     elif [ "$actual_ext" == "tar" ]; then
91         tar xf $canonical_path -C $source_dir --strip-components=1
92     elif [ "$actual_ext" == "tar.gz" ]; then
93         tar xzf $canonical_path -C $source_dir --strip-components=1
94     elif [ "$actual_ext" == "tar.bz2" ]; then
95         tar xjf $canonical_path -C $source_dir --strip-components=1
96     else
97         echo "$0: Invalid file type."
98         exit 1
99     fi
100     echo "done!"
101 elif [ "$#" -eq 2 ]; then
102     source_dir=`dirname $1`
103     build_dir=`dirname $2`
104 else
105     echo "Usage: [vtk_package] or [vtk_source_dir vtk_build_dir]" 
106 fi
107
108 echo "Given source dir : \"$source_dir\""
109 echo "Given build dir  : \"$build_dir\""
110
111 echo "Configuring sources... "
112 cd $build_dir
113 $cmake_exec \
114     -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \
115     -DBUILD_DOCUMENTATION:BOOL=OFF \
116     -DBUILD_EXAMPLES:BOOL=OFF \
117     -DBUILD_SHARED_LIBS:BOOL=ON \
118     -DBUILD_TESTING:BOOL=OFF \
119     -DQT_QMAKE_EXECUTABLE:PATH=$qmake_exec \
120     -DCMAKE_BUILD_TYPE:STRING=$comp_type \
121     -DModule_vtkGUISupportQt:BOOL=ON \
122     -DModule_vtkGUISupportQtOpenGL:BOOL=ON \
123     -DModule_vtkGUISupportQtSQL:BOOL=OFF \
124     -DModule_vtkGUISupportQtWebkit:BOOL=OFF \
125     -DCMAKE_INSTALL_PREFIX:PATH=${HOME}/local \
126     ${source_dir}
127 echo "Configuring sources... done."
128
129 echo "Compiling sources..."
130 cd $build_dir
131 make $number_of_processes
132 echo "Compiling sources... done."
133
134 echo "Installing package..."
135 cd $build_dir
136 make -j install
137 echo "Installing package... done."
138
139 ## eof - $RCSfile$