Dynamic build for Objective-C/Swift wrapper
authorGiles Payne <gilespayne@gmail.com>
Thu, 25 Jun 2020 12:27:31 +0000 (21:27 +0900)
committerGiles Payne <gilespayne@gmail.com>
Thu, 25 Jun 2020 23:26:05 +0000 (08:26 +0900)
57 files changed:
cmake/OpenCVGenInfoPlist.cmake
modules/core/misc/objc/common/ByteVector.h
modules/core/misc/objc/common/CVObjcUtil.h
modules/core/misc/objc/common/Converters.h
modules/core/misc/objc/common/CvType.h
modules/core/misc/objc/common/DMatch.h
modules/core/misc/objc/common/Double2.h
modules/core/misc/objc/common/Double3.h
modules/core/misc/objc/common/DoubleVector.h
modules/core/misc/objc/common/Float4.h
modules/core/misc/objc/common/Float6.h
modules/core/misc/objc/common/FloatVector.h
modules/core/misc/objc/common/Int4.h
modules/core/misc/objc/common/IntVector.h
modules/core/misc/objc/common/KeyPoint.h
modules/core/misc/objc/common/Mat.h
modules/core/misc/objc/common/MatOfByte.h
modules/core/misc/objc/common/MatOfDMatch.h
modules/core/misc/objc/common/MatOfDouble.h
modules/core/misc/objc/common/MatOfFloat.h
modules/core/misc/objc/common/MatOfFloat4.h
modules/core/misc/objc/common/MatOfFloat6.h
modules/core/misc/objc/common/MatOfInt.h
modules/core/misc/objc/common/MatOfInt4.h
modules/core/misc/objc/common/MatOfKeyPoint.h
modules/core/misc/objc/common/MatOfPoint2f.h
modules/core/misc/objc/common/MatOfPoint2i.h
modules/core/misc/objc/common/MatOfPoint3.h
modules/core/misc/objc/common/MatOfPoint3f.h
modules/core/misc/objc/common/MatOfRect2d.h
modules/core/misc/objc/common/MatOfRect2i.h
modules/core/misc/objc/common/MatOfRotatedRect.h
modules/core/misc/objc/common/MinMaxLocResult.h
modules/core/misc/objc/common/Point2d.h
modules/core/misc/objc/common/Point2f.h
modules/core/misc/objc/common/Point2i.h
modules/core/misc/objc/common/Point3d.h
modules/core/misc/objc/common/Point3f.h
modules/core/misc/objc/common/Point3i.h
modules/core/misc/objc/common/Range.h
modules/core/misc/objc/common/Rect2d.h
modules/core/misc/objc/common/Rect2f.h
modules/core/misc/objc/common/Rect2i.h
modules/core/misc/objc/common/RotatedRect.h
modules/core/misc/objc/common/Scalar.h
modules/core/misc/objc/common/Size2d.h
modules/core/misc/objc/common/Size2f.h
modules/core/misc/objc/common/Size2i.h
modules/core/misc/objc/common/TermCriteria.h
modules/imgcodecs/misc/objc/ios/Mat+Converters.h
modules/imgproc/misc/objc/common/Moments.h
modules/objc/generator/templates/cmakelists.template
modules/objc/generator/templates/objc_class_header.template
modules/objc/generator/templates/objc_module_header.template
modules/videoio/misc/objc/ios/CvCamera2.h
platforms/ios/Info.Dynamic.plist.in
platforms/ios/build_framework.py

index 6dbdc5b..90dd854 100644 (file)
@@ -2,7 +2,7 @@ set(OPENCV_APPLE_BUNDLE_NAME "OpenCV")
 set(OPENCV_APPLE_BUNDLE_ID "org.opencv")
 
 if(IOS)
-  if (APPLE_FRAMEWORK AND BUILD_SHARED_LIBS)
+  if (APPLE_FRAMEWORK AND DYNAMIC_PLIST)
     configure_file("${OpenCV_SOURCE_DIR}/platforms/ios/Info.Dynamic.plist.in"
                    "${CMAKE_BINARY_DIR}/ios/Info.plist")
   else()
index e0cce73..77369fa 100644 (file)
 #ifdef __cplusplus
 #import <vector>
 #endif
+#import "CVObjcUtil.h"
 
 NS_ASSUME_NONNULL_BEGIN
 
 /**
 * Utility class to wrap a `std::vector<char>`
 */
