From 59ba33658ac56883034fb810c12010d0bf40e3ab Mon Sep 17 00:00:00 2001 From: Giles Payne Date: Thu, 25 Jun 2020 21:27:31 +0900 Subject: [PATCH] Dynamic build for Objective-C/Swift wrapper --- cmake/OpenCVGenInfoPlist.cmake | 2 +- modules/core/misc/objc/common/ByteVector.h | 3 +- modules/core/misc/objc/common/CVObjcUtil.h | 8 +++ modules/core/misc/objc/common/Converters.h | 4 +- modules/core/misc/objc/common/CvType.h | 4 +- modules/core/misc/objc/common/DMatch.h | 4 +- modules/core/misc/objc/common/Double2.h | 9 +-- modules/core/misc/objc/common/Double3.h | 4 +- modules/core/misc/objc/common/DoubleVector.h | 3 +- modules/core/misc/objc/common/Float4.h | 4 +- modules/core/misc/objc/common/Float6.h | 4 +- modules/core/misc/objc/common/FloatVector.h | 3 +- modules/core/misc/objc/common/Int4.h | 4 +- modules/core/misc/objc/common/IntVector.h | 3 +- modules/core/misc/objc/common/KeyPoint.h | 4 +- modules/core/misc/objc/common/Mat.h | 4 +- modules/core/misc/objc/common/MatOfByte.h | 2 +- modules/core/misc/objc/common/MatOfDMatch.h | 2 +- modules/core/misc/objc/common/MatOfDouble.h | 2 +- modules/core/misc/objc/common/MatOfFloat.h | 2 +- modules/core/misc/objc/common/MatOfFloat4.h | 2 +- modules/core/misc/objc/common/MatOfFloat6.h | 2 +- modules/core/misc/objc/common/MatOfInt.h | 2 +- modules/core/misc/objc/common/MatOfInt4.h | 2 +- modules/core/misc/objc/common/MatOfKeyPoint.h | 2 +- modules/core/misc/objc/common/MatOfPoint2f.h | 2 +- modules/core/misc/objc/common/MatOfPoint2i.h | 2 +- modules/core/misc/objc/common/MatOfPoint3.h | 2 +- modules/core/misc/objc/common/MatOfPoint3f.h | 2 +- modules/core/misc/objc/common/MatOfRect2d.h | 2 +- modules/core/misc/objc/common/MatOfRect2i.h | 2 +- .../core/misc/objc/common/MatOfRotatedRect.h | 2 +- .../core/misc/objc/common/MinMaxLocResult.h | 4 +- modules/core/misc/objc/common/Point2d.h | 4 +- modules/core/misc/objc/common/Point2f.h | 4 +- modules/core/misc/objc/common/Point2i.h | 4 +- modules/core/misc/objc/common/Point3d.h | 4 +- modules/core/misc/objc/common/Point3f.h | 4 +- modules/core/misc/objc/common/Point3i.h | 4 +- modules/core/misc/objc/common/Range.h | 4 +- modules/core/misc/objc/common/Rect2d.h | 4 +- modules/core/misc/objc/common/Rect2f.h | 4 +- modules/core/misc/objc/common/Rect2i.h | 4 +- modules/core/misc/objc/common/RotatedRect.h | 4 +- modules/core/misc/objc/common/Scalar.h | 4 +- modules/core/misc/objc/common/Size2d.h | 4 +- modules/core/misc/objc/common/Size2f.h | 4 +- modules/core/misc/objc/common/Size2i.h | 4 +- modules/core/misc/objc/common/TermCriteria.h | 4 +- .../imgcodecs/misc/objc/ios/Mat+Converters.h | 4 +- modules/imgproc/misc/objc/common/Moments.h | 4 +- .../generator/templates/cmakelists.template | 2 +- .../templates/objc_class_header.template | 4 +- .../templates/objc_module_header.template | 4 +- modules/videoio/misc/objc/ios/CvCamera2.h | 7 ++- platforms/ios/Info.Dynamic.plist.in | 2 +- platforms/ios/build_framework.py | 62 +++++++++++++++---- 57 files changed, 183 insertions(+), 73 deletions(-) diff --git a/cmake/OpenCVGenInfoPlist.cmake b/cmake/OpenCVGenInfoPlist.cmake index 6dbdc5b9e7..90dd85479f 100644 --- a/cmake/OpenCVGenInfoPlist.cmake +++ b/cmake/OpenCVGenInfoPlist.cmake @@ -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() diff --git a/modules/core/misc/objc/common/ByteVector.h b/modules/core/misc/objc/common/ByteVector.h index e0cce73877..77369fab29 100644 --- a/modules/core/misc/objc/common/ByteVector.h +++ b/modules/core/misc/objc/common/ByteVector.h @@ -10,13 +10,14 @@ #ifdef __cplusplus #import #endif +#import "CVObjcUtil.h" NS_ASSUME_NONNULL_BEGIN /** * Utility class to wrap a `std::vector` */ -@interface ByteVector : NSObject +CV_EXPORTS @interface ByteVector : NSObject #pragma mark - Constructors diff --git a/modules/core/misc/objc/common/CVObjcUtil.h b/modules/core/misc/objc/common/CVObjcUtil.h index 9d7d986708..20581384cc 100644 --- a/modules/core/misc/objc/common/CVObjcUtil.h +++ b/modules/core/misc/objc/common/CVObjcUtil.h @@ -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 diff --git a/modules/core/misc/objc/common/Converters.h b/modules/core/misc/objc/common/Converters.h index c73c3fac76..783d9912a4 100755 --- a/modules/core/misc/objc/common/Converters.h +++ b/modules/core/misc/objc/common/Converters.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import +#else +#define CV_EXPORTS #endif #import @@ -27,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface Converters : NSObject +CV_EXPORTS @interface Converters : NSObject + (Mat*)vector_Point_to_Mat:(NSArray*)pts NS_SWIFT_NAME(vector_Point_to_Mat(_:)); diff --git a/modules/core/misc/objc/common/CvType.h b/modules/core/misc/objc/common/CvType.h index 15d1598da0..fb6f86aa48 100644 --- a/modules/core/misc/objc/common/CvType.h +++ b/modules/core/misc/objc/common/CvType.h @@ -6,6 +6,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 diff --git a/modules/core/misc/objc/common/DMatch.h b/modules/core/misc/objc/common/DMatch.h index 79d9f557d1..51bed493b8 100644 --- a/modules/core/misc/objc/common/DMatch.h +++ b/modules/core/misc/objc/common/DMatch.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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. diff --git a/modules/core/misc/objc/common/Double2.h b/modules/core/misc/objc/common/Double2.h index 7512e37ee2..2162acb6d0 100644 --- a/modules/core/misc/objc/common/Double2.h +++ b/modules/core/misc/objc/common/Double2.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 /** diff --git a/modules/core/misc/objc/common/Double3.h b/modules/core/misc/objc/common/Double3.h index dc361bbc25..2aaba9af80 100644 --- a/modules/core/misc/objc/common/Double3.h +++ b/modules/core/misc/objc/common/Double3.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 diff --git a/modules/core/misc/objc/common/DoubleVector.h b/modules/core/misc/objc/common/DoubleVector.h index 6f338199c9..8ee89741ca 100644 --- a/modules/core/misc/objc/common/DoubleVector.h +++ b/modules/core/misc/objc/common/DoubleVector.h @@ -10,13 +10,14 @@ #ifdef __cplusplus #import #endif +#import "CVObjcUtil.h" NS_ASSUME_NONNULL_BEGIN /** * Utility class to wrap a `std::vector` */ -@interface DoubleVector : NSObject +CV_EXPORTS @interface DoubleVector : NSObject #pragma mark - Constructors diff --git a/modules/core/misc/objc/common/Float4.h b/modules/core/misc/objc/common/Float4.h index d0c52dccfe..2a89278040 100644 --- a/modules/core/misc/objc/common/Float4.h +++ b/modules/core/misc/objc/common/Float4.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 diff --git a/modules/core/misc/objc/common/Float6.h b/modules/core/misc/objc/common/Float6.h index c1c0ddd510..d2ec19a60e 100644 --- a/modules/core/misc/objc/common/Float6.h +++ b/modules/core/misc/objc/common/Float6.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 diff --git a/modules/core/misc/objc/common/FloatVector.h b/modules/core/misc/objc/common/FloatVector.h index 9aa25927c7..9ef0ffa965 100644 --- a/modules/core/misc/objc/common/FloatVector.h +++ b/modules/core/misc/objc/common/FloatVector.h @@ -10,13 +10,14 @@ #ifdef __cplusplus #import #endif +#import "CVObjcUtil.h" NS_ASSUME_NONNULL_BEGIN /** * Utility class to wrap a `std::vector` */ -@interface FloatVector : NSObject +CV_EXPORTS @interface FloatVector : NSObject #pragma mark - Constructors diff --git a/modules/core/misc/objc/common/Int4.h b/modules/core/misc/objc/common/Int4.h index 583feef0ad..1a17266572 100644 --- a/modules/core/misc/objc/common/Int4.h +++ b/modules/core/misc/objc/common/Int4.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 diff --git a/modules/core/misc/objc/common/IntVector.h b/modules/core/misc/objc/common/IntVector.h index e8c4acc45f..752f6e056c 100644 --- a/modules/core/misc/objc/common/IntVector.h +++ b/modules/core/misc/objc/common/IntVector.h @@ -10,13 +10,14 @@ #ifdef __cplusplus #import #endif +#import "CVObjcUtil.h" NS_ASSUME_NONNULL_BEGIN /** * Utility class to wrap a `std::vector` */ -@interface IntVector : NSObject +CV_EXPORTS @interface IntVector : NSObject #pragma mark - Constructors diff --git a/modules/core/misc/objc/common/KeyPoint.h b/modules/core/misc/objc/common/KeyPoint.h index 680aafa72e..547960dc9d 100644 --- a/modules/core/misc/objc/common/KeyPoint.h +++ b/modules/core/misc/objc/common/KeyPoint.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 diff --git a/modules/core/misc/objc/common/Mat.h b/modules/core/misc/objc/common/Mat.h index 1542309277..9808738078 100644 --- a/modules/core/misc/objc/common/Mat.h +++ b/modules/core/misc/objc/common/Mat.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 nativePtr; diff --git a/modules/core/misc/objc/common/MatOfByte.h b/modules/core/misc/objc/common/MatOfByte.h index 27d360ee36..8b94359544 100644 --- a/modules/core/misc/objc/common/MatOfByte.h +++ b/modules/core/misc/objc/common/MatOfByte.h @@ -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 diff --git a/modules/core/misc/objc/common/MatOfDMatch.h b/modules/core/misc/objc/common/MatOfDMatch.h index 97507103ee..8839171a5d 100644 --- a/modules/core/misc/objc/common/MatOfDMatch.h +++ b/modules/core/misc/objc/common/MatOfDMatch.h @@ -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 diff --git a/modules/core/misc/objc/common/MatOfDouble.h b/modules/core/misc/objc/common/MatOfDouble.h index 16a925a982..bd0e6b5503 100644 --- a/modules/core/misc/objc/common/MatOfDouble.h +++ b/modules/core/misc/objc/common/MatOfDouble.h @@ -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 diff --git a/modules/core/misc/objc/common/MatOfFloat.h b/modules/core/misc/objc/common/MatOfFloat.h index 110819d85f..ebf1ab1e69 100644 --- a/modules/core/misc/objc/common/MatOfFloat.h +++ b/modules/core/misc/objc/common/MatOfFloat.h @@ -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; diff --git a/modules/core/misc/objc/common/MatOfFloat4.h b/modules/core/misc/objc/common/MatOfFloat4.h index 852e04bfd1..b037aa2ae7 100644 --- a/modules/core/misc/objc/common/MatOfFloat4.h +++ b/modules/core/misc/objc/common/MatOfFloat4.h @@ -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 diff --git a/modules/core/misc/objc/common/MatOfFloat6.h b/modules/core/misc/objc/common/MatOfFloat6.h index c602f48d9e..cf05d4061c 100644 --- a/modules/core/misc/objc/common/MatOfFloat6.h +++ b/modules/core/misc/objc/common/MatOfFloat6.h @@ -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 diff --git a/modules/core/misc/objc/common/MatOfInt.h b/modules/core/misc/objc/common/MatOfInt.h index b7e218353a..6ea78641d3 100644 --- a/modules/core/misc/objc/common/MatOfInt.h +++ b/modules/core/misc/objc/common/MatOfInt.h @@ -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 diff --git a/modules/core/misc/objc/common/MatOfInt4.h b/modules/core/misc/objc/common/MatOfInt4.h index c1fb40bb4b..454a8b1b3c 100644 --- a/modules/core/misc/objc/common/MatOfInt4.h +++ b/modules/core/misc/objc/common/MatOfInt4.h @@ -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 diff --git a/modules/core/misc/objc/common/MatOfKeyPoint.h b/modules/core/misc/objc/common/MatOfKeyPoint.h index 769e836e83..b9b5154b5a 100644 --- a/modules/core/misc/objc/common/MatOfKeyPoint.h +++ b/modules/core/misc/objc/common/MatOfKeyPoint.h @@ -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 diff --git a/modules/core/misc/objc/common/MatOfPoint2f.h b/modules/core/misc/objc/common/MatOfPoint2f.h index e6b6a2df99..e634e7a0ad 100644 --- a/modules/core/misc/objc/common/MatOfPoint2f.h +++ b/modules/core/misc/objc/common/MatOfPoint2f.h @@ -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 diff --git a/modules/core/misc/objc/common/MatOfPoint2i.h b/modules/core/misc/objc/common/MatOfPoint2i.h index dea9710e31..f02007fda9 100644 --- a/modules/core/misc/objc/common/MatOfPoint2i.h +++ b/modules/core/misc/objc/common/MatOfPoint2i.h @@ -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 diff --git a/modules/core/misc/objc/common/MatOfPoint3.h b/modules/core/misc/objc/common/MatOfPoint3.h index d1ab9b87c7..4da850de04 100644 --- a/modules/core/misc/objc/common/MatOfPoint3.h +++ b/modules/core/misc/objc/common/MatOfPoint3.h @@ -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 diff --git a/modules/core/misc/objc/common/MatOfPoint3f.h b/modules/core/misc/objc/common/MatOfPoint3f.h index e9ba7b37f7..a0f06bff8f 100644 --- a/modules/core/misc/objc/common/MatOfPoint3f.h +++ b/modules/core/misc/objc/common/MatOfPoint3f.h @@ -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 diff --git a/modules/core/misc/objc/common/MatOfRect2d.h b/modules/core/misc/objc/common/MatOfRect2d.h index 4388fcfa11..7a3da8ebce 100644 --- a/modules/core/misc/objc/common/MatOfRect2d.h +++ b/modules/core/misc/objc/common/MatOfRect2d.h @@ -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 diff --git a/modules/core/misc/objc/common/MatOfRect2i.h b/modules/core/misc/objc/common/MatOfRect2i.h index fa23338172..3c80ffb4ff 100644 --- a/modules/core/misc/objc/common/MatOfRect2i.h +++ b/modules/core/misc/objc/common/MatOfRect2i.h @@ -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 diff --git a/modules/core/misc/objc/common/MatOfRotatedRect.h b/modules/core/misc/objc/common/MatOfRotatedRect.h index a9108e030e..de1347bc96 100644 --- a/modules/core/misc/objc/common/MatOfRotatedRect.h +++ b/modules/core/misc/objc/common/MatOfRotatedRect.h @@ -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 diff --git a/modules/core/misc/objc/common/MinMaxLocResult.h b/modules/core/misc/objc/common/MinMaxLocResult.h index 87593f2b18..e8daed4cc3 100644 --- a/modules/core/misc/objc/common/MinMaxLocResult.h +++ b/modules/core/misc/objc/common/MinMaxLocResult.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 diff --git a/modules/core/misc/objc/common/Point2d.h b/modules/core/misc/objc/common/Point2d.h index 8187c074f8..dbb8d55efa 100644 --- a/modules/core/misc/objc/common/Point2d.h +++ b/modules/core/misc/objc/common/Point2d.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 diff --git a/modules/core/misc/objc/common/Point2f.h b/modules/core/misc/objc/common/Point2f.h index 6d7d0f9732..0da4fba5d8 100644 --- a/modules/core/misc/objc/common/Point2f.h +++ b/modules/core/misc/objc/common/Point2f.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 diff --git a/modules/core/misc/objc/common/Point2i.h b/modules/core/misc/objc/common/Point2i.h index ac545d4ecc..9e5d74624a 100644 --- a/modules/core/misc/objc/common/Point2i.h +++ b/modules/core/misc/objc/common/Point2i.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 diff --git a/modules/core/misc/objc/common/Point3d.h b/modules/core/misc/objc/common/Point3d.h index 271fbb1bd0..31b5ab8608 100644 --- a/modules/core/misc/objc/common/Point3d.h +++ b/modules/core/misc/objc/common/Point3d.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 diff --git a/modules/core/misc/objc/common/Point3f.h b/modules/core/misc/objc/common/Point3f.h index 8f02aaeb4f..f667ff933d 100644 --- a/modules/core/misc/objc/common/Point3f.h +++ b/modules/core/misc/objc/common/Point3f.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 diff --git a/modules/core/misc/objc/common/Point3i.h b/modules/core/misc/objc/common/Point3i.h index 5323cb8029..832f68d7a8 100644 --- a/modules/core/misc/objc/common/Point3i.h +++ b/modules/core/misc/objc/common/Point3i.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 diff --git a/modules/core/misc/objc/common/Range.h b/modules/core/misc/objc/common/Range.h index ba0aa549e3..dd84edf6aa 100644 --- a/modules/core/misc/objc/common/Range.h +++ b/modules/core/misc/objc/common/Range.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 diff --git a/modules/core/misc/objc/common/Rect2d.h b/modules/core/misc/objc/common/Rect2d.h index c1d944247e..ba91509b77 100644 --- a/modules/core/misc/objc/common/Rect2d.h +++ b/modules/core/misc/objc/common/Rect2d.h @@ -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 diff --git a/modules/core/misc/objc/common/Rect2f.h b/modules/core/misc/objc/common/Rect2f.h index 9ed5f40981..6a8863800f 100644 --- a/modules/core/misc/objc/common/Rect2f.h +++ b/modules/core/misc/objc/common/Rect2f.h @@ -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 diff --git a/modules/core/misc/objc/common/Rect2i.h b/modules/core/misc/objc/common/Rect2i.h index a94a547226..2e4e55cf30 100644 --- a/modules/core/misc/objc/common/Rect2i.h +++ b/modules/core/misc/objc/common/Rect2i.h @@ -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 diff --git a/modules/core/misc/objc/common/RotatedRect.h b/modules/core/misc/objc/common/RotatedRect.h index 5571e739ee..c94053b6c1 100644 --- a/modules/core/misc/objc/common/RotatedRect.h +++ b/modules/core/misc/objc/common/RotatedRect.h @@ -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 diff --git a/modules/core/misc/objc/common/Scalar.h b/modules/core/misc/objc/common/Scalar.h index ebf54c48f6..63c3d1de58 100644 --- a/modules/core/misc/objc/common/Scalar.h +++ b/modules/core/misc/objc/common/Scalar.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -17,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN /** * Represents a four element vector */ -@interface Scalar : NSObject +CV_EXPORTS @interface Scalar : NSObject #pragma mark - Properties diff --git a/modules/core/misc/objc/common/Size2d.h b/modules/core/misc/objc/common/Size2d.h index 233f4c29ae..11c6c50a02 100644 --- a/modules/core/misc/objc/common/Size2d.h +++ b/modules/core/misc/objc/common/Size2d.h @@ -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 diff --git a/modules/core/misc/objc/common/Size2f.h b/modules/core/misc/objc/common/Size2f.h index 83f1bae016..2d1f2865c3 100644 --- a/modules/core/misc/objc/common/Size2f.h +++ b/modules/core/misc/objc/common/Size2f.h @@ -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 diff --git a/modules/core/misc/objc/common/Size2i.h b/modules/core/misc/objc/common/Size2i.h index 9a714da13e..61aa8da885 100644 --- a/modules/core/misc/objc/common/Size2i.h +++ b/modules/core/misc/objc/common/Size2i.h @@ -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 diff --git a/modules/core/misc/objc/common/TermCriteria.h b/modules/core/misc/objc/common/TermCriteria.h index 1e3055dd74..c7396582b2 100644 --- a/modules/core/misc/objc/common/TermCriteria.h +++ b/modules/core/misc/objc/common/TermCriteria.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -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 diff --git a/modules/imgcodecs/misc/objc/ios/Mat+Converters.h b/modules/imgcodecs/misc/objc/ios/Mat+Converters.h index 73dbe9cbc7..d33abbf4f9 100644 --- a/modules/imgcodecs/misc/objc/ios/Mat+Converters.h +++ b/modules/imgcodecs/misc/objc/ios/Mat+Converters.h @@ -8,6 +8,8 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import @@ -16,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface Mat (Converters) +CV_EXPORTS @interface Mat (Converters) -(UIImage*)toUIImage; -(instancetype)initWithUIImage:(UIImage*)image; diff --git a/modules/imgproc/misc/objc/common/Moments.h b/modules/imgproc/misc/objc/common/Moments.h index cf64625403..dfa5653bac 100644 --- a/modules/imgproc/misc/objc/common/Moments.h +++ b/modules/imgproc/misc/objc/common/Moments.h @@ -8,13 +8,15 @@ #ifdef __cplusplus #import "opencv.hpp" +#else +#define CV_EXPORTS #endif #import NS_ASSUME_NONNULL_BEGIN -@interface Moments : NSObject +CV_EXPORTS @interface Moments : NSObject @property double m00; @property double m10; diff --git a/modules/objc/generator/templates/cmakelists.template b/modules/objc/generator/templates/cmakelists.template index d6fab2cede..42acc276b7 100644 --- a/modules/objc/generator/templates/cmakelists.template +++ b/modules/objc/generator/templates/cmakelists.template @@ -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}") diff --git a/modules/objc/generator/templates/objc_class_header.template b/modules/objc/generator/templates/objc_class_header.template index fae6b48dd6..0bad670685 100644 --- a/modules/objc/generator/templates/objc_class_header.template +++ b/modules/objc/generator/templates/objc_class_header.template @@ -6,6 +6,8 @@ #ifdef __cplusplus #import "opencv.hpp" $additionalImports +#else +#define CV_EXPORTS #endif #import @@ -18,7 +20,7 @@ $enumDeclarations NS_ASSUME_NONNULL_BEGIN $docs -@interface $objcName : $base +CV_EXPORTS @interface $objcName : $base $nativePointerHandling diff --git a/modules/objc/generator/templates/objc_module_header.template b/modules/objc/generator/templates/objc_module_header.template index 9c7f14bdf1..fa9e7df6a3 100644 --- a/modules/objc/generator/templates/objc_module_header.template +++ b/modules/objc/generator/templates/objc_module_header.template @@ -6,6 +6,8 @@ #ifdef __cplusplus #import "opencv.hpp" $additionalImports +#else +#define CV_EXPORTS #endif #import @@ -17,7 +19,7 @@ $enumDeclarations NS_ASSUME_NONNULL_BEGIN $docs -@interface $module : $base +CV_EXPORTS @interface $module : $base $methodDeclarations diff --git a/modules/videoio/misc/objc/ios/CvCamera2.h b/modules/videoio/misc/objc/ios/CvCamera2.h index 0127116f86..e4ec03b3e0 100644 --- a/modules/videoio/misc/objc/ios/CvCamera2.h +++ b/modules/videoio/misc/objc/ios/CvCamera2.h @@ -8,12 +8,13 @@ #import #import #import +#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 +CV_EXPORTS @interface CvVideoCamera2 : CvAbstractCamera2 @property (nonatomic, weak) id delegate; @property (nonatomic, assign) BOOL grayscaleMode; @property (nonatomic, assign) BOOL recordVideo; @@ -78,7 +79,7 @@ - (void)photoCameraCancel:(CvPhotoCamera2*)photoCamera; @end -@interface CvPhotoCamera2 : CvAbstractCamera2 +CV_EXPORTS @interface CvPhotoCamera2 : CvAbstractCamera2 @property (nonatomic, weak) id delegate; - (void)takePicture; @end diff --git a/platforms/ios/Info.Dynamic.plist.in b/platforms/ios/Info.Dynamic.plist.in index 00c9277659..e48fffdb9d 100644 --- a/platforms/ios/Info.Dynamic.plist.in +++ b/platforms/ios/Info.Dynamic.plist.in @@ -5,7 +5,7 @@ CFBundleDevelopmentRegion en CFBundleExecutable - opencv2 + ${FRAMEWORK_NAME} CFBundleName ${OPENCV_APPLE_BUNDLE_NAME} CFBundleIdentifier diff --git a/platforms/ios/build_framework.py b/platforms/ios/build_framework.py index 58d6517320..c498a462fb 100755 --- a/platforms/ios/build_framework.py +++ b/platforms/ios/build_framework.py @@ -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)