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