]> Creatis software - cpPlugins.git/blob - third_party_installers/cpPlugins_Install_ITK.sh
d716a854ffd4af4b7ad47bf6cfd3940b0ea3e4f4
[cpPlugins.git] / third_party_installers / cpPlugins_Install_ITK.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 ## Check input parameters and process inputs (if needed)
46 if [ "$#" -eq 1 ]; then
47     valid_extensions=("zip" "tar" "tar.gz" "tar.bz2")
48     actual_ext=""
49     for ext in ${valid_extensions[@]}; do
50         if [ `basename $1 $ext` != $1 ]; then
51             actual_ext=$ext
52         fi
53     done
54     if [ "x$actual_ext" == "x" ]; then
55         echo "$0: Invalid file type."
56         exit 1
57     fi
58     canonical_path=`abspath $1`
59     source_dir=`dirname $canonical_path`/`basename $1 .$actual_ext`
60     build_dir=`dirname $canonical_path`/`basename $1 .$actual_ext`-build
61     echo -n "Cleaning directories... "
62     rm -rf $source_dir
63     rm -rf $build_dir
64     echo "done."
65     echo -n "Creating directories... "
66     mkdir -p $source_dir
67     mkdir -p $build_dir
68     echo "done."
69     echo -n "Extracting sources... "
70     if [ "$actual_ext" == "zip" ]; then
71         echo unzip $canonical_path
72     elif [ "$actual_ext" == "tar" ]; then
73         tar xf $canonical_path -C $source_dir --strip-components=1
74     elif [ "$actual_ext" == "tar.gz" ]; then
75         tar xzf $canonical_path -C $source_dir --strip-components=1
76     elif [ "$actual_ext" == "tar.bz2" ]; then
77         tar xjf $canonical_path -C $source_dir --strip-components=1
78     else
79         echo "$0: Invalid file type."
80         exit 1
81     fi
82     echo "done!"
83 elif [ "$#" -eq 2 ]; then
84     source_dir=`dirname $1`
85     build_dir=`dirname $2`
86 else
87     echo "Usage: [itk_package] or [itk_source_dir itk_build_dir]" 
88 fi
89
90 echo "Given source dir : \"$source_dir\""
91 echo "Given build dir  : \"$build_dir\""
92
93 echo "Configuring sources... "
94 cd $build_dir
95 $cmake_exec \
96     -DCMAKE_CXX_FLAGS:STRING=-std=c++11 \
97     -DBUILD_DOCUMENTATION:BOOL=OFF \
98     -DBUILD_EXAMPLES:BOOL=OFF \
99     -DBUILD_SHARED_LIBS:BOOL=ON \
100     -DBUILD_TESTING:BOOL=OFF \
101     -DCMAKE_BUILD_TYPE:STRING=$comp_type \
102     -DModule_ITKReview:BOOL=ON \
103     -DModule_ITKVtkGlue:BOOL=OFF \
104     -DCMAKE_INSTALL_PREFIX:PATH=${HOME}/local \
105     ${source_dir}
106 echo "Configuring sources... done."
107
108 echo "Compiling sources..."
109 cd $build_dir
110 make $number_of_processes
111 echo "Compiling sources... done."
112
113 echo "Installing package..."
114 cd $build_dir
115 make -j install
116 echo "Installing package... done."
117
118 ## eof - $RCSfile$