-
Notifications
You must be signed in to change notification settings - Fork 19
/
build-opencv4-mac.sh
56 lines (48 loc) · 1.46 KB
/
build-opencv4-mac.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
#!/usr/bin/env bash
# ./build-opencv4-mac.sh -n x86_64
# ./build-opencv4-mac.sh -n arm64
HOST_OS=$(uname -s)
NUM_THREADS=1
BUILD_TYPE=Release
if [ "$HOST_OS" == "Darwin" ]; then
NUM_THREADS=$(sysctl -n hw.ncpu)
else
echo "Unsupported OS: $HOST_OS"
exit 0
fi
JAVA_FLAG=""
TARGET_ARCH=""
while getopts "n:j" arg; do
case $arg in
n)
echo "n(TARGET_ARCH):$OPTARG"
TARGET_ARCH="$OPTARG"
;;
j)
echo "j's arg:$OPTARG"
JAVA_FLAG="-DBUILD_FAT_JAVA_LIB=ON -DBUILD_JAVA=ON -DBUILD_opencv_java=ON -DBUILD_opencv_flann=ON"
;;
?)
echo -e "unkonw argument."
exit 1
;;
esac
done
if [ -z "$TARGET_ARCH" ]; then
echo -e "empty TARGET_ARCH."
echo -e "usage1: ./build-opencv3-linux.sh -n x86_64"
echo -e "usage2: ./build-opencv3-linux.sh -n arm64"
exit 1
fi
BUILD_OUTPUT_PATH="build-$BUILD_TYPE-$TARGET_ARCH"
BUILD_INSTALL_PATH="$BUILD_OUTPUT_PATH/install"
mkdir -p "$BUILD_OUTPUT_PATH"
cmake --compile-no-warning-as-error \
-B"$BUILD_OUTPUT_PATH" \
-DCMAKE_INSTALL_PREFIX="$BUILD_INSTALL_PATH" \
-DCMAKE_SYSTEM_NAME="Darwin" -DCMAKE_OSX_DEPLOYMENT_TARGET="10.9" \
-DCMAKE_SYSTEM_PROCESSOR="$TARGET_ARCH" -DCMAKE_OSX_ARCHITECTURES="$TARGET_ARCH" \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CONFIGURATION_TYPES=$BUILD_TYPE \
$(cat opencv4_cmake_options.txt) \
$JAVA_FLAG
cmake --build $BUILD_OUTPUT_PATH --config $BUILD_TYPE --parallel $NUM_THREADS --target install