-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·53 lines (45 loc) · 1.28 KB
/
build.sh
File metadata and controls
executable file
·53 lines (45 loc) · 1.28 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
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
BUILD_DIR="${ROOT}/build"
BUILD_TYPE="${BUILD_TYPE:-Release}"
JOBS="${JOBS:-$(nproc 2>/dev/null || sysctl -n hw.logicalcpu 2>/dev/null || echo 4)}"
usage() {
echo "usage: $0 [clean|debug|release|run|install|lint]"
exit 1
}
configure() {
local extra_args=()
if command -v ninja &>/dev/null; then
extra_args+=(-G Ninja)
fi
cmake -S "$ROOT" -B "$BUILD_DIR" \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
"${extra_args[@]}"
ln -sf "${BUILD_DIR}/compile_commands.json" "${ROOT}/compile_commands.json" 2>/dev/null || true
}
build() {
configure
cmake --build "$BUILD_DIR" --parallel "$JOBS"
}
CMD="${1:-release}"
case "$CMD" in
clean) rm -rf "$BUILD_DIR" ;;
debug) BUILD_TYPE=Debug build ;;
release) BUILD_TYPE=Release build ;;
run)
BUILD_TYPE=Release build
exec "${BUILD_DIR}/htop_killer"
;;
install)
BUILD_TYPE=Release build
cmake --install "$BUILD_DIR" --prefix /usr/local
;;
lint)
configure
find "${ROOT}/src" "${ROOT}/include" \( -name '*.cpp' -o -name '*.hpp' \) \
| xargs clang-tidy -p "${BUILD_DIR}"
;;
*) usage ;;
esac