]> Creatis software - cpPlugins.git/blob - dependencies/cpPlugins_ThirdParty_Install_linux.sh
...
[cpPlugins.git] / dependencies / cpPlugins_ThirdParty_Install_linux.sh
1 #!/bin/bash
2
3 ## ====================================
4 ## == Some base configuration values ==
5 ## ====================================
6
7 cmake_min_version="3.0"
8 qt_min_version="4.8"
9 number_of_cores=`grep -c ^processor /proc/cpuinfo`
10 number_of_threads=`expr $number_of_cores / 2`
11
12 ## =================================
13 ## == Compare two version strings ==
14 ## =================================
15
16 function version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }
17
18 ## ==============================
19 ## == Try to locate base tools ==
20 ## ==============================
21
22 gpp_exe=`which g++`
23 if [ -z "gpp_exe" ]; then
24     echo "ERROR: \"g++\" program was not found."
25     echo "ERROR: Please install \"g++\""
26 fi
27
28 make_exe=`which make`
29 if [ -z "$make_exe" ]; then
30     echo "ERROR: \"make\" program was not found."
31     echo "ERROR: Please install \"make\""
32 fi
33
34 ## ===============
35 ## == Verify Qt ==
36 ## ===============
37
38 read -p "Do you want to use Qt4.8? [y/N] " -n 1 -r
39 echo
40 if [[ $REPLY =~ ^[Yy]$ ]]; then
41     cont=true
42     qmake_exe=`which qmake`
43     while [ $cont == true ]; do
44         if [ -z "$qmake_exe" ]; then
45             read -e -p "Please provide a valid location for qmake: " tmp
46             eval tmp=$tmp
47             qmake_exe=`readlink -f $tmp`
48         fi
49         read -p "I am going to use \"$qmake_exe\" as the entry tool for Qt. Is this ok? [y/N] " -n 1 -r
50         echo
51         if [[ $REPLY =~ ^[Nn]$ ]]; then
52             qmake_exe=""
53         else
54             cont=false
55         fi
56     done
57     qt_version=`$qmake_exe -v | grep Using\ Qt\ version | sed 's/Using\ Qt\ version\ //g'`
58     if version_gt $qt_min_version $qt_version; then
59         echo "FATAL ERROR: your Qt version is $qt_version, but needed version should be at least $qt_min_version"
60     fi
61 fi
62
63 ## ==================
64 ## == Verify cmake ==
65 ## ==================
66
67 cmake_qt_options="--no-qt-gui"
68 if [ -x "$qmake_exe" ]; then
69     cmake_qt_options="--qt-gui --qt-qmake=$qmake_exe"
70 fi
71
72 cont=true
73 cmake_exe=`which cmake`
74 while [ $cont == true ]; do
75     if [ -z "$cmake_exe" ]; then
76         read -e -p "Please provide a valid location for cmake: " tmp
77         eval tmp=$tmp
78         cmake_exe=`readlink -f $tmp`
79     fi
80     read -p "I am going to use \"$cmake_exe\". Is this ok? [y/N] " -n 1 -r
81     echo
82     if [[ $REPLY =~ ^[Nn]$ ]]; then
83         cmake_exe=""
84     else
85         cont=false
86     fi
87 done
88 if [ -z $cmake_exe ]; then
89     echo "FATAL ERROR: cmake is really needed to build cpPlugins."
90     exit 1
91 fi
92
93 cmake_mime=`file -bzk --mime-type $cmake_exe`
94 if [ "$cmake_mime" != "application/x-executable" ]; then
95     echo "WARNING: I will try to compile cmake..."
96     if [[ -f $cmake_exe ]]; then
97         if [ "$cmake_mime" == "application/x-tar" ]; then
98             sub_mime=`file -b --mime-type $cmake_exe`
99             if [ $sub_mime == "application/gzip" ]; then
100                 cmake_source_dir=`dirname $cmake_exe`/`basename $cmake_exe .tar.gz`
101                 cmake_binary_dir=`dirname $cmake_exe`/`basename $cmake_exe .tar.gz`-build
102                 echo -n "==> Extracting cmake sources... "
103                 rm -rf $cmake_source_dir $cmake_binary_dir
104                 mkdir -p $cmake_source_dir $cmake_binary_dir
105                 tar xzf $cmake_exe -C $cmake_source_dir --strip-components=1
106                 echo "done."
107             fi
108         fi
109     elif [[ -d $cmake_exe ]]; then
110         cmake_source_dir="$cmake_exe"
111         cmake_binary_dir="$cmake_exe"-build
112     else
113         echo "FATAL ERROR: $cmake_exe is not a valid file/directory"
114         exit 1
115     fi
116
117     read -e -p "==> Please provide instalation location for \"cmake\": " tmp
118     eval tmp=$tmp
119     cmake_prefix=`readlink -f $tmp`
120
121     echo "==> Configuring sources... "
122     cd $cmake_binary_dir
123     $cmake_source_dir/bootstrap --prefix=$cmake_prefix $cmake_qt_options
124     echo "==> Configuring sources... done."
125
126     echo "==> Compiling sources..."
127     cd $cmake_binary_dir
128     make -j$number_of_threads
129     echo "==> Compiling sources... done."
130
131     echo "==> Installing package..."
132     cd $cmake_binary_dir
133     make -j install
134     echo "==> Installing package... done."
135     cmake_exe=$cmake_binary_dir/bin/cmake
136 fi
137 cmake_version=`$cmake_exe --version | grep version | sed 's/cmake\ version\ //g'`
138
139 if version_gt $cmake_min_version $cmake_version; then
140     echo "FATAL ERROR: your cmake version is $cmake_version, but needed version should be at least $cmake_min_version"
141 fi
142
143 ## ===============
144 ## == Build VTK ==
145 ## ===============
146
147 cont=true
148 vtk_sources=""
149 while [ $cont == true ]; do
150     if [ -z "$vtk_sources" ]; then
151         read -e -p "Please provide a valid location for VTK: " tmp
152         eval tmp=$tmp
153         vtk_sources=`readlink -f $tmp`
154     fi
155     read -p "I am going to use \"$vtk_sources\". Is this ok? [y/N] " -n 1 -r
156     echo
157     if [[ $REPLY =~ ^[Nn]$ ]]; then
158         vtk_sources=""
159     else
160         cont=false
161     fi
162 done
163 if [ -z $vtk_sources ]; then
164     echo "FATAL ERROR: VTK is really needed to build cpPlugins."
165     exit 1
166 fi
167
168 echo "Now, I will try to compile VTK..."
169 vtk_mime=`file -bzk --mime-type $vtk_sources`
170 if [[ -f $vtk_sources ]]; then
171     if [ "$vtk_mime" == "application/x-tar" ]; then
172         sub_mime=`file -b --mime-type $vtk_sources`
173         if [ $sub_mime == "application/gzip" ]; then
174             vtk_source_dir=`dirname $vtk_sources`/`basename $vtk_sources .tar.gz`
175             vtk_binary_dir=`dirname $vtk_sources`/`basename $vtk_sources .tar.gz`-build
176             echo -n "==> Extracting VTK sources... "
177             rm -rf $vtk_source_dir $vtk_binary_dir
178             mkdir -p $vtk_source_dir $vtk_binary_dir
179             tar xzf $vtk_sources -C $vtk_source_dir --strip-components=1
180             echo "done."
181         fi
182     fi
183 elif [[ -d $vtk_sources ]]; then
184     vtk_source_dir="$vtk_sources"
185     vtk_binary_dir="$vtk_sources"-build
186 else
187     echo "FATAL ERROR: $vtk_sources is not a valid file/directory"
188     exit 1
189 fi
190
191 read -e -p "==> Please provide instalation location for \"VTK\": " tmp
192 eval tmp=$tmp
193 vtk_prefix=`readlink -f $tmp`
194
195 vtk_build_type=MinSizeRel
196
197 echo "==> Configuring sources... "
198 cd $vtk_binary_dir
199 if [ -x "$qmake_exe" ]; then
200     $cmake_exe \
201         -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \
202         -DBUILD_DOCUMENTATION:BOOL=OFF \
203         -DBUILD_EXAMPLES:BOOL=OFF \
204         -DBUILD_SHARED_LIBS:BOOL=ON \
205         -DBUILD_TESTING:BOOL=OFF \
206         -DQT_QMAKE_EXECUTABLE:PATH=$qmake_exe \
207         -DCMAKE_BUILD_TYPE:STRING=$vtk_build_type \
208         -DModule_vtkGUISupportQt:BOOL=ON \
209         -DModule_vtkGUISupportQtOpenGL:BOOL=ON \
210         -DModule_vtkGUISupportQtSQL:BOOL=OFF \
211         -DModule_vtkGUISupportQtWebkit:BOOL=OFF \
212         -DCMAKE_INSTALL_PREFIX:PATH=$vtk_prefix \
213         $vtk_source_dir
214 else
215     $cmake_exe \
216         -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \
217         -DBUILD_DOCUMENTATION:BOOL=OFF \
218         -DBUILD_EXAMPLES:BOOL=OFF \
219         -DBUILD_SHARED_LIBS:BOOL=ON \
220         -DBUILD_TESTING:BOOL=OFF \
221         -DCMAKE_BUILD_TYPE:STRING=$build_type \
222         -DCMAKE_INSTALL_PREFIX:PATH=$vtk_prefix \
223         $vtk_source_dir
224 fi
225 echo "==> Configuring sources... done."
226
227 echo "==> Compiling sources..."
228 cd $vtk_binary_dir
229 make -j$number_of_threads
230 echo "==> Compiling sources... done."
231
232 echo "==> Installing package..."
233 cd $vtk_binary_dir
234 make -j install
235 echo "==> Installing package... done."
236
237 ## ===============
238 ## == Build ITK ==
239 ## ===============
240
241 cont=true
242 itk_sources=""
243 while [ $cont == true ]; do
244     if [ -z "$itk_sources" ]; then
245         read -e -p "Please provide a valid location for ITK: " tmp
246         eval tmp=$tmp
247         itk_sources=`readlink -f $tmp`
248     fi
249     read -p "I am going to use \"$itk_sources\". Is this ok? [y/N] " -n 1 -r
250     echo
251     if [[ $REPLY =~ ^[Nn]$ ]]; then
252         itk_sources=""
253     else
254         cont=false
255     fi
256 done
257 if [ -z $itk_sources ]; then
258     echo "FATAL ERROR: ITK is really needed to build cpPlugins."
259     exit 1
260 fi
261
262 echo "Now, I will try to compile ITK..."
263 itk_mime=`file -bzk --mime-type $itk_sources`
264 if [[ -f $itk_sources ]]; then
265     if [ "$itk_mime" == "application/x-tar" ]; then
266         sub_mime=`file -b --mime-type $itk_sources`
267         if [ $sub_mime == "application/gzip" ]; then
268             itk_source_dir=`dirname $itk_sources`/`basename $itk_sources .tar.gz`
269             itk_binary_dir=`dirname $itk_sources`/`basename $itk_sources .tar.gz`-build
270             echo -n "==> Extracting ITK sources... "
271             rm -rf $itk_source_dir $itk_binary_dir
272             mkdir -p $itk_source_dir $itk_binary_dir
273             tar xzf $itk_sources -C $itk_source_dir --strip-components=1
274             echo "done."
275         fi
276     fi
277 elif [[ -d $itk_sources ]]; then
278     itk_source_dir="$itk_sources"
279     itk_binary_dir="$itk_sources"-build
280 else
281     echo "FATAL ERROR: $itk_sources is not a valid file/directory"
282     exit 1
283 fi
284
285 read -e -p "==> Please provide instalation location for \"ITK\": " tmp
286 eval tmp=$tmp
287 itk_prefix=`readlink -f $tmp`
288
289 itk_build_type=MinSizeRel
290
291 echo "==> Configuring sources... "
292 cd $itk_binary_dir
293 $cmake_exe \
294     -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \
295     -DBUILD_DOCUMENTATION:BOOL=OFF \
296     -DBUILD_EXAMPLES:BOOL=OFF \
297     -DBUILD_SHARED_LIBS:BOOL=ON \
298     -DBUILD_TESTING:BOOL=OFF \
299     -DCMAKE_BUILD_TYPE:STRING=$itk_build_type \
300     -DModule_ITKReview:BOOL=ON \
301     -DModule_ITKVtkGlue:BOOL=OFF \
302     -DModule_ParabolicMorphology:BOOL=ON \
303     -DCMAKE_INSTALL_PREFIX:PATH=$itk_prefix \
304     $itk_source_dir
305 echo "==> Configuring sources... done."
306
307 echo "==> Compiling sources..."
308 cd $itk_binary_dir
309 make -j$number_of_threads
310 echo "==> Compiling sources... done."
311
312 echo "==> Installing package..."
313 cd $itk_binary_dir
314 make -j install
315 echo "==> Installing package... done."
316
317 ## eof - $RCSfile$