compile.sh 3.47 KB
Newer Older
1 2
#Basic Librairies And Applications for Robotics (BLAAR)
#Copyright  ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2015 - 2017)
Arnaud Blanchard's avatar
Arnaud Blanchard committed
3 4 5 6 7
#This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
#You can use, modify and/ or redistribute the software under the terms of the CeCILL v2.1 license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
#As a counterpart to the access to the source code and  rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights,  and the successive licensors have only limited liability.
#In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean  that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge.
#Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security.
Arnaud Blanchard's avatar
Arnaud Blanchard committed
8
#The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms.
Arnaud Blanchard's avatar
Arnaud Blanchard committed
9

10 11
#!/usr/bin/env bash #Use your $PATH to find bash
set -o errexit  #Exit on first error
Arnaud Blanchard's avatar
Arnaud Blanchard committed
12
set -o nounset  #Error if a variable is used but not defined
13 14 15
set -o pipefail #Error if a pipe fail

usage(){
Arnaud Blanchard's avatar
Arnaud Blanchard committed
16
    echo "usage: compile.sh [-h] <project dir> [Release|Debug|RelWithDebugInfo|MinSizeRel] [<target>]"
17 18
}

Arnaud Blanchard's avatar
Arnaud Blanchard committed
19 20
args=$(getopt h $*) || { usage;  exit 1; }
set -- $args #update positional parameter
Arnaud Blanchard's avatar
Arnaud Blanchard committed
21 22 23 24 25
while [ $# -gt 0 ]
do
case "$1" in
(-h) usage; exit 0;;
(--) shift; break;;
26
(-*) echo "$0: error - unrecognized option $1"; exit 1;;
Arnaud Blanchard's avatar
Arnaud Blanchard committed
27 28 29 30 31
(*)  break;;
esac
shift
done

32
[ $# -lt 1 ] && { echo "Missing project directory."; usage; exit 1; }
33

34
#We go to the project directory and get the directory name then we go back to seach for the baar directory
35
cd $1
36 37 38
project_dir="$PWD"
project_name=$(basename $project_dir)
cd - >/dev/null #Now we have the project directory we go back in current directory without message (/dev/null)
39

40
cd $(dirname $0) #We go in the directory of the current program which is in blaar
41 42
blaar_dir="$PWD"
blaar_build_dir="${blaar_dir}_build"
43

44
echo "Compiling **$project_dir**"
45

46
if [ $# -gt 1 ]; then
47
case $2 in
Arnaud Blanchard's avatar
Arnaud Blanchard committed
48 49
    Release|Debug|RelWithDebugInfo|MinSizeRel) build_type="$2";;
    *)echo "Unknown build type '$2'"; usage;;
50 51 52 53
esac
else build_type="Release"
fi

54 55
if [ $# -gt 3 ]; then
target=$(basename $3)
Arnaud Blanchard's avatar
Arnaud Blanchard committed
56
else
57
target="$project_name"
Arnaud Blanchard's avatar
Arnaud Blanchard committed
58 59
fi

Arnaud Blanchard's avatar
Arnaud Blanchard committed
60
build_dir="$blaar_build_dir/cmake_files_${build_type}/$project_name"
61
mkdir -p "$build_dir"
62 63
mkdir -p "$build_dir/lib"

64
mkdir -p "$blaar_build_dir/Release"
65 66

[ -d build ] || ln -s "$blaar_build_dir" build
67
[ -d bin ] || ln -s "$blaar_build_dir/Release" bin
68

69
cd $build_dir
70

71 72
#On mac and linux  -nt does not return the same if the file does not exist. We have to check the no existance or seniority
[ ! -e build.ninja -o $project_dir/CMakeLists.txt -nt build.ninja ] && {
73
    cmake --no-warn-unused-cli -GNinja    $project_dir -DCMAKE_BUILD_TYPE=$build_type -DLIBRARY_OUTPUT_PATH="${blaar_build_dir}/${build_type}/lib" -DEXECUTABLE_OUTPUT_PATH="${blaar_build_dir}/${build_type}"
74
}
Arnaud Blanchard's avatar
Arnaud Blanchard committed
75
ninja