forked from niw/iphone_opencv_test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opencv_cmake.sh
executable file
·122 lines (108 loc) · 3.52 KB
/
opencv_cmake.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
#!/bin/sh
if [ "$1" = "-h" -o "$1" = "--help" -o -z "$1" ]; then
echo "USAGE"
echo " $0 [-h,--help] {device,simulator} source_dir"
echo "OPTIONS"
echo " -h, --help Show help and default options"
echo " device Build binary for iOS devices"
echo " simulator Build binary for iOS Simulator"
echo " source_dir Path to OpenCV source directory"
echo "ENVIRONMENT"
echo " INSTALL_PREFIX Path to OpenCV binary directory"
echo " SDK_VERSION iOS SDK version"
echo " IPHONEOS_VERSION_MIN iOS deployment target"
echo " CMAKE_OPTIONS Additional CMake options"
echo " CFLAGS Additional compiler flags"
exit
fi
if ! type 'cmake' > /dev/null 2>&1; then
echo "cmake is not found, please install cmake command which is required to build OpenCV."
exit 1;
fi
TARGET_SDK=`echo "$1"|tr '[:upper:]' '[:lower:]'`
if [ "$TARGET_SDK" = "device" ]; then
TARGET_SDK_NAME="iPhoneOS"
elif [ "$TARGET_SDK" = "simulator" ]; then
TARGET_SDK_NAME="iPhoneSimulator"
else
echo "Please select Device or Simulator."
exit 1
fi
if [ -z "$SDK_VERSION" ]; then
SDK_VERSION="4.3"
fi
if [ -z "$IPHONEOS_VERSION_MIN" ]; then
IPHONEOS_VERSION_MIN="3.0"
fi
DEVELOPER_ROOT="/Developer/Platforms/${TARGET_SDK_NAME}.platform/Developer"
SDK_ROOT="${DEVELOPER_ROOT}/SDKs/${TARGET_SDK_NAME}${SDK_VERSION}.sdk"
if [ ! -d "$SDK_ROOT" ]; then
echo "iOS SDK Version ${SDK_VERSION} is not found, please select iOS version you have."
exit 1
fi
if [ -z "$2" ]; then
echo "Please assign path to OpenCV source directory which includes CMakeLists.txt."
exit 1
else
OPENCV_ROOT="$2"
fi
if [ ! -f "${OPENCV_ROOT}/CMakeLists.txt" ]; then
echo "No CMakeLists.txt in ${OPENCV_ROOT}, please select OpenCV source directory."
exit 1
fi
if [ -z "$INSTALL_PREFIX" ]; then
INSTALL_PREFIX="`pwd`/../opencv_${TARGET_SDK}"
fi
#BUILD_PATH="`pwd`/build_${TARGET_SDK}"
#if [ -d "${BUILD_PATH}" ]; then
# echo "${BUILD_PATH} is found, please remove it prior to run this command."
# exit 1
#else
# mkdir -p "${BUILD_PATH}"
#fi
#cd "${BUILD_PATH}"
echo "Starting cmake..."
echo "CMake version = `cmake --version`"
echo "Target SDK = $TARGET_SDK_NAME"
echo "iOS SDK Version = $SDK_VERSION"
echo "iOS Deployment Target = $IPHONEOS_VERSION_MIN"
echo "OpenCV Root = $OPENCV_ROOT"
echo "OpenCV Install Prefix = $INSTALL_PREFIX"
echo ""
if [ "$TARGET_SDK" = "device" ]; then
CFLAGS="-arch armv6 -arch armv7 -mthumb -miphoneos-version-min=${IPHONEOS_VERSION_MIN} ${CFLAGS}"
ARCH="armv6;armv7"
CMAKE_OPTIONS="-D ENABLE_SSE=OFF -D ENABLE_SSE2=OFF ${CMAKE_OPTIONS}"
else
CFLAGS="-m32 ${CFLAGS}"
ARCH="i386"
CMAKE_OPTIONS="-D CMAKE_OSX_DEPLOYMENT_TARGET=\"10.6\" ${CMAKE_OPTIONS}"
fi
env \
CFLAGS="${CFLAGS}" \
CXXFLAGS="${CFLAGS}" \
cmake \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_NEW_PYTHON_SUPPORT=OFF \
-D BUILD_SHARED_LIBS=OFF \
-D BUILD_TESTS=OFF \
-D OPENCV_BUILD_3RDPARTY_LIBS=OFF \
-D WITH_1394=OFF \
-D WITH_CARBON=OFF \
-D WITH_FFMPEG=OFF \
-D WITH_JASPER=OFF \
-D WITH_PVAPI=OFF \
-D WITH_QUICKTIME=OFF \
-D WITH_TBB=OFF \
-D WITH_TIFF=OFF \
-D CMAKE_C_FLAGS="${CFLAGS}" \
-D CMAKE_CXX_FLAGS="${CFLAGS}" \
-D CMAKE_OSX_SYSROOT="${SDK_ROOT}" \
-D CMAKE_OSX_ARCHITECTURES="${ARCH}" \
-D CMAKE_C_COMPILER="${DEVELOPER_ROOT}/usr/bin/gcc" \
-D CMAKE_CXX_COMPILER="${DEVELOPER_ROOT}/usr/bin/g++" \
-D CMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
${CMAKE_OPTIONS} \
"${OPENCV_ROOT}" \
&& echo "" \
&& echo "Done! next step is runing make (with -j option if you want to build using multi cores)."