forked from f0enix/motioncam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupenv.sh
executable file
·292 lines (193 loc) · 7.94 KB
/
setupenv.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/bin/bash
set -euxo pipefail
if [[ -z "${ANDROID_NDK-}" ]]; then
echo -e "Please set ANDROID_NDK to point to the NDK installation path"
exit 1
fi
if [[ -z "${LLVM_DIR-}" ]]; then
echo -e "Please set LLVM_DIR to point to LLVM"
exit 1
fi
NUM_CORES="$(python3 -c 'import multiprocessing as mp; print(mp.cpu_count())')"
ANDROID_ABI="arm64-v8a"
OPENCV_VERSION="4.5.4"
LIBEXPAT_VERSION="2.4.1"
LIBEXIV2_VERSION="0.27.4"
ZSTD_VERSION="v1.5.0"
DLIB_VERSION="19.22"
HALIDE_BRANCH=https://github.com/mirsadm/Halide
mkdir -p tmp
pushd tmp
build_opencv() {
OPENCV_ARCHIVE="opencv-${OPENCV_VERSION}.zip"
OPENCV_CONTRIB_ARCHIVE="opencv-contrib-${OPENCV_VERSION}.zip"
curl -L https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip --output ${OPENCV_ARCHIVE}
curl -L https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip --output ${OPENCV_CONTRIB_ARCHIVE}
unzip ${OPENCV_ARCHIVE}
unzip ${OPENCV_CONTRIB_ARCHIVE}
pushd opencv-${OPENCV_VERSION}
mkdir -p build
pushd build
cmake -DCMAKE_BUILD_TYPE=Release -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules -DCMAKE_INSTALL_PREFIX=../build/${ANDROID_ABI} -DCMAKE_SYSTEM_NAME=Android \
-DANDROID_NATIVE_API_LEVEL=21 -DCMAKE_SYSTEM_VERSION=21 -DANDROID_ABI=${ANDROID_ABI} -DCMAKE_ANDROID_ARCH_ABI=${ANDROID_ABI} -DANDROID_STL=c++_shared \
-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang -DWITH_TBB=ON -DBUILD_ANDROID_EXAMPLES=OFF -DBUILD_DOCS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DCPU_BASELINE=NEON \
-DBUILD_JAVA=OFF -DENABLE_NEON=ON -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake ..
make -j${NUM_CORES}
make install
INSTALL_DIR="../../../libMotionCam/thirdparty/opencv"
mkdir -p ${INSTALL_DIR}/libs
mkdir -p ${INSTALL_DIR}/include
mkdir -p ${INSTALL_DIR}/thirdparty
cp -a ./lib/. ${INSTALL_DIR}/libs/.
cp -a ./${ANDROID_ABI}/sdk/native/jni/include/. ${INSTALL_DIR}/include/.
cp -a ./${ANDROID_ABI}/sdk/native/3rdparty/. ${INSTALL_DIR}/thirdparty/.
popd # build
popd # opencv-${OPENCV_VERSION}
touch ".opencv-${OPENCV_VERSION}"
}
build_expat() {
LIBEXPAT_ARCHIVE="libexpat-${LIBEXPAT_VERSION}.tar.gz"
curl -L https://github.com/libexpat/libexpat/releases/download/R_2_4_1/expat-${LIBEXPAT_VERSION}.tar.gz --output ${LIBEXPAT_ARCHIVE}
tar -xvf ${LIBEXPAT_ARCHIVE}
pushd expat-${LIBEXPAT_VERSION}
mkdir -p build
pushd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../build/${ANDROID_ABI} -DCMAKE_SYSTEM_NAME=Android \
-DANDROID_NATIVE_API_LEVEL=21 -DCMAKE_SYSTEM_VERSION=21 -DANDROID_ABI=${ANDROID_ABI} -DCMAKE_ANDROID_ARCH_ABI=${ANDROID_ABI} -DANDROID_STL=c++_shared \
-DEXPAT_BUILD_DOCS=OFF -DEXPAT_BUILD_EXAMPLES=OFF -DEXPAT_BUILD_TESTS=OFF -DEXPAT_BUILD_TOOLS=OFF -DEXPAT_SHARED_LIBS=OFF \
-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake ..
make -j${NUM_CORES}
make install
INSTALL_DIR="../../../libMotionCam/thirdparty/expat"
mkdir -p ${INSTALL_DIR}/lib
mkdir -p ${INSTALL_DIR}/include
cp -a ./${ANDROID_ABI}/include/. ${INSTALL_DIR}/include/.
cp -a ./${ANDROID_ABI}/lib/*.a ${INSTALL_DIR}/lib
popd # build
popd # expat-${LIBEXPAT_VERSION}
touch ".expat-${LIBEXPAT_VERSION}"
}
build_exiv2() {
LIBEXIV2_ARCHIVE="libexiv2-${LIBEXPAT_VERSION}.tar.gz"
curl -L https://www.exiv2.org/builds/exiv2-${LIBEXIV2_VERSION}-Source.tar.gz --output ${LIBEXIV2_ARCHIVE}
tar -xvf ${LIBEXIV2_ARCHIVE}
pushd exiv2-${LIBEXIV2_VERSION}-Source
mkdir -p build
pushd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../build/${ANDROID_ABI} -DCMAKE_SYSTEM_NAME=Android \
-DANDROID_NATIVE_API_LEVEL=21 -DCMAKE_SYSTEM_VERSION=21 -DANDROID_ABI=${ANDROID_ABI} -DCMAKE_ANDROID_ARCH_ABI=${ANDROID_ABI} -DANDROID_STL=c++_shared \
-DEXIV2_BUILD_SAMPLES=OFF -DBUILD_SHARED_LIBS=OFF -DEXIV2_BUILD_EXIV2_COMMAND=OFF \
-DEXPAT_LIBRARY=../../../libMotionCam/thirdparty/expat/lib/libexpat.a -DEXPAT_INCLUDE_DIR=../../../libMotionCam/thirdparty/expat/include \
-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake ..
make -j${NUM_CORES}
make install
INSTALL_DIR="../../../libMotionCam/thirdparty/exiv2"
mkdir -p ${INSTALL_DIR}/lib
mkdir -p ${INSTALL_DIR}/include
cp -a ./${ANDROID_ABI}/include/. ${INSTALL_DIR}/include/.
cp -a ./${ANDROID_ABI}/lib/*.a ${INSTALL_DIR}/lib/.
popd # build
popd # exiv2-${LIBEXIV2_VERSION}-Source
touch ".exiv2-${LIBEXIV2_VERSION}"
}
build_zstd() {
if [ ! -d "zstd-src" ]; then
git clone https://github.com/facebook/zstd zstd-src
fi
pushd zstd-src
git checkout ${ZSTD_VERSION}
pushd build/cmake
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../output/${ANDROID_ABI} -DCMAKE_SYSTEM_NAME=Android \
-DANDROID_NATIVE_API_LEVEL=21 -DCMAKE_SYSTEM_VERSION=21 -DANDROID_ABI=${ANDROID_ABI} -DCMAKE_ANDROID_ARCH_ABI=${ANDROID_ABI} -DANDROID_STL=c++_shared \
-DZSTD_BUILD_STATIC=ON -DZSTD_BUILD_TESTS=OFF -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake .
make -j${NUM_CORES}
make install
INSTALL_DIR="../../../../libMotionCam/thirdparty/zstd"
mkdir -p ${INSTALL_DIR}/lib
mkdir -p ${INSTALL_DIR}/include
cp -a ../output/${ANDROID_ABI}/include/. ${INSTALL_DIR}/include/.
cp -a ../output/${ANDROID_ABI}/lib/*.a ${INSTALL_DIR}/lib/.
popd # /build/cmake
popd # zstd-src
touch ".zstd-${ZSTD_VERSION}"
}
build_dlib() {
DLIB_ARCHIVE="dlib-${DLIB_VERSION}.tar.bz2"
curl -L http://dlib.net/files/${DLIB_ARCHIVE} --output ${DLIB_ARCHIVE}
tar -xvf ${DLIB_ARCHIVE}
pushd dlib-${DLIB_VERSION}
mkdir -p build
pushd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../build/${ANDROID_ABI} -DCMAKE_SYSTEM_NAME=Android \
-DANDROID_NATIVE_API_LEVEL=21 -DCMAKE_SYSTEM_VERSION=21 -DANDROID_ABI=${ANDROID_ABI} -DCMAKE_ANDROID_ARCH_ABI=${ANDROID_ABI} -DANDROID_STL=c++_shared \
-DBUILD_SHARED_LIBS=OFF -DDLIB_USE_CUDA=NO -DDLIB_USE_BLAS=NO -DDLIB_NO_GUI_SUPPORT=YES -DDLIB_LINK_WITH_SQLITE3=NO -DDLIB_PNG_SUPPORT=NO -DDLIB_JPEG_SUPPORT=NO \
-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake ..
make -j${NUM_CORES}
make install
INSTALL_DIR="../../../libMotionCam/thirdparty/dlib"
mkdir -p ${INSTALL_DIR}/lib
mkdir -p ${INSTALL_DIR}/include
cp -a ./${ANDROID_ABI}/include/. ${INSTALL_DIR}/include/.
cp -a ./${ANDROID_ABI}/lib/*.a ${INSTALL_DIR}/lib/.
popd # build
popd # dlib-${LIBEXIV2_VERSION}-Source
touch ".dlib-${DLIB_VERSION}"
}
build_halide() {
if [ ! -d "halide-src" ]; then
git clone ${HALIDE_BRANCH} halide-src
fi
pushd halide-src
git pull
mkdir -p build
pushd build
INSTALL_DIR="../../../libMotionCam/thirdparty/halide"
mkdir -p ${INSTALL_DIR}
cmake -DTARGET_WEBASSEMBLY=OFF -DWITH_TUTORIALS=OFF -DWITH_TESTS=OFF -DWITH_PYTHON_BINDINGS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} ..
make -j${NUM_CORES}
make install
popd # build
popd # halide-src
touch ".halide"
}
halide_generate() {
pushd ../libMotionCam/libMotionCam/generators
./generate.sh
popd
}
# Build dependencies
if [ ! -f ".opencv-${OPENCV_VERSION}" ]; then
build_opencv
fi
if [ ! -f ".expat-${LIBEXPAT_VERSION}" ]; then
build_expat
fi
if [ ! -f ".exiv2-${LIBEXIV2_VERSION}" ]; then
build_exiv2
fi
if [ ! -f ".zstd-${ZSTD_VERSION}" ]; then
build_zstd
fi
if [ ! -f ".dlib-${DLIB_VERSION}" ]; then
build_dlib
fi
if [ ! -f ".halide" ]; then
build_halide
fi
# Generate halide libraries
halide_generate
popd # tmp
# Compile utilities
if [[ "$OSTYPE" == "darwin"* ]]; then
export CPLUS_INCLUDE_PATH=/usr/local/include:/usr/local/include/opencv4
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
export CPLUS_INCLUDE_PATH=/usr/include/opencv4
fi
pushd ./tools/convert
mkdir -p build
cd build
cmake ../
make -j${NUM_CORES}
popd
mkdir -p ./tools/bin
cp tools/convert/build/convert ./tools/bin/convert