-@interface ByteVector : NSObject
+CV_EXPORTS @interface ByteVector : NSObject
 
 #pragma mark - Constructors
 
index 9d7d986..2058138 100644 (file)
@@ -12,6 +12,14 @@ typedef union { float f; int32_t i; } V32;
 #define DOUBLE_TO_BITS(x)  ((V64){ .d = x }).l
 #define FLOAT_TO_BITS(x)  ((V32){ .f = x }).i
 
+#ifndef CV_EXPORTS
+#ifdef __cplusplus
+#define CV_EXPORTS __attribute__ ((visibility ("default")))
+#else
+#define CV_EXPORTS
+#endif
+#endif
+
 #ifdef __cplusplus
 #import <vector>
 
index c73c3fa..783d991 100755 (executable)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import <opencv2/opencv.hpp>
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -27,7 +29,7 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
-@interface Converters : NSObject
+CV_EXPORTS @interface Converters : NSObject
 
 + (Mat*)vector_Point_to_Mat:(NSArray<Point2i*>*)pts NS_SWIFT_NAME(vector_Point_to_Mat(_:));
 
index 15d1598..fb6f86a 100644 (file)
@@ -6,6 +6,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -15,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Utility functions for handling CvType values
 */
-@interface CvType : NSObject
+CV_EXPORTS @interface CvType : NSObject
 
 #pragma mark - Type Utility functions
 
index 79d9f55..51bed49 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -18,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
 * Structure for matching: query descriptor index, train descriptor index, train
 * image index and distance between descriptors.
 */
-@interface DMatch : NSObject
+CV_EXPORTS @interface DMatch : NSObject
 
 /**
  * Query descriptor index.
index 7512e37..2162acb 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -19,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Simple wrapper for a vector of two `double`
 */
-@interface Double2 : NSObject
+CV_EXPORTS @interface Double2 : NSObject
 
 #pragma mark - Properties
 
@@ -33,11 +35,6 @@ NS_ASSUME_NONNULL_BEGIN
 */
 @property double v1;
 
-/**
-* Third vector element
-*/
-@property double v2;
-
 
 #ifdef __cplusplus
 /**
index dc361bb..2aaba9a 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -19,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Simple wrapper for a vector of three `double`
 */
-@interface Double3 : NSObject
+CV_EXPORTS @interface Double3 : NSObject
 
 #pragma mark - Properties
 
index 6f33819..8ee8974 100644 (file)
 #ifdef __cplusplus
 #import <vector>
 #endif
+#import "CVObjcUtil.h"
 
 NS_ASSUME_NONNULL_BEGIN
 
 /**
 * Utility class to wrap a `std::vector<double>`
 */
-@interface DoubleVector : NSObject
+CV_EXPORTS @interface DoubleVector : NSObject
 
 #pragma mark - Constructors
 
index d0c52dc..2a89278 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -19,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Simple wrapper for a vector of four `float`
 */
-@interface Float4 : NSObject
+CV_EXPORTS @interface Float4 : NSObject
 
 #pragma mark - Properties
 
index c1c0ddd..d2ec19a 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -19,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Simple wrapper for a vector of six `float`
 */
-@interface Float6 : NSObject
+CV_EXPORTS @interface Float6 : NSObject
 
 #pragma mark - Properties
 
index 9aa2592..9ef0ffa 100644 (file)
 #ifdef __cplusplus
 #import <vector>
 #endif
+#import "CVObjcUtil.h"
 
 NS_ASSUME_NONNULL_BEGIN
 
 /**
 * Utility class to wrap a `std::vector<float>`
 */
-@interface FloatVector : NSObject
+CV_EXPORTS @interface FloatVector : NSObject
 
 #pragma mark - Constructors
 
index 583feef..1a17266 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -19,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Simple wrapper for a vector of four `int`
 */
-@interface Int4 : NSObject
+CV_EXPORTS @interface Int4 : NSObject
 
 #pragma mark - Properties
 
index e8c4acc..752f6e0 100644 (file)
 #ifdef __cplusplus
 #import <vector>
 #endif
+#import "CVObjcUtil.h"
 
 NS_ASSUME_NONNULL_BEGIN
 
 /**
 * Utility class to wrap a `std::vector<int>`
 */
-@interface IntVector : NSObject
+CV_EXPORTS @interface IntVector : NSObject
 
 #pragma mark - Constructors
 
