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