merged iOS framework from the trunk
authorMarina Kolpakova <no@email>
Thu, 28 Jun 2012 15:13:57 +0000 (15:13 +0000)
committerMarina Kolpakova <no@email>
Thu, 28 Jun 2012 15:13:57 +0000 (15:13 +0000)
ios/Info.plist.in [new file with mode: 0644]
ios/build_framework.py [new file with mode: 0755]
modules/core/src/persistence.cpp
modules/world/CMakeLists.txt [new file with mode: 0644]
modules/world/include/opencv2/world/world.hpp [new file with mode: 0644]
modules/world/src/precomp.cpp [new file with mode: 0644]
modules/world/src/precomp.hpp [new file with mode: 0644]
modules/world/src/world_init.cpp [new file with mode: 0644]

diff --git a/ios/Info.plist.in b/ios/Info.plist.in
new file mode 100644 (file)
index 0000000..9b3d882
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+       <key>CFBundleName</key>
+       <string>OpenCV</string>
+       <key>CFBundleIdentifier</key>
+    <string>com.itseez.opencv</string>
+       <key>CFBundleVersion</key>
+       <string>${VERSION}</string>
+       <key>CFBundleShortVersionString</key>
+       <string>${VERSION}</string>
+       <key>CFBundleSignature</key>
+       <string>????</string>
+       <key>CFBundlePackageType</key>
+       <string>FMWK</string>
+</dict>
+</plist>
diff --git a/ios/build_framework.py b/ios/build_framework.py
new file mode 100755 (executable)
index 0000000..e5c8b16
--- /dev/null
@@ -0,0 +1,126 @@
+#!/usr/bin/env python
+"""
+The script builds OpenCV.framework for iOS.
+The built framework is universal, it can be used to build app and run it on either iOS simulator or real device.
+
+Usage:
+    ./build_framework.py <outputdir>
+    
+By cmake conventions (and especially if you work with OpenCV SVN repository),
+the output dir should not be a subdirectory of OpenCV source tree.
+    
+Script will create <outputdir>, if it's missing, and a few its subdirectories:
+    
+    <outputdir>
+        build/
+            iPhoneOS/
+               [cmake-generated build tree for an iOS device target]
+            iPhoneSimulator/
+               [cmake-generated build tree for iOS simulator]
+        OpenCV.framework/
+            [the framework content]
+
+The script should handle minor OpenCV updates efficiently
+- it does not recompile the library from scratch each time.
+However, OpenCV.framework directory is erased and recreated on each run.
+"""
+
+import glob, re, os, os.path, shutil, string, sys
+
+def build_opencv(srcroot, buildroot, target):
+    "builds OpenCV for device or simulator"
+    
+    builddir = os.path.join(buildroot, target)
+    if not os.path.isdir(builddir):
+        os.makedirs(builddir)
+    currdir = os.getcwd()
+    os.chdir(builddir)
+    # for some reason, if you do not specify CMAKE_BUILD_TYPE, it puts libs to "RELEASE" rather than "Release"
+    cmakeargs = ("-GXcode " +
+                "-DCMAKE_BUILD_TYPE=Release " +
+                "-DCMAKE_TOOLCHAIN_FILE=%s/ios/cmake/Toolchains/Toolchain-%s_Xcode.cmake " +
+                "-DBUILD_opencv_world=ON " +
+                "-DCMAKE_INSTALL_PREFIX=install") % (srcroot, target)
+    # if cmake cache exists, just rerun cmake to update OpenCV.xproj if necessary
+    if os.path.isfile(os.path.join(builddir, "CMakeCache.txt")):
+        os.system("cmake %s ." % (cmakeargs,))
+    else:
+        os.system("cmake %s %s" % (cmakeargs, srcroot))
+    
+    for wlib in [builddir + "/modules/world/UninstalledProducts/libopencv_world.a",
+                 builddir + "/lib/Release/libopencv_world.a"]:
+        if os.path.isfile(wlib):
+            os.remove(wlib)
+    
+    os.system("xcodebuild -parallelizeTargets -jobs 8 -sdk %s -configuration Release -target ALL_BUILD" % target.lower())
+    os.system("xcodebuild -sdk %s -configuration Release -target install install" % target.lower())
+    os.chdir(currdir)
+    
+def put_framework_together(srcroot, dstroot):
+    "constructs the framework directory after all the targets are built"
+    
+    # find the list of targets (basically, ["iPhoneOS", "iPhoneSimulator"])
+    targetlist = glob.glob(os.path.join(dstroot, "build", "*"))
+    targetlist = [os.path.basename(t) for t in targetlist]
+    
+    # set the current dir to the dst root
+    currdir = os.getcwd()
+    framework_dir = dstroot + "/opencv2.framework"
+    if os.path.isdir(framework_dir):
+        shutil.rmtree(framework_dir)
+    os.makedirs(framework_dir)
+    os.chdir(framework_dir)
+    
+    # determine OpenCV version (without subminor part)
+    tdir0 = "../build/" + targetlist[0]
+    cfg = open(tdir0 + "/cvconfig.h", "rt")
+    for l in cfg.readlines():
+        if l.startswith("#define  VERSION"):
+            opencv_version = l[l.find("\"")+1:l.rfind(".")]
+            break
+    cfg.close()
+    
+    # form the directory tree
+    dstdir = "Versions/A"
+    os.makedirs(dstdir + "/Resources")
+
+    # copy headers
+    shutil.copytree(tdir0 + "/install/include/opencv2", dstdir + "/Headers")
+    
+    # make universal static lib
+    wlist = " ".join(["../build/" + t + "/lib/Release/libopencv_world.a" for t in targetlist])
+    os.system("lipo -create " + wlist + " -o " + dstdir + "/opencv2")
+    
+    # form Info.plist
+    srcfile = open(srcroot + "/ios/Info.plist.in", "rt")
+    dstfile = open(dstdir + "/Resources/Info.plist", "wt")
+    for l in srcfile.readlines():
+        dstfile.write(l.replace("${VERSION}", opencv_version))
+    srcfile.close()
+    dstfile.close()
+    
+    # copy cascades
+    # TODO ...
+    
+    # make symbolic links
+    os.symlink(dstdir + "/Headers", "Headers")
+    os.symlink(dstdir + "/Resources", "Resources")
+    os.symlink(dstdir + "/opencv2", "opencv2")
+    os.symlink("A", "Versions/Current")
+        
+        
+def build_framework(srcroot, dstroot):
+    "main function to do all the work"
+    
+    for target in ["iPhoneOS", "iPhoneSimulator"]:
+        build_opencv(srcroot, os.path.join(dstroot, "build"), target)
+    
+    put_framework_together(srcroot, dstroot)
+    
+
+if __name__ == "__main__":
+    if len(sys.argv) != 2:
+        print "Usage:\n\t./build_framework.py <outputdir>\n\n"
+        sys.exit(0)
+    
+    build_framework(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "..")), os.path.abspath(sys.argv[1]))
index a038c9a..d27fc07 100644 (file)
 #include <deque>
 #include <iterator>
 #include <wchar.h>