index 680aafa..547960d 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -18,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 *  Object representing a point feature found by one of many available keypoint detectors, such as Harris corner detector, FAST, StarDetector, SURF, SIFT etc.
 */
-@interface KeyPoint : NSObject
+CV_EXPORTS @interface KeyPoint : NSObject
 
 #pragma mark - Properties
 
index 1542309..9808738 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -23,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * The class Mat represents an n-dimensional dense numerical single-channel or multi-channel array.
 */
-@interface Mat : NSObject
+CV_EXPORTS @interface Mat : NSObject
 
 #ifdef __cplusplus
 @property(readonly) cv::Ptr<cv::Mat> nativePtr;
index 27d360e..8b94359 100644 (file)
@@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Mat representation of an array of bytes
 */
-@interface MatOfByte : Mat
+CV_EXPORTS @interface MatOfByte : Mat
 
 #pragma mark - Constructors
 
index 9750710..8839171 100644 (file)
@@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Mat representation of an array of DMatch objects
 */
-@interface MatOfDMatch : Mat
+CV_EXPORTS @interface MatOfDMatch : Mat
 
 #pragma mark - Constructors
 
index 16a925a..bd0e6b5 100644 (file)
@@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Mat representation of an array of doubles
 */
-@interface MatOfDouble : Mat
+CV_EXPORTS @interface MatOfDouble : Mat
 
 #pragma mark - Constructors
 
index 110819d..ebf1ab1 100644 (file)
@@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Mat representation of an array of floats
 */
-@interface MatOfFloat : Mat
+CV_EXPORTS @interface MatOfFloat : Mat
 
 #ifdef __cplusplus
 - (instancetype)initWithNativeMat:(cv::Mat*)nativeMat;
index 852e04b..b037aa2 100644 (file)
@@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Mat representation of an array of vectors of four floats
 */
-@interface MatOfFloat4 : Mat
+CV_EXPORTS @interface MatOfFloat4 : Mat
 
 #pragma mark - Constructors
 
index c602f48..cf05d40 100644 (file)
@@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Mat representation of an array of vectors of six floats
 */
-@interface MatOfFloat6 : Mat
+CV_EXPORTS @interface MatOfFloat6 : Mat
 
 #pragma mark - Constructors
 
index b7e2183..6ea7864 100644 (file)
@@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Mat representation of an array of ints
 */
-@interface MatOfInt : Mat
+CV_EXPORTS @interface MatOfInt : Mat
 
 #pragma mark - Constructors
 
index c1fb40b..454a8b1 100644 (file)
@@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Mat representation of an array of vectors of four ints
 */
-@interface MatOfInt4 : Mat
+CV_EXPORTS @interface MatOfInt4 : Mat
 
 #pragma mark - Constructors
 
index 769e836..b9b5154 100644 (file)
@@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Mat representation of an array of KeyPoint objects
 */
-@interface MatOfKeyPoint : Mat
+CV_EXPORTS @interface MatOfKeyPoint : Mat
 
 #pragma mark - Constructors
 
index e6b6a2d..e634e7a 100644 (file)
@@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Mat representation of an array of Point2f objects
 */
-@interface MatOfPoint2f : Mat
+CV_EXPORTS @interface MatOfPoint2f : Mat
 
 #pragma mark - Constructors
 
index dea9710..f02007f 100644 (file)
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
 * Mat representation of an array of Point objects
 */
 NS_SWIFT_NAME(MatOfPoint)
-@interface MatOfPoint2i : Mat
+CV_EXPORTS @interface MatOfPoint2i : Mat
 
 #pragma mark - Constructors
 
index d1ab9b8..4da850d 100644 (file)
@@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Mat representation of an array of Point3i objects
 */
-@interface MatOfPoint3 : Mat
+CV_EXPORTS @interface MatOfPoint3 : Mat
 
 #pragma mark - Constructors
 
index e9ba7b3..a0f06bf 100644 (file)
@@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Mat representation of an array of Point3f objects
 */
-@interface MatOfPoint3f : Mat
+CV_EXPORTS @interface MatOfPoint3f : Mat
 
 #pragma mark - Constructors
 
index 4388fcf..7a3da8e 100644 (file)
@@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Mat representation of an array of Rect2d objects
 */
