-
Notifications
You must be signed in to change notification settings - Fork 15
/
build.sh
71 lines (59 loc) · 1.67 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
#!/usr/bin/env bash
set -eu -o pipefail
TARGETS="gram|all|test_main"
BUILD_TYPES="DEBUG|REL_WITH_ASSERTS"
usage(){
echo "Builds the gramtools backend"
echo "usage: $0 [--target ($TARGETS)] [--build_type ($BUILD_TYPES)] [--static]"
echo -e "\tDefaults: --target gram --build_type REL_WITH_ASSERTS"
echo -e "\tPass --static to make a standalone executable"
exit 0
}
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--target)
TARGET="$2"
[[ "$TARGET" =~ $TARGETS ]] || usage
shift
shift
;;
--build_type)
BUILD_TYPE="$2"
[[ "$BUILD_TYPE" =~ $BUILD_TYPES ]] || usage
shift
shift
;;
--static)
STATIC="-static"
shift
;;
*) # unknown option
usage
;;
esac
done
TARGET=${TARGET:-gram}
BUILD_TYPE=${BUILD_TYPE:-REL_WITH_ASSERTS}
STATIC=${STATIC:- }
[[ "$STATIC" =~ -static| ]] || usage
BASE_DIR=$(realpath $(dirname $0))
CUR_DIR=$(pwd)
EXIT_CODE=0
conan >/dev/null 2>&1 || EXIT_CODE=$?
if [[ "$EXIT_CODE" != 0 ]]; then
echo "Missing conan: first run 'pip install conan'"
exit 1
fi
BUILD_DIR="${BASE_DIR}/cmake-build"
STDOUT_FILE="${BUILD_DIR}/build_stdout.txt"
echo "Building in: ${BUILD_DIR}" >&1
echo "Writing stdout to: ${STDOUT_FILE}" >&1
mkdir -p "${BUILD_DIR}" && cd "${BUILD_DIR}"
CMAKE_OPTS="-DCMAKE_EXE_LINKER_FLAGS=${STATIC} -DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
conan install .. -s compiler.libcxx=libstdc++11 --build=missing > "$STDOUT_FILE"
CC=gcc CXX=g++ cmake "$CMAKE_OPTS" .. | tee -a "$STDOUT_FILE"
make -j 4 "${TARGET}" | tee -a "$STDOUT_FILE"
[[ "${TARGET}" == "test_main" ]] && ctest -V
cd "$CUR_DIR"