-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.sh
executable file
·106 lines (90 loc) · 1.84 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
PROGNAME=${0##*/}
CURDIR="$( cd "$(dirname "$0")" ; pwd -P )"
BUILD_TYPE="Release"
BUILD_DIR="build"
TEST="False"
if which nproc; then
# Linux
CORES="$(nproc --all)"
elif which sysctl; then
# MacOS
CORES="$(sysctl -n hw.logicalcpu)"
else
CORES=2
fi
JOBS=$(( (CORES + 1) / 2 ))
usage() {
cat <<EOF
Usage: $PROGNAME [options]
Options:
-h, --help Display this help and exit
-c, --clean Clean build
-d, --debug Build with debug mode
-j, --jobs Use N cores to build
-t, --tetst Build Debug and run tests
EOF
}
clean() {
rm -rf "$BUILD_DIR"
}
test() {
cd ./build/test;
./all_test
cd $CURDIR;
lcov \
--capture \
--directory build/test/ \
--output-file coverage.info \
--test-name coverageHtml > /dev/null
lcov -o coverage.info --extract coverage.info "${CURDIR}/ini/*" > /dev/null
genhtml -o .coverage coverage.info
}
while (( "$#" )); do
case "$1" in
-h|--help)
usage
exit 0
;;
-j|--jobs)
JOBS="$2"
shift 2
;;
-d|--debug)
BUILD_TYPE="Debug"
shift
;;
-t|--test)
BUILD_TYPE="Debug"
TEST="True"
shift
;;
-c|--clean)
clean
shift
;;
-*|--*=)
echo "Invalid arguments"
exit 1
;;
*)
break
;;
esac
done
BUILD_OPTIONS="-DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
mkdir -p "${BUILD_DIR}"
cd "${BUILD_DIR}"
if cmake .. ${BUILD_OPTIONS}; then
if ! make -j "${JOBS}"; then
exit 1
fi
cd "$CURDIR"
if [ "${TEST}" == "True" ]; then
test
cd "$CURDIR"
fi
else
cd "$CURDIR"
exit 1
fi