-
Notifications
You must be signed in to change notification settings - Fork 23
/
configure.sh
executable file
·77 lines (69 loc) · 1.84 KB
/
configure.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
#!/bin/bash
set -o errexit # set -e: exit the script if any statement returns a non-true value
# Program constants
ROOT_DIR="$(
cd "$(dirname "${BASH_SOURCE[0]}")"
pwd -P
)"
BUILD_DIR="$ROOT_DIR/build"
# Program options
CXX=${CXX:-"g++"}
CC=${CC:-"gcc"}
function usage() {
echo -e "Usage:\n$0 [options]"
echo -e "\nConfigure a build directory using the provided options."
echo -e "\nGeneral options:"
echo -e " -h,--help Display this help message"
echo -e " -c,--clang Use clang as compiler"
echo -e " -t,--test Enable the testing target"
echo -e " --cov Enable the coverage"
echo -e "\nClang-specific options:"
echo -e " -y,--tidy Enable clang-tidy static analysis target"
echo
exit "${1:-1}"
}
function configure() {
cmake \
-DCMAKE_C_COMPILER="$CC" \
-DCMAKE_CXX_COMPILER="$CXX" \
-DBUILD_TYPE="$TASK_MANAGER_BUILD_TYPE" \
-DTASK_MANAGER_ENABLE_CLANGTIDY="$TASK_MANAGER_ENABLE_CLANGTIDY" \
-DTASK_MANAGER_BUILD_TESTS="$TASK_MANAGER_BUILD_TESTS" \
-DTASK_MANAGER_ENABLE_COVERAGE="$TASK_MANAGER_ENABLE_COVERAGE" \
"$ROOT_DIR"
}
# Process arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-h | --help)
usage 0
;;
-c | --clang)
CC="clang"
CXX="clang++"
shift
;;
-t | --test)
TASK_MANAGER_BUILD_TESTS="ON"
shift
;;
-y | --tidy)
TASK_MANAGER_ENABLE_CLANGTIDY="ON"
shift
;;
--cov)
TASK_MANAGER_ENABLE_COVERAGE="ON"
shift
;;
-*)
echo -e "unknown option '$1'"
usage
;;
esac
done
# Prevent use of clang-only options with other compilers
if [[ "$TASK_MANAGER_ENABLE_CLANGTIDY" == "ON" && "$CXX" != "clang++" ]]; then
echo -e "cannot use clang-tidy if compiler is not clang"
usage
fi
mkdir -p "$BUILD_DIR" && cd "$BUILD_DIR" && configure