forked from UZ-SLAMLab/ORB_SLAM3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·132 lines (106 loc) · 3.74 KB
/
install.sh
File metadata and controls
executable file
·132 lines (106 loc) · 3.74 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ "${1:-}" == "--force" ]]; then
FORCE_REBUILD=1
fi
FORCE_REBUILD="${FORCE_REBUILD:-0}"
if command -v nproc >/dev/null 2>&1; then
BUILD_JOBS="${BUILD_JOBS:-$(nproc)}"
else
BUILD_JOBS="${BUILD_JOBS:-1}"
fi
require_command() {
local command_name="$1"
if ! command -v "$command_name" >/dev/null 2>&1; then
echo "Error: required command '$command_name' is not available in PATH." >&2
exit 1
fi
}
require_directory() {
local directory_path="$1"
if [[ ! -d "$directory_path" ]]; then
echo "Error: required directory does not exist: $directory_path" >&2
exit 1
fi
}
require_file() {
local file_path="$1"
if [[ ! -f "$file_path" ]]; then
echo "Error: required file does not exist: $file_path" >&2
exit 1
fi
}
ensure_orb_vocabulary() {
local vocabulary_dir="$ROOT_DIR/Vocabulary"
local vocabulary_text="$vocabulary_dir/ORBvoc.txt"
local vocabulary_archive="$vocabulary_dir/ORBvoc.txt.tar.gz"
if [[ -f "$vocabulary_text" ]]; then
echo "[ORB_SLAM3] Vocabulary already extracted, skipping."
return
fi
require_command tar
require_file "$vocabulary_archive"
echo "[ORB_SLAM3] Extracting ORBvoc.txt from archive..."
tar -xzf "$vocabulary_archive" -C "$vocabulary_dir"
if [[ ! -f "$vocabulary_text" ]]; then
echo "Error: extraction did not produce expected file: $vocabulary_text" >&2
exit 1
fi
}
clean_build_caches() {
echo "[ORB_SLAM3] Force rebuild: removing all build caches..."
rm -rf "$ROOT_DIR/Thirdparty/DBoW2/build"
rm -rf "$ROOT_DIR/Thirdparty/g2o/build"
rm -rf "$ROOT_DIR/Thirdparty/Sophus/build"
rm -rf "$ROOT_DIR/build"
}
build_with_cmake() {
local source_dir="$1"
local build_dir="$2"
local target_name="$3"
shift 3
echo "[ORB_SLAM3] Configuring ${target_name}..."
cmake -S "$source_dir" -B "$build_dir" -DCMAKE_BUILD_TYPE=Release "$@"
echo "[ORB_SLAM3] Building ${target_name}..."
cmake --build "$build_dir" -- -j"${BUILD_JOBS}"
}
main() {
if [[ -f "$ROOT_DIR/lib/libORB_SLAM3.so" ]] && [[ "$FORCE_REBUILD" != "1" ]]; then
echo "[ORB_SLAM3] Already built, skipping. Use --force to rebuild."
exit 0
fi
if [[ "$FORCE_REBUILD" == "1" ]]; then
clean_build_caches
fi
require_command cmake
require_directory "$ROOT_DIR/Thirdparty/DBoW2"
require_directory "$ROOT_DIR/Thirdparty/g2o"
require_directory "$ROOT_DIR/Thirdparty/Sophus"
require_directory "$ROOT_DIR/Vocabulary"
ensure_orb_vocabulary
build_with_cmake "$ROOT_DIR/Thirdparty/DBoW2" "$ROOT_DIR/Thirdparty/DBoW2/build" "Thirdparty/DBoW2"
build_with_cmake "$ROOT_DIR/Thirdparty/g2o" "$ROOT_DIR/Thirdparty/g2o/build" "Thirdparty/g2o"
build_with_cmake \
"$ROOT_DIR/Thirdparty/Sophus" \
"$ROOT_DIR/Thirdparty/Sophus/build" \
"Thirdparty/Sophus" \
-DBUILD_TESTS=OFF \
-DBUILD_EXAMPLES=OFF
build_with_cmake "$ROOT_DIR" "$ROOT_DIR/build" "ORB_SLAM3"
if [[ ! -f "$ROOT_DIR/lib/libORB_SLAM3.so" ]]; then
echo "Error: expected output library not found: $ROOT_DIR/lib/libORB_SLAM3.so" >&2
exit 1
fi
if python3 -c "import pybind11" 2>/dev/null; then
echo "[ORB_SLAM3] Building pybind11 Python bindings..."
cmake -S "$ROOT_DIR" -B "$ROOT_DIR/build" \
-DCMAKE_BUILD_TYPE=Release \
-Dpybind11_DIR="$(python3 -m pybind11 --cmakedir)"
cmake --build "$ROOT_DIR/build" --target orbslam3_python -- -j"${BUILD_JOBS}"
else
echo "[ORB_SLAM3] pybind11 not found, skipping Python bindings."
fi
echo "[ORB_SLAM3] Install build complete."
}
main "$@"