--- CMakeLists.txt	2013-07-10 20:49:00.000000000 +0900
+++ CMakeLists.txt	2013-08-15 09:06:48.000000000 +0900
@@ -501,6 +501,24 @@
 # Generate OpenCVСonfig.cmake and OpenCVConfig-version.cmake for cmake projects
 include(cmake/OpenCVGenConfig.cmake)
 
+# ----------------------------------------------------------------------------
+# Mac OS X Framework Support: 
+# ----------------------------------------------------------------------------
+if (APPLE)
+  set (BUILD_OSX_FRAMEWORK ON CACHE BOOL "Build Mac OS X Framework")
+  if (BUILD_OSX_FRAMEWORK)
+    # Mac OS X Framework properties
+    set (OSX_FRAMEWORK_NAME opencv2 CACHE STRING "Name of the Mac OS X Framework - Warning support for a different framework name has only been tested in 2.4.6.1")
+    set (OSX_FRAMEWORK_TARGET_NAME OpenCV_OSXFramework CACHE STRING "Name of the Mac OS X Framework Xcode Project")
+    set (OSX_FRAMEWORK_VERSION ${OPENCV_VERSION})
+    set (OSX_FRAMEWORK_CPP_FILE "osx-framework/OpenCVOSXFramework.cpp")
+    set (OSX_FRAMEWORK_CREATE_DSYM ON CACHE BOOL "Build Mac OS X Framework with DWARF dSYM Debug Information in Release")
+    set (OSX_FRAMEWORK_LINKER_PATH_ABSOLUTE OFF CACHE BOOL "Set OS X Framework Linker Path to /Library/Frameworks (as opposed to @executable_path/../Frameworks)")
+    set (OSX_FRAMEWORK_LINKER_PATH_CUSTOM "" CACHE PATH "Set OS X Framework Linker Path to a Custom Path (overrides OSX_FRAMEWORK_LINKER_PATH_ABSOLUTE)")
+    # Create Mac OS X Framework
+    include(osx-framework/OpenCVOSXFramework.cmake REQUIRED)
+  endif (BUILD_OSX_FRAMEWORK)
+endif (APPLE)
 
 # ----------------------------------------------------------------------------
 # Summary:
--- osx-framework/OpenCVOSXFramework.cmake	1970-01-01 09:00:00.000000000 +0900
+++ osx-framework/OpenCVOSXFramework.cmake	2013-08-15 09:16:24.000000000 +0900
@@ -0,0 +1,68 @@
+include(osx-framework/OpenCVOSXFrameworkFunctions.cmake REQUIRED)
+
+# Set the framework's path to itself (first line of `otool -L ${OSX_FRAMEWORK_NAME}`)
+if (OSX_FRAMEWORK_LINKER_PATH_CUSTOM)
+  get_filename_component (OSX_FRAMEWORK_LINKER_PATH_CUSTOM_PATH ${OSX_FRAMEWORK_LINKER_PATH_CUSTOM} PATH)
+  get_filename_component (OSX_FRAMEWORK_LINKER_PATH_CUSTOM_NAME ${OSX_FRAMEWORK_LINKER_PATH_CUSTOM} NAME)
+  set (OSX_FRAMEWORK_LINKER_PATH "${OSX_FRAMEWORK_LINKER_PATH_CUSTOM_PATH}/${OSX_FRAMEWORK_LINKER_PATH_CUSTOM_NAME}")
+else (OSX_FRAMEWORK_LINKER_PATH_CUSTOM)
+  if (OSX_FRAMEWORK_LINKER_PATH_ABSOLUTE)
+    set (OSX_FRAMEWORK_LINKER_PATH "/Library/Frameworks/")
+  else (OSX_FRAMEWORK_LINKER_PATH_ABSOLUTE)
+    set (OSX_FRAMEWORK_LINKER_PATH "@executable_path/../Frameworks")
+  endif (OSX_FRAMEWORK_LINKER_PATH_ABSOLUTE)
+endif (OSX_FRAMEWORK_LINKER_PATH_CUSTOM)
+
+# General Framework Setup
+add_framework (${OSX_FRAMEWORK_TARGET_NAME} ${OSX_FRAMEWORK_NAME} ${OSX_FRAMEWORK_CPP_FILE} ${OSX_FRAMEWORK_VERSION} ${OSX_FRAMEWORK_LINKER_PATH})
+set_xcode_debug_info (${OSX_FRAMEWORK_TARGET_NAME})
+include_directories (${OSX_FRAMEWORK_TARGET_NAME} "include")
+
+# Include all OpenCV library modules
+foreach (OPENCV_MODULE_FULL_NAME ${OPENCV_MODULES_BUILD})
+  string (REGEX REPLACE "^opencv_" "" OPENCV_MODULE_SHORT_NAME "${OPENCV_MODULE_FULL_NAME}")
+  # The dependencies are only used for install_name_tool
+  ## Therefore having too many can never be a problem but missing one can
+  ## So we'll just use all the modules currently being built
+  ## This is necessary since in some cases (calib3d, gpu, nonfree, stitching)
+  ## the linker flags contain a dependency to opencv_highgui when
+  ## ${OPENCV_MODULE_${OPENCV_MODULE_FULL_NAME}_DEPS} doesn't
+  set (OPENCV_MODULE_DEPS ${OPENCV_MODULES_BUILD})
+  get_target_property (OPENCV_MODULE_VERSION "${OPENCV_MODULE_FULL_NAME}" VERSION)
+  get_target_property (OPENCV_MODULE_SOVERSION "${OPENCV_MODULE_FULL_NAME}" SOVERSION)
+  # This seperates sublibraries from independent ones such as the python module
+  if (OPENCV_MODULE_VERSION AND OPENCV_MODULE_SOVERSION)
+    add_framework_sublibrary (${OSX_FRAMEWORK_TARGET_NAME} "${OPENCV_MODULE_FULL_NAME}" "${OPENCV_MODULE_DEPS}")
+    set (OPENCV_MODULE_INCLUDE_DIR "${OPENCV_MODULE_${OPENCV_MODULE_FULL_NAME}_LOCATION}/include")
+    if (EXISTS ${OPENCV_MODULE_INCLUDE_DIR})
+      include_directories (${OSX_FRAMEWORK_TARGET_NAME} "${OPENCV_MODULE_INCLUDE_DIR}")
+      set (OPENCV_MODULE_INCLUDE_NAME_DIR "${OPENCV_MODULE_INCLUDE_DIR}/opencv2/${OPENCV_MODULE_SHORT_NAME}")
+      if (EXISTS ${OPENCV_MODULE_INCLUDE_NAME_DIR})
+        add_framework_header (${OSX_FRAMEWORK_TARGET_NAME} "${OPENCV_MODULE_INCLUDE_NAME_DIR}")
+      endif (EXISTS ${OPENCV_MODULE_INCLUDE_NAME_DIR})
+    else (EXISTS ${OPENCV_MODULE_INCLUDE_DIR})
+      MESSAGE(STATUS "${OPENCV_MODULE_FULL_NAME} DOES NOT HAVE THIS DIRECTORY: ${OPENCV_MODULE_INCLUDE_DIR}")
+    endif (EXISTS ${OPENCV_MODULE_INCLUDE_DIR})
+  else (OPENCV_MODULE_VERSION AND OPENCV_MODULE_SOVERSION)
+    add_framework_independent_library(${OSX_FRAMEWORK_TARGET_NAME} "${OPENCV_MODULE_FULL_NAME}" "${OPENCV_MODULE_DEPS}" "${OSX_FRAMEWORK_LINKER_PATH}")
+  endif (OPENCV_MODULE_VERSION AND OPENCV_MODULE_SOVERSION)
+  set_xcode_debug_info ("${OPENCV_MODULE_FULL_NAME}")
+endforeach (OPENCV_MODULE_FULL_NAME ${OPENCV_MODULES_BUILD})
+
+# Copy all global OpenCV headers to framework
+file (GLOB OPENCV_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/opencv2/*.hpp")
+foreach (header_file ${OPENCV_HEADERS})
+  add_framework_header (${OSX_FRAMEWORK_TARGET_NAME} ${header_file})
+endforeach (header_file ${OPENCV_HEADERS})
+
+# Rewrite path to other header files in framework header files only if framework name has changed
+if (NOT ("${OSX_FRAMEWORK_NAME}" STREQUAL "opencv2"))
+  get_target_property (OPENCV_HEADERS_LOCATION ${OSX_FRAMEWORK_TARGET_NAME} CONTENTS_OF_Headers_DIRECTORY)
+  foreach (header_file ${OPENCV_HEADERS_LOCATION})
+    add_custom_command (TARGET ${OSX_FRAMEWORK_TARGET_NAME}
+                               POST_BUILD
+                               COMMAND find
+                               ARGS ${header_file} -iregex "'.*hp*'" -exec sed -i "''" -e "'s|#include[ \\t]*\"opencv2/\\([^\"]*\\)\"|#include \"${OSX_FRAMEWORK_NAME}/\\1\"|'" {} +)
+  endforeach (header_file ${OPENCV_HEADERS_LOCATION})
+endif (NOT ("${OSX_FRAMEWORK_NAME}" STREQUAL "opencv2"))
+
--- osx-framework/OpenCVOSXFramework.cpp	1970-01-01 09:00:00.000000000 +0900
+++ osx-framework/OpenCVOSXFramework.cpp	2013-08-15 09:12:35.000000000 +0900
@@ -0,0 +1,3 @@
+#include <opencv2/opencv.hpp>
+
+const char* OpenCVFrameworkVersion = CV_VERSION;
--- osx-framework/OpenCVOSXFrameworkFunctions.cmake	1970-01-01 09:00:00.000000000 +0900
+++ osx-framework/OpenCVOSXFrameworkFunctions.cmake	2013-08-15 09:24:36.000000000 +0900
@@ -0,0 +1,290 @@
+function (add_framework_bundle_directory TARGET NAME)
+  get_target_property (HAS_DIR ${TARGET} HAS_${NAME}_DIRECTORY)
+  if (NOT HAS_DIR)
+    # Get full path to bundle directory
+    set_target_properties (${TARGET} PROPERTIES HAS_${NAME}_DIRECTORY TRUE)
+    get_target_property (FRAMEWORK_LOCATION ${TARGET} LOCATION)
+    get_filename_component (FRAMEWORK_DIR "${FRAMEWORK_LOCATION}" PATH)
+    set (TARGET_DIR "${FRAMEWORK_DIR}/${NAME}")
+    get_filename_component (LINK_TARGET_PARENT_DIR "${FRAMEWORK_DIR}/../../" ABSOLUTE)
+    set_target_properties ( ${TARGET} PROPERTIES ${NAME}_DIRECTORY "${TARGET_DIR}" )
+    # Create Directory in Version/**/
+    add_custom_command (TARGET ${TARGET}
+      POST_BUILD
+      COMMAND ${CMAKE_COMMAND}
+      ARGS -E make_directory ${TARGET_DIR} )
+    # Create symlink in outer directory to it
+    add_custom_command (TARGET ${TARGET}
+      POST_BUILD
+      WORKING_DIRECTORY "${LINK_TARGET_PARENT_DIR}"
+      COMMAND ${CMAKE_COMMAND}
+      ARGS -E create_symlink "Versions/Current/${NAME}" "${NAME}" )
+  endif (NOT HAS_DIR)
+endfunction (add_framework_bundle_directory)
+
+function (add_file_to_framework_subdir TARGET DIR FILE_PATH)
+  # Create DIR directory if not created yet
+  add_framework_bundle_directory (${TARGET} "${DIR}")
+
+  # get location of the new location for the copied file in the headers directory
+  get_target_property (FRAMEWORK_LOCATION ${TARGET} LOCATION)
+  get_filename_component (FRAMEWORK_DIR "${FRAMEWORK_LOCATION}" PATH)
+  get_filename_component (FILE_NAME ${FILE_PATH} NAME)
+  get_filename_component (COPY_FILE_PATH "${FRAMEWORK_DIR}/${DIR}/${FILE_NAME}" ABSOLUTE)
+
+  get_target_property (HAS_FILE_IN_DIR ${TARGET} HAS_${FILE_NAME}_IN_${DIR}_DIRECTORY)
+
+  if (NOT HAS_FILE_IN_DIR)
+    set_target_properties (${TARGET} PROPERTIES HAS_${FILE_NAME}_IN_${DIR}_DIRECTORY TRUE)
+    set (FILES_TO_ADD "${COPY_FILE_PATH}")
+
+    # setup file copy
+    add_custom_command (TARGET ${TARGET}
+      POST_BUILD
+      COMMAND cp
+      ARGS -R ${FILE_PATH} ${COPY_FILE_PATH} )
+
+    get_target_property (CONTENTS_OF_DIR ${TARGET} CONTENTS_OF_${DIR}_DIRECTORY)
+    if (CONTENTS_OF_DIR)
+      set_target_properties (${TARGET} PROPERTIES CONTENTS_OF_${DIR}_DIRECTORY "${CONTENTS_OF_DIR};${FILES_TO_ADD}")
+    else (CONTENTS_OF_DIR)
+      set_target_properties (${TARGET} PROPERTIES CONTENTS_OF_${DIR}_DIRECTORY "${FILES_TO_ADD}")
+    endif (CONTENTS_OF_DIR)
+  endif (NOT HAS_FILE_IN_DIR)
+
+endfunction (add_file_to_framework_subdir)
+
+function (add_framework_header TARGET HEADER)
+  add_file_to_framework_subdir(${TARGET} "Headers" ${HEADER})
+endfunction (add_framework_header)
+
+function (add_framework_privateheader TARGET HEADER)
+  add_file_to_framework_subdir(${TARGET} "PrivateHeaders" ${HEADER})
+endfunction (add_framework_privateheader)
+
+function (add_framework_resource TARGET FILE_PATH)
+  add_file_to_framework_subdir(${TARGET} "Resources" ${FILE_PATH})
+endfunction (add_framework_resource)
+
+function (add_framework_sublibrary TARGET LIB DEPENDENCIES)
+  # Check if we are also building $LIB. Otherwise if it isnt a
+  # system library (i.e. not in /usr/lib) copy it and all
+  # dependencies 
+  if (TARGET ${LIB})
+    # Create the framework Bundles directory if it has not been created yet
+    add_framework_bundle_directory(${TARGET} "Libraries")
+    
+    # Add As Dependency
+    add_dependencies(${TARGET} ${LIB})
+
+    # Get location of library after it is built
+    get_target_property (LIBRARY_LOCATION ${LIB} LOCATION)
+    get_filename_component (LIBRARY_LOCATION_DIR "${LIBRARY_LOCATION}" PATH)
+
+    # Get location of the framework's bundle directory ``Libraries''
+    # and append the name of the library to said path in order to
+    # get the full copy path for the library
+    get_target_property (FRAMEWORK ${TARGET} LOCATION)
+    get_filename_component (FRAMEWORK_DIR "${FRAMEWORK}" PATH)
+    get_filename_component (LIBRARY_COPY_PATH "${FRAMEWORK_DIR}/Libraries/lib${LIB}.dylib" ABSOLUTE)
+
+    # We want all the symbols in the library to be reexported since we are using
+    # a sublibrary
+    target_link_libraries (${TARGET} "-Wl,-reexport_library ${LIBRARY_LOCATION}")
+
+    # Add copy command for library during post processing
+    add_custom_command(TARGET ${TARGET}
+      POST_BUILD
+      COMMAND ${CMAKE_COMMAND}
+      ARGS -E copy ${LIBRARY_LOCATION} ${LIBRARY_COPY_PATH})
+
+    # Setup correct id of copied library
+    add_custom_command(TARGET ${TARGET}
+      POST_BUILD
+      COMMAND install_name_tool
+      ARGS -id "@loader_path/Libraries/lib${LIB}.dylib" "${LIBRARY_COPY_PATH}")
+
+    # Add install name tool command to update the framework's path to library during post processing
+    ## Different build tools will link the framework with one of the following paths:
+    ## lib${LIB}.dylib
+    ## lib${LIB}.${LIBRARY_SO_VERSION}.dylib
+    ## lib${LIB}.${LIBRARY_VERSION}.dylib
+    ## So we install name tool for all of them. If one of them was not linked, it will just be ignored
+    get_filename_component (LIBRARY_LINK_PATH_VANILLA "${LIBRARY_LOCATION_DIR}/lib${LIB}.dylib" ABSOLUTE)
+    add_custom_command(TARGET ${TARGET}
+      POST_BUILD
+      COMMAND install_name_tool
+      ARGS -change ${LIBRARY_LINK_PATH_VANILLA} "@loader_path/Libraries/lib${LIB}.dylib" ${FRAMEWORK})
+
+    get_target_property (LIBRARY_SO_VERSION ${LIB} SOVERSION)
+    if (LIBRARY_SO_VERSION)
+      get_filename_component (LIBRARY_LINK_PATH_SO_VERSION "${LIBRARY_LOCATION_DIR}/lib${LIB}.${LIBRARY_SO_VERSION}.dylib" ABSOLUTE)
+      add_custom_command(TARGET ${TARGET}
+        POST_BUILD
+        COMMAND install_name_tool
+        ARGS -change ${LIBRARY_LINK_PATH_SO_VERSION} "@loader_path/Libraries/lib${LIB}.dylib" ${FRAMEWORK})
+    endif (LIBRARY_SO_VERSION)
+
+    get_target_property (LIBRARY_VERSION ${LIB} VERSION)
+    if (LIBRARY_VERSION)
+      get_filename_component (LIBRARY_LINK_PATH_VERSION "${LIBRARY_LOCATION_DIR}/lib${LIB}.${LIBRARY_VERSION}.dylib" ABSOLUTE)
+      add_custom_command(TARGET ${TARGET}
+        POST_BUILD
+        COMMAND install_name_tool
+        ARGS -change ${LIBRARY_LINK_PATH_VERSION} "@loader_path/Libraries/lib${LIB}.dylib" ${FRAMEWORK})
+    endif (LIBRARY_VERSION)
+
+    # Setup install name tool command to update loader path for all dependent libraries
+    foreach (DEP ${DEPENDENCIES})
+      add_custom_command(TARGET ${TARGET}
+        POST_BUILD
+        COMMAND install_name_tool
+        ARGS -change "${LIBRARY_LOCATION_DIR}/lib${DEP}.dylib"  "@loader_path/lib${DEP}.dylib" ${LIBRARY_COPY_PATH})
+      get_target_property (DEP_SO_VERSION ${DEP} SOVERSION)
+      if (DEP_SO_VERSION)
+        add_custom_command(TARGET ${TARGET}
+          POST_BUILD
+          COMMAND install_name_tool
+          ARGS -change "${LIBRARY_LOCATION_DIR}/lib${DEP}.${DEP_SO_VERSION}.dylib"  "@loader_path/lib${DEP}.dylib" ${LIBRARY_COPY_PATH})
+      endif (DEP_SO_VERSION)
+      get_target_property (DEP_VERSION ${DEP} VERSION)
+      if (DEP_VERSION)
+        add_custom_command(TARGET ${TARGET}
+          POST_BUILD
+          COMMAND install_name_tool
+          ARGS -change "${LIBRARY_LOCATION_DIR}/lib${DEP}.${DEP_VERSION}.dylib"  "@loader_path/lib${DEP}.dylib" ${LIBRARY_COPY_PATH})
+      endif (DEP_VERSION)
+    endforeach (DEP ${DEPENDENCIES})
+
+    # copy library dSYMs into framework dSYM if they exist
+    if (OSX_FRAMEWORK_CREATE_DSYM)
+      get_filename_component (FRAMEWORK_NAME "${FRAMEWORK}" NAME)
+      add_custom_command (TARGET ${TARGET}
+        POST_BUILD
+        COMMAND if [ -a "${LIBRARY_LOCATION}.dSYM" ] \; then cp "${LIBRARY_LOCATION}.dSYM/Contents/Resources/DWARF/*" "${LIBRARY_LOCATION_DIR}/${FRAMEWORK_NAME}.framework.dSYM/Contents/Resources/DWARF" \; fi )
+    endif (OSX_FRAMEWORK_CREATE_DSYM)
+
+    # strip dylib if we are in Release mode
+    add_custom_command (TARGET ${TARGET}
+      POST_BUILD
+      COMMAND if [ $<CONFIGURATION> == Release ] \; then strip -u ${LIBRARY_COPY_PATH} \; fi )
+
+  endif (TARGET ${LIB})
+endfunction (add_framework_sublibrary)
+
+function (add_framework_independent_library TARGET LIB DEPENDENCIES INSTALL_NAME_TOOL_DIR)
+  # Check if we are also building $LIB.
+  if (TARGET ${LIB})
+    # Create the framework Bundles directory if it has not been created yet
+    add_framework_bundle_directory(${TARGET} "Libraries")
+
+    # Add As Dependency
+    add_dependencies(${TARGET} ${LIB})
+
+    # Get location of library after it is built
+    get_target_property (LIBRARY_LOCATION ${LIB} LOCATION)
+    get_filename_component (LIBRARY_LOCATION_DIR "${LIBRARY_LOCATION}" PATH)
+
+    # Get location of the framework's directory
+    # to get the full copy path for the library
+    get_target_property (FRAMEWORK ${TARGET} LOCATION)
+    get_filename_component (FRAMEWORK_DIR "${FRAMEWORK}" PATH)
+    get_target_property (LIBRARY_LOCATION ${LIB} LOCATION)
+    get_filename_component (LIBRARY_TARGET_FILE ${LIBRARY_LOCATION} NAME)
+    get_filename_component (LIBRARY_COPY_PATH "${FRAMEWORK_DIR}/${LIBRARY_TARGET_FILE}" ABSOLUTE)
+
+    # Add copy command for library during post processing
+    add_custom_command(TARGET ${TARGET}
+      POST_BUILD
+      COMMAND ${CMAKE_COMMAND}
+      ARGS -E copy ${LIBRARY_LOCATION} ${LIBRARY_COPY_PATH})
+    # setup install name tool command after post processing
+    add_custom_command (TARGET ${TARGET}
+      POST_BUILD
+      COMMAND install_name_tool
+      ARGS -id "${INSTALL_NAME_TOOL_DIR}/${FRAMEWORK_NAME}.framework/Versions/${VERSION}/${LIBRARY_TARGET_FILE}" "${LIBRARY_COPY_PATH}" )
+
+    # Setup install name tool command to update loader path for all dependent libraries
+    foreach (DEP ${DEPENDENCIES})
+      set (DEP_NEW_LINK_PATH "@loader_path/Libraries/lib${DEP}.dylib")
+      add_custom_command(TARGET ${TARGET}
+        POST_BUILD
+        COMMAND install_name_tool
+        ARGS -change "${LIBRARY_LOCATION_DIR}/lib${DEP}.dylib"  "${DEP_NEW_LINK_PATH}" ${LIBRARY_COPY_PATH})
+      get_target_property (DEP_SO_VERSION ${DEP} SOVERSION)
+      if (DEP_SO_VERSION)
+        add_custom_command(TARGET ${TARGET}
+          POST_BUILD
+          COMMAND install_name_tool
+          ARGS -change "${LIBRARY_LOCATION_DIR}/lib${DEP}.${DEP_SO_VERSION}.dylib"  "${DEP_NEW_LINK_PATH}" ${LIBRARY_COPY_PATH})
+      endif (DEP_SO_VERSION)
+      get_target_property (DEP_VERSION ${DEP} VERSION)
+      if (DEP_VERSION)
+        add_custom_command(TARGET ${TARGET}
+          POST_BUILD
+          COMMAND install_name_tool
+          ARGS -change "${LIBRARY_LOCATION_DIR}/lib${DEP}.${DEP_VERSION}.dylib"  "${DEP_NEW_LINK_PATH}" ${LIBRARY_COPY_PATH})
+      endif (DEP_VERSION)
+    endforeach (DEP ${DEPENDENCIES})    
+    # Create symlink in outer directory to it
+    add_custom_command (TARGET ${TARGET}
+      POST_BUILD
+      WORKING_DIRECTORY "${FRAMEWORK_DIR}/../.."
+      COMMAND ${CMAKE_COMMAND}
+      ARGS -E create_symlink "Versions/Current/${LIBRARY_TARGET_FILE}" "${LIBRARY_TARGET_FILE}" )
+    # strip dylib if we are in Release mode
+    add_custom_command (TARGET ${TARGET}
+      POST_BUILD
+      COMMAND if [ $<CONFIGURATION> == Release ] \; then strip -u ${LIBRARY_COPY_PATH} \; fi )
+  endif (TARGET ${LIB})
+  
+  # copy library dSYMs into framework dSYM if they exist
+  if (OSX_FRAMEWORK_CREATE_DSYM)
+    get_filename_component (FRAMEWORK_NAME "${FRAMEWORK}" NAME)
+    add_custom_command (TARGET ${TARGET}
+      POST_BUILD
+      COMMAND if [ -a "${LIBRARY_LOCATION}.dSYM" ] \; then cp "${LIBRARY_LOCATION}.dSYM/Contents/Resources/DWARF/*" "${LIBRARY_LOCATION_DIR}/${FRAMEWORK_NAME}.framework.dSYM/Contents/Resources/DWARF" \; fi )
+  endif (OSX_FRAMEWORK_CREATE_DSYM)
+endfunction (add_framework_independent_library)
+
+function (add_framework TARGET FRAMEWORK_NAME FILES VERSION INSTALL_NAME_TOOL_DIR)
+   # Create Actual Framework library and add files to it
+  add_library(${TARGET} SHARED ${FILES})
+
+  # Set Settings so it is a framework
+  set_target_properties(${TARGET}
+    PROPERTIES
+    FRAMEWORK TRUE
+    FRAMEWORK_VERSION ${VERSION}
+    OUTPUT_NAME ${FRAMEWORK_NAME} )
+  # get location of framework so we can install_name_tool it correctly
+  get_target_property (FRAMEWORK_LOCATION ${TARGET} LOCATION)
+  get_filename_component (FRAMEWORK_DIR "${FRAMEWORK_LOCATION}" PATH)   
+  set_target_properties (${TARGET} PROPERTIES BUNDLE_DIRECTORY "${FRAMEWORK_DIR}/../.." )
+
+  # setup install name tool command after post processing
+  add_custom_command (TARGET ${TARGET}
+    POST_BUILD
+    COMMAND install_name_tool
+    ARGS -id "${INSTALL_NAME_TOOL_DIR}/${FRAMEWORK_NAME}.framework/Versions/${VERSION}/${FRAMEWORK_NAME}" "${FRAMEWORK_LOCATION}" )
+  # strip framework if we are in Release mode
+  add_custom_command (TARGET ${TARGET}
+    POST_BUILD
+    COMMAND if [ $<CONFIGURATION> == Release ] \; then strip -u ${FRAMEWORK_LOCATION} \; fi )
+endfunction (add_framework)
+
+function (set_xcode_debug_info TARGET)
+  if (OSX_FRAMEWORK_CREATE_DSYM)
+    # CMake 2.8.8 and previous versions have a major bug regarding configuration-dependent Xcode attributes
+    ## See CMake Bugtracker: http://public.kitware.com/Bug/view.php?id=12532
+    ## All this can be cleaned once CMAKE_XCODE_ATTRIB_CONFIG is lower than the minimum required for Xcode 4.3
+    ## CMAKE_XCODE_ATTRIB_CONFIG should be set to the first CMake version that supports configuration-dependent Xcode attributes
+    set (CMAKE_XCODE_ATTRIB_CONFIG 9.9.9)
+    if (${CMAKE_VERSION} VERSION_GREATER ${CMAKE_XCODE_ATTRIB_CONFIG})
+      set_target_properties (${TARGET} PROPERTIES XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT[variant=Release] "dwarf-with-dsym")
+    else (${CMAKE_VERSION} VERSION_GREATER ${CMAKE_XCODE_ATTRIB_CONFIG})
+      set_target_properties (${TARGET} PROPERTIES XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym")
+    endif (${CMAKE_VERSION} VERSION_GREATER ${CMAKE_XCODE_ATTRIB_CONFIG})
+    set_target_properties (${TARGET} PROPERTIES XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS "YES")
+  endif (OSX_FRAMEWORK_CREATE_DSYM)
+endfunction (set_xcode_debug_info)
--- osx-framework/build-osx-framework.sh	1970-01-01 09:00:00.000000000 +0900
+++ osx-framework/build-osx-framework.sh	2013-08-15 11:37:11.000000000 +0900
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+# IMPORTANT: Please upgrade Xcode and CMake to latest versions before running this script
+## This script was initially written for Xcode 4.3.2
+
+FRAMEWORKS_DIR_NAME="Frameworks"
+TEMP_DIR_NAME="temp-build-framework"
+
+if [ $# -ne 1 ]; then
+   echo "    Syntax: $0 <framework build directory>\n        Frameworks will be built in <framework build directory>/$TEMP_DIR_NAME\n        and moved to <framework build directory>/$FRAMEWORKS_DIR_NAME\n        WARNING These directories will be deleted upon script launch"
+exit; fi
+if [ ! -d $1 ]; then
+   echo "Error : $1 is not an existing directory"
+exit; fi
+
+FRAMEWORK_PROJECT_NAME="OpenCV_OSXFramework"
+
+INI_DIR=`pwd`
+cd $1
+BUILD_DIR=`pwd`
+FRAMEWORKS_DIR="$BUILD_DIR/$FRAMEWORKS_DIR_NAME"
+TEMP_BUILD_DIR="$BUILD_DIR/$TEMP_DIR_NAME"
+cd $INI_DIR
+INI_DIR=`dirname $0`
+cd $INI_DIR/..
+SOURCE_DIR=`pwd`
+
+rm -rf $FRAMEWORKS_DIR
+rm -rf $TEMP_BUILD_DIR
+mkdir -p $TEMP_BUILD_DIR
+cd $TEMP_BUILD_DIR
+
+unset PKG_CONFIG_PATH
+export CMAKE_OSX_ARCHITECTURES="x86_64"
+
+# Note: if you wish to change the framework's linker path add one of the following:
+## -D "OSX_FRAMEWORK_LINKER_PATH_ABSOLUTE=ON"
+## -D "OSX_FRAMEWORK_LINKER_PATH_CUSTOM=/new/path"
+### The default path is @executable_path/../Frameworks
+### OSX_FRAMEWORK_LINKER_PATH_ABSOLUTE sets the path to /Library/Frameworks
+### OSX_FRAMEWORK_LINKER_PATH_CUSTOM overrides OSX_FRAMEWORK_LINKER_PATH_ABSOLUTE
+
+cmake -G "Xcode" -D "BUILD_ZLIB=ON" -D "BUILD_TIFF=ON" -D "BUILD_JASPER=ON" -D "BUILD_JPEG=ON" -D "BUILD_PNG=ON" -D "WITH_1394=OFF" -D "WITH_AVFOUNDATION=ON" -D "WITH_CARBON=OFF" -D "WITH_CUDA=OFF" -D "WITH_EIGEN=ON" -D "WITH_FFMPEG=ON" -D "WITH_IPP=OFF" -D "WITH_OPENEXR=OFF" -D "WITH_OPENNI=OFF" -D "WITH_PVAPI=OFF" -D "WITH_QT=OFF" -D "WITH_QUICKTIME=OFF" -D "WITH_TBB=ON" -D "BUILD_opencv_python=ON" -D "BUILD_opencv_java=ON" -D "BUILD_DOCS=OFF" -D "BUILD_PERF_TESTS=OFF" -D "BUILD_TESTS=OFF" -D "OSX_FRAMEWORK_TARGET_NAME=$FRAMEWORK_PROJECT_NAME" -D "OSX_FRAMEWORK_CREATE_DSYM=ON" $SOURCE_DIR
+
+xcodebuild -project OpenCV.xcodeproj -target $FRAMEWORK_PROJECT_NAME -configuration Release
+mkdir -p $FRAMEWORKS_DIR/Release
+cp -R lib/Release/*.framework* $FRAMEWORKS_DIR/Release
+
+#  We have to run cmake a second time with OSX_FRAMEWORK_CREATE_DSYM=OFF
+## because of a bug in CMake 2.8.8 writing different Xcode settings
+## in Debug and Release configurations.
+## This should be fixed in CMake 2.8.9 but that is not certain yet.
+## See Cmake Bugtracker: http://public.kitware.com/Bug/view.php?id=12532
+## Once it is fixed the last lines of OpenCVOSXFrameworkFunctions.cmake must
+## be edited then the next lines up to the cmake line included can be removed
+mkdir tempDebug
+cd tempDebug
+cmake -G "Xcode" -D "BUILD_ZLIB=ON" -D "BUILD_TIFF=ON" -D "BUILD_JASPER=ON" -D "BUILD_JPEG=ON" -D "BUILD_PNG=ON" -D "WITH_1394=OFF" -D "WITH_AVFOUNDATION=ON" -D "WITH_CARBON=OFF" -D "WITH_CUDA=OFF" -D "WITH_EIGEN=ON" -D "WITH_FFMPEG=ON" -D "WITH_IPP=OFF" -D "WITH_OPENEXR=OFF" -D "WITH_OPENNI=OFF" -D "WITH_PVAPI=OFF" -D "WITH_QT=OFF" -D "WITH_QUICKTIME=OFF" -D "WITH_TBB=ON" -D "BUILD_opencv_python=ON" -D "BUILD_opencv_java=ON" -D "BUILD_DOCS=OFF" -D "BUILD_PERF_TESTS=OFF" -D "BUILD_TESTS=OFF" -D "OSX_FRAMEWORK_TARGET_NAME=$FRAMEWORK_PROJECT_NAME" -D "OSX_FRAMEWORK_CREATE_DSYM=OFF" $SOURCE_DIR
+
+xcodebuild -project OpenCV.xcodeproj -target $FRAMEWORK_PROJECT_NAME -configuration Debug
+mkdir -p $FRAMEWORKS_DIR/Debug
+cp -R lib/Debug/*.framework* $FRAMEWORKS_DIR/Debug
+
+echo "\nFrameworks were copied to $FRAMEWORKS_DIR\nYou can now delete $TEMP_BUILD_DIR"
+
+exit 0