+
+#define USE_ZLIB 1
+
+#ifdef __APPLE__
+#  include "TargetConditionals.h"
+#  if (defined TARGET_OS_IPHONE && TARGET_OS_IPHONE) || (defined TARGET_IPHONE_SIMULATOR && TARGET_IPHONE_SIMULATOR)
+#    undef USE_ZLIB
+#    define USE_ZLIB 0
+     typedef void* gzFile;
+#  endif
+#endif
+
+#if USE_ZLIB
 #include <zlib.h>
+#endif
 
 /****************************************************************************************\
 *                            Common macros and type definitions                          *
@@ -258,8 +272,10 @@ static void icvPuts( CvFileStorage* fs, const char* str )
         std::copy(str, str + strlen(str), std::back_inserter(*fs->outbuf));
     else if( fs->file )
         fputs( str, fs->file );
+#if USE_ZLIB
     else if( fs->gzfile )
         gzputs( fs->gzfile, str );
+#endif
     else
         CV_Error( CV_StsError, "The storage is not opened" );
 }
@@ -286,8 +302,10 @@ static char* icvGets( CvFileStorage* fs, char* str, int maxCount )
     }
     if( fs->file )
         return fgets( str, maxCount, fs->file );
+#if USE_ZLIB
     if( fs->gzfile )
         return gzgets( fs->gzfile, str, maxCount );
+#endif
     CV_Error( CV_StsError, "The storage is not opened" );
     return 0;
 }
@@ -298,8 +316,10 @@ static int icvEof( CvFileStorage* fs )
         return fs->strbufpos >= fs->strbufsize;
     if( fs->file )
         return feof(fs->file);
+#if USE_ZLIB
     if( fs->gzfile )
         return gzeof(fs->gzfile);
+#endif
     return false;
 }
 
@@ -307,8 +327,10 @@ static void icvCloseFile( CvFileStorage* fs )
 {
     if( fs->file )
         fclose( fs->file );
+#if USE_ZLIB
     else if( fs->gzfile )
         gzclose( fs->gzfile );
+#endif
     fs->file = 0;
     fs->gzfile = 0;
     fs->strbuf = 0;
@@ -320,8 +342,10 @@ static void icvRewind( CvFileStorage* fs )
 {
     if( fs->file )
         rewind(fs->file);
+#if USE_ZLIB
     else if( fs->gzfile )
         gzrewind(fs->gzfile);
+#endif
     fs->strbufpos = 0;
 }
 
@@ -2713,10 +2737,14 @@ cvOpenFileStorage( const char* filename, CvMemStorage* dststorage, int flags, co
         }
         else
         {
+            #if USE_ZLIB
             char mode[] = { fs->write_mode ? 'w' : 'r', 'b', compression ? compression : '3', '\0' };
             fs->gzfile = gzopen(fs->filename, mode);
             if( !fs->gzfile )
                 goto _exit_;
+            #else
+            CV_Error(CV_StsNotImplemented, "There is no compressed file storage support in this configuration");
+            #endif
         }
     }
     
diff --git a/modules/world/CMakeLists.txt b/modules/world/CMakeLists.txt
new file mode 100644 (file)
index 0000000..383b3cf
--- /dev/null
@@ -0,0 +1,102 @@
+if(NOT IOS)
+  ocv_module_disable(world)
+endif()
+
+set(the_description "All the selected OpenCV modules in a single binary")
+set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE)
+set(BUILD_opencv_world_INIT OFF)
+
+if(IOS OR NOT BUILD_SHARED_LIBS)
+  set(OPENCV_MODULE_TYPE STATIC)
+  set(OPENCV_WORLD_FLAGS_PROPERTY STATIC_LIBRARY_FLAGS)
+else()
+  set(OPENCV_WORLD_FLAGS_PROPERTY LINK_FLAGS)
+endif()
+
+ocv_add_module(world opencv_core)
+
+if(MSVC)
+  foreach(_var CMAKE_EXE_LINKER_FLAGS_RELEASE CMAKE_MODULE_LINKER_FLAGS_RELEASE CMAKE_SHARED_LINKER_FLAGS_RELEASE
+               CMAKE_EXE_LINKER_FLAGS_DEBUG   CMAKE_MODULE_LINKER_FLAGS_DEBUG   CMAKE_SHARED_LINKER_FLAGS_DEBUG)
+    string(REPLACE "/INCREMENTAL:NO" "/INCREMENTAL:YES" ${_var} "${${_var}}")
+  endforeach()
+endif()
+
+ocv_glob_module_sources()
+ocv_module_include_directories()
+ocv_create_module(SKIP_LINK)
+
+#TODO: try to use try_compile to find real object file extension/location
+if(CMAKE_GENERATOR MATCHES "^Visual.*$")
+  set(have_cfg 1)
+  set(objpath0 "<MODULE_NAME>.dir/<CONFIGURATION>/<SRC_NAME_WE>.obj")
+elseif (CMAKE_GENERATOR MATCHES Xcode)
+  set(have_cfg 1)
+  set(objpath0 "OpenCV.build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/<MODULE_NAME>.build/Objects-normal/$(CURRENT_ARCH)/<SRC_NAME_WE>.o")
+else()
+  set(have_cfg 0)
+  set(objpath0 "CMakeFiles/<MODULE_NAME>.dir/<RELATIVE_SRC_NAME>.o")
+  if(MINGW OR MSVC)
+    set(objpath0 "${objpath0}bj")
+  endif()
+endif()
+
+set(objlist "")
+foreach(m ${OPENCV_MODULE_${the_module}_DEPS})
+  # build order dependencies
+  add_dependencies(${the_module} ${m})
+  # link dependencies
+  string(REGEX REPLACE "(general|debug|optimized);opencv_[^;]*(;|$)" "" _link_deps "${${m}_LIB_DEPENDS}")
+  if(_link_deps)
+    target_link_libraries(${the_module} ${_link_deps})
+  endif()
+
+  string(REGEX REPLACE "<MODULE_NAME>" "${m}" objpath1 "${${m}_BINARY_DIR}/${objpath0}")
+  foreach(srcname ${OPENCV_MODULE_${m}_SOURCES})
+    if(srcname MATCHES "\\.(cpp|mm|c|cxx|cc|o|obj)$")
+      if(srcname MATCHES "\\.(o|obj)$")
+        if(IS_ABSOLUTE "${srcname}")
+          set(objpath3 "${srcname}")
+        else()
+          set(objpath3 "${${m}_SOURCE_DIR}/${srcname}")
+        endif()
+      else()
+        if(IS_ABSOLUTE "${srcname}")
+          if(srcname MATCHES "/(qrc|moc)_[^/]*\\.cxx$")
+            # QT generated sources
+            file(RELATIVE_PATH srcname "${${m}_BINARY_DIR}" "${srcname}")
+          else()
+            file(RELATIVE_PATH srcname "${OPENCV_MODULE_${m}_LOCATION}" "${srcname}")
+          endif()
+        endif()
+        string(REPLACE ".." "__" srcname "${srcname}")
+        get_filename_component(srcname_we ${srcname} NAME_WE)
+        string(REGEX REPLACE <SRC_NAME_WE> "${srcname_we}" objpath2 "${objpath1}")
+        string(REGEX REPLACE <RELATIVE_SRC_NAME> "${srcname}" objpath3 "${objpath2}")
+      endif()
+      if(CMAKE_GENERATOR MATCHES Makefiles)
+        file(RELATIVE_PATH objpath4 "${CMAKE_CURRENT_BINARY_DIR}" "${objpath3}")
+      else()
+        set(objpath4 ${objpath3})
+      endif()
+      list(APPEND objlist "\"${objpath4}\"")
+    endif()
+  endforeach()
+endforeach()
+
+string(REPLACE ";" " " objlist "${objlist}")
+
+if(have_cfg)
+  string(REGEX REPLACE "<CONFIGURATION>" "Debug" objlist_dbg "${objlist}")
+  string(REGEX REPLACE "<CONFIGURATION>" "Release" objlist_rls "${objlist}")
+  set_target_properties(${the_module} PROPERTIES
+    ${OPENCV_WORLD_FLAGS_PROPERTY}_DEBUG ${objlist_dbg}
+    ${OPENCV_WORLD_FLAGS_PROPERTY}_RELEASE ${objlist_rls})
+else()
+  file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/world_objects.list" "${objlist}")
+  execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/world_objects.list" "${CMAKE_CURRENT_BINARY_DIR}/world_objects.rsp" OUTPUT_QUIET)
+  set_target_properties(${the_module} PROPERTIES
+    ${OPENCV_WORLD_FLAGS_PROPERTY} "@${CMAKE_CURRENT_BINARY_DIR}/world_objects.rsp")
+endif()
+
+ocv_add_precompiled_headers(${the_module})
diff --git a/modules/world/include/opencv2/world/world.hpp b/modules/world/include/opencv2/world/world.hpp
new file mode 100644 (file)
index 0000000..b4bff33
--- /dev/null
@@ -0,0 +1,58 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
+//                           License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
+// Copyright (C) 2009-2010, Willow Garage Inc., all rights reserved.
+// Third party copyrights are property of their respective owners.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+//   * Redistribution's of source code must retain the above copyright notice,
+//     this list of conditions and the following disclaimer.
+//
+//   * Redistribution's in binary form must reproduce the above copyright notice,
+//     this list of conditions and the following disclaimer in the documentation
+//     and/or other materials provided with the distribution.
+//
+//   * The name of the copyright holders may not be used to endorse or promote products
+//     derived from this software without specific prior written permission.
+//
+// This software is provided by the copyright holders and contributors "as is" and
+// any express or implied warranties, including, but not limited to, the implied
+// warranties of merchantability and fitness for a particular purpose are disclaimed.
+// In no event shall the Intel Corporation or contributors be liable for any direct,
+// indirect, incidental, special, exemplary, or consequential damages
+// (including, but not limited to, procurement of substitute goods or services;
+// loss of use, data, or profits; or business interruption) however caused
+// and on any theory of liability, whether in contract, strict liability,
+// or tort (including negligence or otherwise) arising in any way out of
+// the use of this software, even if advised of the possibility of such damage.
+//
+//M*/
+
+#ifndef __OPENCV_WORLD_HPP__
+#define __OPENCV_WORLD_HPP__
+
+#include "opencv2/core/core.hpp"
+
+#ifdef __cplusplus
+namespace cv
+{
+
+CV_EXPORTS_W bool initAll();
+
+}
+
+#endif
+
+#endif
diff --git a/modules/world/src/precomp.cpp b/modules/world/src/precomp.cpp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/modules/world/src/precomp.hpp b/modules/world/src/precomp.hpp
new file mode 100644 (file)
index 0000000..667d2ff
--- /dev/null
@@ -0,0 +1,66 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
+// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
+// Third party copyrights are property of their respective owners.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+//   * Redistribution's of source code must retain the above copyright notice,
+//     this list of conditions and the following disclaimer.
+//
+//   * Redistribution's in binary form must reproduce the above copyright notice,
+//     this list of conditions and the following disclaimer in the documentation
+//     and/or other materials provided with the distribution.
+//
+//   * The name of the copyright holders may not be used to endorse or promote products
+//     derived from this software without specific prior written permission.
+//
+// This software is provided by the copyright holders and contributors "as is" and
+// any express or implied warranties, including, but not limited to, the implied
+// warranties of merchantability and fitness for a particular purpose are disclaimed.
+// In no event shall the Intel Corporation or contributors be liable for any direct,
+// indirect, incidental, special, exemplary, or consequential damages
+// (including, but not limited to, procurement of substitute goods or services;
+// loss of use, data, or profits; or business interruption) however caused
+// and on any theory of liability, whether in contract, strict liability,
+// or tort (including negligence or otherwise) arising in any way out of
+// the use of this software, even if advised of the possibility of such damage.
+//
+//M*/
+
+#ifndef __OPENCV_PRECOMP_H__
+#define __OPENCV_PRECOMP_H__
+
+#ifdef HAVE_CVCONFIG_H 
+#include "cvconfig.h"
+#endif
+
+#include "opencv2/opencv_modules.hpp"
+#ifdef HAVE_OPENCV_VIDEO
+#include "opencv2/video/video.hpp"
+#endif
+#ifdef HAVE_OPENCV_FEATURES2D
+#include "opencv2/features2d/features2d.hpp"
+#endif
+#ifdef HAVE_OPENCV_NONFREE
+#include "opencv2/nonfree/nonfree.hpp"
+#endif
+#ifdef HAVE_OPENCV_ML
+#include "opencv2/ml/ml.hpp"
+#endif
+
+#include "opencv2/world/world.hpp"
+
+#endif
diff --git a/modules/world/src/world_init.cpp b/modules/world/src/world_init.cpp
new file mode 100644 (file)
index 0000000..3fd13f3
--- /dev/null
@@ -0,0 +1,61 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
+//                          License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
+// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
+// Third party copyrights are property of their respective owners.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+//   * Redistribution's of source code must retain the above copyright notice,
+//     this list of conditions and the following disclaimer.
+//
+//   * Redistribution's in binary form must reproduce the above copyright notice,
+//     this list of conditions and the following disclaimer in the documentation
+//     and/or other materials provided with the distribution.
+//
+//   * The name of the copyright holders may not be used to endorse or promote products
+//     derived from this software without specific prior written permission.
+//
+// This software is provided by the copyright holders and contributors "as is" and
+// any express or implied warranties, including, but not limited to, the implied
+// warranties of merchantability and fitness for a particular purpose are disclaimed.
+// In no event shall the Intel Corporation or contributors be liable for any direct,
+// indirect, incidental, special, exemplary, or consequential damages
+// (including, but not limited to, procurement of substitute goods or services;
+// loss of use, data, or profits; or business interruption) however caused
+// and on any theory of liability, whether in contract, strict liability,
+// or tort (including negligence or otherwise) arising in any way out of
+// the use of this software, even if advised of the possibility of such damage.
+//
+//M*/
+
+#include "precomp.hpp"
+
+bool cv::initAll()
+{
+    return true
+#ifdef HAVE_OPENCV_VIDEO
+    && initModule_video()
+#endif
+#ifdef HAVE_OPENCV_FEATURES2D
+    && initModule_features2d()
+#endif
+#ifdef HAVE_OPENCV_NONFREE
+    && initModule_nonfree()
+#endif
+#ifdef HAVE_OPENCV_ML
+    && initModule_ml()
+#endif
+    ;
+}