├── BuildOpenCV.sh └── README /BuildOpenCV.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################################################ 3 | # This script will create universal binaries for OpenCV library for 4 | # iOS-based devices (iPhone, iPad, iPod, etc). 5 | # As output you obtain debug/release static libraries and include headers. 6 | # 7 | # This script was written by Eugene Khvedchenya 8 | # And distributed under GPL license 9 | # Support site: http://computer-vision-talks.com 10 | ################################################################################ 11 | 12 | if [ $# -ne 2 ] 13 | then 14 | echo "Error in $0 - Invalid Argument Count" 15 | echo "Syntax: $0 [OpenCV source directory] [Build destination directory]" 16 | echo "If the destination directory already exists, it will be overwritten!" 17 | exit 18 | fi 19 | 20 | # Absolute path to the source code directory. 21 | D=`dirname "$1"` 22 | B=`basename "$1"` 23 | SRC="`cd \"$D\" 2>/dev/null && pwd || echo \"$D\"`/$B" 24 | 25 | # Absolute path to the build directory. 26 | D=`dirname "$2"` 27 | B=`basename "$2"` 28 | BUILD="`cd \"$D\" 2>/dev/null && pwd || echo \"$D\"`/$B" 29 | 30 | INTERMEDIATE=$BUILD/tmp 31 | IOS_DEV_BUILD_DIR=$INTERMEDIATE/ios-dev-build 32 | IOS_SIM_BUILD_DIR=$INTERMEDIATE/ios-sim-build 33 | 34 | ################################################################################ 35 | # Clear the old build and recompile the new one. 36 | echo $SRC 37 | echo $BUILD 38 | echo "WARNING: The bulid directory will be removed and re-created again." 39 | echo "WARNING: It's your last chance to check is it correct and you do not have anything valuable in it." 40 | read -p "Press any key to continue..." 41 | 42 | #rm -rf $BUILD 43 | 44 | ################################################################################ 45 | # Build release and debug configurations for iOS device 46 | mkdir -p $IOS_DEV_BUILD_DIR 47 | pushd $IOS_DEV_BUILD_DIR 48 | cmake -GXcode -DCMAKE_TOOLCHAIN_FILE=$SRC/ios/cmake/Toolchains/Toolchain-iPhoneOS_Xcode.cmake \ 49 | -DCMAKE_INSTALL_PREFIX=$INTERMEDIATE/install \ 50 | -DOPENCV_BUILD_3RDPARTY_LIBS=YES \ 51 | -DBUILD_EXAMPLES=NO \ 52 | -DBUILD_TESTS=NO \ 53 | -DBUILD_NEW_PYTHON_SUPPORT=NO \ 54 | -DBUILD_PERF_TESTS=NO \ 55 | -DBUILD_PERF_TESTS=NO \ 56 | -DCMAKE_C_FLAGS_RELEASE="-O3 -ffast-math" \ 57 | -DCMAKE_CXX_FLAGS_RELEASE="-O3 -ffast-math" \ 58 | -DCMAKE_XCODE_ATTRIBUTE_GCC_VERSION="com.apple.compilers.llvmgcc42" $SRC 59 | 60 | xcodebuild -sdk iphoneos -configuration Release -target ALL_BUILD 61 | xcodebuild -sdk iphoneos -configuration Release -target install install 62 | xcodebuild -sdk iphoneos -configuration Debug -target ALL_BUILD 63 | popd 64 | 65 | ################################################################################ 66 | # Build release and debug configurations for iOS simulator 67 | mkdir -p $IOS_SIM_BUILD_DIR 68 | pushd $IOS_SIM_BUILD_DIR 69 | cmake -GXcode -DCMAKE_TOOLCHAIN_FILE=$SRC/ios/cmake/Toolchains/Toolchain-iPhoneSimulator_Xcode.cmake \ 70 | -DCMAKE_INSTALL_PREFIX=$INTERMEDIATE/install \ 71 | -DOPENCV_BUILD_3RDPARTY_LIBS=YES \ 72 | -DBUILD_EXAMPLES=NO \ 73 | -DBUILD_TESTS=NO \ 74 | -DBUILD_NEW_PYTHON_SUPPORT=NO \ 75 | -DBUILD_PERF_TESTS=NO \ 76 | -DCMAKE_XCODE_ATTRIBUTE_GCC_VERSION="com.apple.compilers.llvmgcc42" $SRC 77 | xcodebuild -sdk iphonesimulator -configuration Release -target ALL_BUILD 78 | xcodebuild -sdk iphonesimulator -configuration Debug -target ALL_BUILD 79 | popd 80 | 81 | ################################################################################ 82 | # Copy third party libs to opencv libs lib dir: 83 | cp -f $IOS_DEV_BUILD_DIR/3rdparty/lib/Debug/*.a $IOS_DEV_BUILD_DIR/lib/Debug/ 84 | cp -f $IOS_DEV_BUILD_DIR/3rdparty/lib/Release/*.a $IOS_DEV_BUILD_DIR/lib/Release/ 85 | 86 | cp -f $IOS_SIM_BUILD_DIR/3rdparty/lib/Debug/*.a $IOS_SIM_BUILD_DIR/lib/Debug/ 87 | cp -f $IOS_SIM_BUILD_DIR/3rdparty/lib/Release/*.a $IOS_SIM_BUILD_DIR/lib/Release/ 88 | 89 | ################################################################################ 90 | # Make universal binaries for release configuration: 91 | mkdir -p $BUILD/lib/Release/ 92 | 93 | for FILE in `ls $IOS_DEV_BUILD_DIR/lib/Release` 94 | do 95 | lipo $IOS_DEV_BUILD_DIR/lib/Release/$FILE \ 96 | $IOS_SIM_BUILD_DIR/lib/Release/$FILE \ 97 | -create -output $BUILD/lib/Release/$FILE 98 | done 99 | 100 | ################################################################################ 101 | # Make universal binaries for debug configuration: 102 | mkdir -p $BUILD/lib/Debug/ 103 | 104 | for FILE in `ls $IOS_DEV_BUILD_DIR/lib/Debug` 105 | do 106 | lipo $IOS_DEV_BUILD_DIR/lib/Debug/$FILE \ 107 | $IOS_SIM_BUILD_DIR/lib/Debug/$FILE \ 108 | -create -output $BUILD/lib/Debug/$FILE 109 | done 110 | 111 | ################################################################################ 112 | # Copy headers: 113 | rm -rf $BUILD/include 114 | mv $INTERMEDIATE/install/include $BUILD/include 115 | 116 | ################################################################################ 117 | # Final cleanup 118 | #rm -rf $INTERMEDIATE 119 | echo "All is done" -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This script will create universal binaries for OpenCV library for 3 | # iOS-based devices (iPhone, iPad, iPod, etc). 4 | # As output you obtain debug/release static libraries and include headers. 5 | # 6 | # This script was written by Eugene Khvedchenya 7 | # And distributed under GPL license 8 | # Support site: http://computer-vision-talks.com 9 | ################################################################################ 10 | 11 | Changelog: 12 | 13 | Version 1.5 14 | + Added Xcode 4.2.x and iOS 5 SDK support 15 | + Native experimental OpenCV build system is used 16 | 17 | Version 1.4 18 | + Updated build script to support OpenCV 2.2.9 19 | 20 | Version 1.3 21 | + Fixed bug with creation of universal binaries if opencv source path was not ends with 'opencv' 22 | 23 | Version 1.2 24 | + Added Armv6 architecture support 25 | 26 | Version 1.1 - Added support for XCode 4 27 | + Fixed problem when building for XCode 4 - resolved by patching copy of OpenCV sources 28 | 29 | Version 1.0 - Initial commit 30 | + Supported OpenCV up to 4771 revision, XCode 3 and iOS SDK 4.2.1 31 | --------------------------------------------------------------------------------