-@interface MatOfRect2d : Mat
+CV_EXPORTS @interface MatOfRect2d : Mat
 
 #pragma mark - Constructors
 
index fa23338..3c80ffb 100644 (file)
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
 * Mat representation of an array of Rect objects
 */
 NS_SWIFT_NAME(MatOfRect)
-@interface MatOfRect2i : Mat
+CV_EXPORTS @interface MatOfRect2i : Mat
 
 #pragma mark - Constructors
 
index a9108e0..de1347b 100644 (file)
@@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Mat representation of an array of RotatedRect objects
 */
-@interface MatOfRotatedRect : Mat
+CV_EXPORTS @interface MatOfRotatedRect : Mat
 
 #pragma mark - Constructors
 
index 87593f2..e8daed4 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -19,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Result of operation to determine global minimum and maximum of an array
 */
-@interface MinMaxLocResult : NSObject
+CV_EXPORTS @interface MinMaxLocResult : NSObject
 
 #pragma mark - Properties
 
index 8187c07..dbb8d55 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -19,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Represents a two dimensional point the coordinate values of which are of type `double`
 */
-@interface Point2d : NSObject
+CV_EXPORTS @interface Point2d : NSObject
 
 # pragma mark - Properties
 
index 6d7d0f9..0da4fba 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -19,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Represents a two dimensional point the coordinate values of which are of type `float`
 */
-@interface Point2f : NSObject
+CV_EXPORTS @interface Point2f : NSObject
 
 # pragma mark - Properties
 
index ac545d4..9e5d746 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -20,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
 * Represents a two dimensional point the coordinate values of which are of type `int`
 */
 NS_SWIFT_NAME(Point)
-@interface Point2i : NSObject
+CV_EXPORTS @interface Point2i : NSObject
 
 # pragma mark - Properties
 
index 271fbb1..31b5ab8 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -19,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Represents a three dimensional point the coordinate values of which are of type `double`
 */
-@interface Point3d : NSObject
+CV_EXPORTS @interface Point3d : NSObject
 
 # pragma mark - Properties
 
index 8f02aae..f667ff9 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -19,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Represents a three dimensional point the coordinate values of which are of type `float`
 */
-@interface Point3f : NSObject
+CV_EXPORTS @interface Point3f : NSObject
 
 # pragma mark - Properties
 
index 5323cb8..832f68d 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -19,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Represents a three dimensional point the coordinate values of which are of type `int`
 */
-@interface Point3i : NSObject
+CV_EXPORTS @interface Point3i : NSObject
 
 # pragma mark - Properties
 
index ba0aa54..dd84edf 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -17,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Represents a range of dimension indices
 */
-@interface Range : NSObject
+CV_EXPORTS @interface Range : NSObject
 
 #pragma mark - Properties
 
index c1d9442..ba91509 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 @class Point2d;
@@ -20,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Represents a rectange the coordinate and dimension values of which are of type `double`
 */
-@interface Rect2d : NSObject
+CV_EXPORTS @interface Rect2d : NSObject
 
 #pragma mark - Properties
 
index 9ed5f40..6a88638 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 @class Point2f;
@@ -20,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Represents a rectange the coordinate and dimension values of which are of type `float`
 */
-@interface Rect2f : NSObject
+CV_EXPORTS @interface Rect2f : NSObject
 
 #pragma mark - Properties
 
index a94a547..2e4e55c 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 @class Point2i;
@@ -21,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
 * Represents a rectange the coordinate and dimension values of which are of type `int`
 */
 NS_SWIFT_NAME(Rect)
-@interface Rect2i : NSObject
+CV_EXPORTS @interface Rect2i : NSObject
 
 #pragma mark - Properties
 
index 5571e73..c94053b 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 @class Point2f;
@@ -21,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Represents a rotated rectangle on a plane
 */
-@interface RotatedRect : NSObject
+CV_EXPORTS @interface RotatedRect : NSObject
 
 #pragma mark - Properties
 
index ebf54c4..63c3d1d 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -17,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Represents a four element vector
 */
-@interface Scalar : NSObject
+CV_EXPORTS @interface Scalar : NSObject
 
 #pragma mark - Properties
 
index 233f4c2..11c6c50 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 @class Point2d;
@@ -19,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Represents the dimensions of a rectangle the values of which are of type `double`
 */
-@interface Size2d : NSObject
+CV_EXPORTS @interface Size2d : NSObject
 
 #pragma mark - Properties
 
