-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·74 lines (60 loc) · 1.39 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·74 lines (60 loc) · 1.39 KB
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
#!/bin/bash
#
# Build script for cppcheatsheet project
#
set -uo pipefail
DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PROGRAM="$0"
CLEAN=false
CUDA=false
JOBS=$(nproc 2>/dev/null || sysctl -n hw.ncpu)
info() {
echo -e "[$(date +'%Y-%m-%dT%H:%M:%S%z')][info] $*"
}
err() {
echo -e "[$(date +'%Y-%m-%dT%H:%M:%S%z')][error] $*" >&2
}
usage() {
cat <<EOF
Usage: $PROGRAM [OPTIONS]
Options:
-h,--help show this help
-c,--clean clean build
-j [N],--jobs [N] specify the number of jobs
--cuda enable CUDA support
EOF
}
build() {
local jobs="$1"
local clean="$2"
local cuda="$3"
local dir="${DIR}/build"
local cmake_opts=""
if [ "${clean}" == true ]; then
rm -rf "${dir}"
fi
if [ "${cuda}" == true ]; then
cmake_opts="-DENABLE_CUDA=ON"
fi
set -x
if ! cmake -GNinja -B "${dir}" ${cmake_opts}; then
err "run cmake configuration failed."
return 1
fi
if ! cmake --build "${dir}" -j "${jobs}" --verbose; then
err "build source code failed."
return 1
fi
}
while (( "$#" )); do
case "$1" in
-h|-\?|--help) usage; exit 0 ;;
-j|--jobs) JOBS="${2}"; shift 2 ;;
-c|--clean) CLEAN=true; shift ;;
--cuda) CUDA=true; shift ;;
--*=|-*) err "unsupported option $1"; exit 1 ;;
esac
done
if ! build "${JOBS}" "${CLEAN}" "${CUDA}"; then
exit 1
fi