-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.sh
executable file
·58 lines (50 loc) · 1.04 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
#!/bin/bash
BUILD_TYPE="${1:-Release}"
case "${BUILD_TYPE}" in
"Debug")
SUFFIX="Debug"
;;
"Release")
SUFFIX="Release"
;;
"RelWithDebInfo")
SUFFIX="RelWithDebInfo"
;;
*)
echo "Unknown build type: ${BUILD_TYPE}"
exit 1
;;
esac
BUILD_DIR="build-${SUFFIX}"
git submodule status | while read -r LINE; do
GIT_SUBMOD=$(echo $LINE | awk '{print $2}')
if [[ $LINE == -* ]]; then
echo "Initializing submodule $GIT_SUBMOD"
git submodule update --init --recursive $GIT_SUBMOD
else
echo "Submodule ${GIT_SUBMOD} is already initialized"
fi
done
mkdir -p "${BUILD_DIR}"
cd "${BUILD_DIR}"
rm -f ./CMakeCache.txt
NINJA_BIN="$(which ninja 2>&1)";
if [ $? -ne 0 ]; then
NINJA_BIN="$(which ninja-build 2>&1)";
if [ $? -ne 0 ]; then
NINJA_BIN="";
fi
fi
if [ -z $NINJA_BIN ]; then
echo "Using make build system"
cmake .. -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" ${@:2}
cmake --build . -- -j5
STATUS=$?
else
echo "Using Ninja build system"
cmake .. -G Ninja -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" ${@:2}
ninja
STATUS=$?
fi
cd ..
exit $STATUS