index 83f1bae..2d1f286 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 @class Point2f;
@@ -19,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Represents the dimensions of a rectangle the values of which are of type `float`
 */
-@interface Size2f : NSObject
+CV_EXPORTS @interface Size2f : NSObject
 
 #pragma mark - Properties
 
index 9a714da..61aa8da 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 @class Point2i;
@@ -20,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
 * Represents the dimensions of a rectangle the values of which are of type `int`
 */
 NS_SWIFT_NAME(Size)
-@interface Size2i : NSObject
+CV_EXPORTS @interface Size2i : NSObject
 
 #pragma mark - Properties
 
index 1e3055d..c739658 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -17,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
 * Class representing termination criteria for iterative algorithms.
 */
-@interface TermCriteria : NSObject
+CV_EXPORTS @interface TermCriteria : NSObject
 
 #pragma mark - Properties
 
index 73dbe9c..d33abbf 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -16,7 +18,7 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
-@interface Mat (Converters)
+CV_EXPORTS @interface Mat (Converters)
 
 -(UIImage*)toUIImage;
 -(instancetype)initWithUIImage:(UIImage*)image;
index cf64625..dfa5653 100644 (file)
@@ -8,13 +8,15 @@
 
 #ifdef __cplusplus
 #import "opencv.hpp"
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
 
 NS_ASSUME_NONNULL_BEGIN
 
-@interface Moments : NSObject
+CV_EXPORTS @interface Moments : NSObject
 
 @property double m00;
 @property double m10;
index d6fab2c..42acc27 100644 (file)
@@ -8,7 +8,7 @@ set(MODULES "$modules")
 set (CMAKE_CXX_STANDARD 11)
 set (CMAKE_CXX_STANDARD_REQUIRED TRUE)
 
-set (OBJC_COMPILE_FLAGS "-fobjc-arc -fobjc-weak -fvisibility=hidden -D__OPENCV_BUILD=1")
+set (OBJC_COMPILE_FLAGS "-fobjc-arc -fobjc-weak -fvisibility=hidden -fPIC -D__OPENCV_BUILD=1")
 set (SUPPRESS_WARNINGS_FLAGS "-Wno-incomplete-umbrella")
 set (CMAKE_CXX_FLAGS  "$${CMAKE_CXX_FLAGS} $${OBJC_COMPILE_FLAGS} $${SUPPRESS_WARNINGS_FLAGS}")
 
index fae6b48..0bad670 100644 (file)
@@ -6,6 +6,8 @@
 #ifdef __cplusplus
 #import "opencv.hpp"
 $additionalImports
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -18,7 +20,7 @@ $enumDeclarations
 NS_ASSUME_NONNULL_BEGIN
 
 $docs
-@interface $objcName : $base
+CV_EXPORTS @interface $objcName : $base
 
 $nativePointerHandling
 
index 9c7f14b..fa9e7df 100644 (file)
@@ -6,6 +6,8 @@
 #ifdef __cplusplus
 #import "opencv.hpp"
 $additionalImports
+#else
+#define CV_EXPORTS
 #endif
 
 #import <Foundation/Foundation.h>
@@ -17,7 +19,7 @@ $enumDeclarations
 NS_ASSUME_NONNULL_BEGIN
 
 $docs
-@interface $module : $base
+CV_EXPORTS @interface $module : $base
 
 $methodDeclarations
 
index 0127116..e4ec03b 100644 (file)
@@ -8,12 +8,13 @@
 #import <Accelerate/Accelerate.h>
 #import <AVFoundation/AVFoundation.h>
 #import <ImageIO/ImageIO.h>
+#import "CVObjcUtil.h"
 
 @class Mat;
 
 @class CvAbstractCamera2;
 
-@interface CvAbstractCamera2 : NSObject
+CV_EXPORTS @interface CvAbstractCamera2 : NSObject
 
 @property UIDeviceOrientation currentDeviceOrientation;
 @property BOOL cameraAvailable;
@@ -55,7 +56,7 @@
 - (void)processImage:(Mat*)image;
 @end
 
-@interface CvVideoCamera2 : CvAbstractCamera2<AVCaptureVideoDataOutputSampleBufferDelegate>
+CV_EXPORTS @interface CvVideoCamera2 : CvAbstractCamera2<AVCaptureVideoDataOutputSampleBufferDelegate>
 @property (nonatomic, weak) id<CvVideoCameraDelegate2> delegate;
 @property (nonatomic, assign) BOOL grayscaleMode;
 @property (nonatomic, assign) BOOL recordVideo;
@@ -78,7 +79,7 @@
 - (void)photoCameraCancel:(CvPhotoCamera2*)photoCamera;
 @end
 
-@interface CvPhotoCamera2 : CvAbstractCamera2<AVCapturePhotoCaptureDelegate>
+CV_EXPORTS @interface CvPhotoCamera2 : CvAbstractCamera2<AVCapturePhotoCaptureDelegate>
 @property (nonatomic, weak) id<CvPhotoCameraDelegate2> delegate;
 - (void)takePicture;
 @end
index 00c9277..e48fffd 100644 (file)
@@ -5,7 +5,7 @@
     <key>CFBundleDevelopmentRegion</key>
     <string>en</string>
     <key>CFBundleExecutable</key>
-    <string>opencv2</string>
+    <string>${FRAMEWORK_NAME}</string>
     <key>CFBundleName</key>
     <string>${OPENCV_APPLE_BUNDLE_NAME}</string>
     <key>CFBundleIdentifier</key>
index 58d6517..c498a46 100755 (executable)
@@ -49,6 +49,14 @@ def getXCodeMajor():
     else:
         raise Exception("Failed to parse Xcode version")
 
+def getXCodeSetting(var, projectdir):
+    ret = check_output(["xcodebuild", "-showBuildSettings"], cwd = projectdir)
+    m = re.search("\s" + var + " = (.*)", ret)
+    if m:
+        return m.group(1)
+    else:
+        raise Exception("Failed to parse Xcode settings")
+
 class Builder:
     def __init__(self, opencv, contrib, dynamic, bitcodedisabled, exclude, disable, enablenonfree, targets, debug, debug_info, framework_name):
         self.opencv = os.path.abspath(opencv)
@@ -90,7 +98,7 @@ class Builder:
 
         xcode_ver = getXCodeMajor()
 
-        if self.dynamic:
+        if self.dynamic and not self.build_objc_wrapper:
             alltargets = self.targets
         else:
             # if we are building a static library, we must build each architecture separately
@@ -114,8 +122,10 @@ class Builder:
                 cmake_flags.append("-DCMAKE_CXX_FLAGS=-fembed-bitcode")
             self.buildOne(t[0], t[1], mainBD, cmake_flags)
 
-            if self.dynamic == False:
+            if not self.dynamic:
                 self.mergeLibs(mainBD)
+            elif self.dynamic and self.build_objc_wrapper:
+                self.makeDynamicLib(mainBD)
         self.makeFramework(outdir, dirs)
         if self.build_objc_wrapper:
             print("To run tests call:")
@@ -153,6 +163,8 @@ class Builder:
             "-DBUILD_SHARED_LIBS=ON",
             "-DCMAKE_MACOSX_BUNDLE=ON",
             "-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=NO",
+        ] if self.dynamic and not self.build_objc_wrapper else []) + ([
+            "-DDYNAMIC_PLIST=ON"
         ] if self.dynamic else []) + ([
             "-DOPENCV_ENABLE_NONFREE=ON"
         ] if self.enablenonfree else []) + ([
@@ -160,7 +172,7 @@ class Builder:
         ] if self.debug_info else [])
 
         if len(self.exclude) > 0:
-            args += ["-DBUILD_opencv_world=OFF"] if not self.dynamic else []
+            args += ["-DBUILD_opencv_world=OFF"] if not (self.dynamic and not self.build_objc_wrapper) else []
             args += ["-DBUILD_opencv_%s=OFF" % m for m in self.exclude]
 
         if len(self.disable) > 0:
@@ -174,15 +186,15 @@ class Builder:
             "xcodebuild",
         ]
 
-        if self.dynamic:
+        if (self.dynamic or self.build_objc_wrapper) and not self.bitcodedisabled and target == "iPhoneOS":
+            buildcmd.append("BITCODE_GENERATION_MODE=bitcode")
+
+        if self.dynamic and not self.build_objc_wrapper:
             buildcmd += [
                 "IPHONEOS_DEPLOYMENT_TARGET=" + os.environ['IPHONEOS_DEPLOYMENT_TARGET'],
                 "ONLY_ACTIVE_ARCH=NO",
             ]
 
-            if not self.bitcodedisabled:
-                buildcmd.append("BITCODE_GENERATION_MODE=bitcode")
-
             for arch in archs:
                 buildcmd.append("-arch")
                 buildcmd.append(arch.lower())
@@ -198,7 +210,7 @@ class Builder:
                 "-configuration", self.getConfiguration(),
                 "-parallelizeTargets",
                 "-jobs", str(multiprocessing.cpu_count()),
-            ] + (["-target","ALL_BUILD"] if self.dynamic else [])
+            ] + (["-target","ALL_BUILD"] if self.dynamic and not self.build_objc_wrapper else [])
 
         return buildcmd
 
@@ -253,6 +265,32 @@ class Builder:
         print("Merging libraries:\n\t%s" % "\n\t".join(libs + libs3 + module), file=sys.stderr)
         execute(["libtool", "-static", "-o", res] + libs + libs3 + module)
 
+    def makeDynamicLib(self, builddir):
+        target = builddir[(builddir.rfind("build-") + 6):]
+        target_platform = target[(target.rfind("-") + 1):]
+        is_device = target_platform == "iphoneos"
+        res = os.path.join(builddir, "install", "lib", self.framework_name + ".framework", self.framework_name)
+        libs = glob.glob(os.path.join(builddir, "install", "lib", "*.a"))
+        module = [os.path.join(builddir, "lib", self.getConfiguration(), self.framework_name + ".framework", self.framework_name)]
+
+        libs3 = glob.glob(os.path.join(builddir, "install", "lib", "3rdparty", "*.a"))
+
+        link_target = target[:target.find("-")] + "-apple-ios" + os.environ['IPHONEOS_DEPLOYMENT_TARGET'] + ("-simulator" if target.endswith("simulator") else "")
+        bitcode_flags = ["-fembed-bitcode", "-Xlinker", "-bitcode_verify"] if is_device and not self.bitcodedisabled else []
+        toolchain_dir = getXCodeSetting("TOOLCHAIN_DIR", builddir)
+        swift_link_dirs = ["-L" + toolchain_dir + "/usr/lib/swift/" + target_platform, "-L/usr/lib/swift"]
+        sdk_dir = getXCodeSetting("SDK_DIR", builddir)
+        execute([
+            "clang++",
+            "-Xlinker", "-rpath",
+            "-Xlinker", "/usr/lib/swift",
+            "-target", link_target,
+            "-isysroot", sdk_dir,
+            "-install_name", ("@executable_path/Frameworks/" + self.framework_name + ".framework/" + self.framework_name) if is_device else res,
+            "-dynamiclib", "-dead_strip", "-fobjc-link-runtime", "-all_load",
+            "-o", res
+        ] + swift_link_dirs + bitcode_flags + module + libs + libs3)
+
     def makeFramework(self, outdir, builddirs):
         name = self.framework_name
 
@@ -264,10 +302,8 @@ class Builder:
 
         if self.dynamic:
             dstdir = framework_dir
-            libname = name + ".framework/" + name
         else:
             dstdir = os.path.join(framework_dir, "Versions", "A")
-            libname = "libopencv_merged.a"
 
         # copy headers from one of build folders
         shutil.copytree(os.path.join(builddirs[0], "install", "include", "opencv2"), os.path.join(dstdir, "Headers"))
@@ -301,7 +337,10 @@ class Builder:
                         os.rename(os.path.join(dirname, filename), os.path.join(dirname, platform_name_map[filestem] + fileext))
 
         # make universal static lib
-        libs = [os.path.join(d, "lib", self.getConfiguration(), libname) for d in builddirs]
+        if self.dynamic:
+            libs = [os.path.join(d, "install", "lib", name + ".framework", name) for d in builddirs]
+        else:
+            libs = [os.path.join(d, "lib", self.getConfiguration(), "libopencv_merged.a") for d in builddirs]
         lipocmd = ["lipo", "-create"]
         lipocmd.extend(libs)
         lipocmd.extend(["-o", os.path.join(dstdir, name)])
@@ -412,4 +451,5 @@ if __name__ == "__main__":
             (iphoneos_archs, "iPhoneOS"),
             (iphonesimulator_archs, "iPhoneSimulator"),
         ], args.debug, args.debug_info, args.framework_name)
+
     b.build(args.out)