"objc_type": "Point2i*",
"to_cpp": "%(n)s.nativeRef",
"from_cpp": "[Point2i fromNative:%(n)s]",
- "swift_type": "Point"
+ "swift_type": "Point2i"
},
"Point2i": {
"objc_type": "Point2i*",
"to_cpp": "%(n)s.nativeRef",
"from_cpp": "[Point2i fromNative:%(n)s]",
- "swift_type": "Point"
+ "swift_type": "Point2i"
},
"Point2f": {
"objc_type": "Point2f*",
"objc_type": "Rect2i*",
"to_cpp": "%(n)s.nativeRef",
"from_cpp": "[Rect2i fromNative:%(n)s]",
- "swift_type": "Rect"
+ "swift_type": "Rect2i"
},
"Rect2i": {
"objc_type": "Rect2i*",
"to_cpp": "%(n)s.nativeRef",
"from_cpp": "[Rect2i fromNative:%(n)s]",
- "swift_type": "Rect"
+ "swift_type": "Rect2i"
},
"Rect2f": {
"objc_type": "Rect2f*",
"objc_type": "Size2i*",
"to_cpp": "%(n)s.nativeRef",
"from_cpp": "[Size2i fromNative:%(n)s]",
- "swift_type": "Size"
+ "swift_type": "Size2i"
},
"Size2i": {
"objc_type": "Size2i*",
"to_cpp": "%(n)s.nativeRef",
"from_cpp": "[Size2i fromNative:%(n)s]",
- "swift_type": "Size"
+ "swift_type": "Size2i"
},
"Size2f": {
"objc_type": "Size2f*",
"vector_Point": {
"objc_type": "Point2i*",
"v_type": "Point2i",
- "swift_type": "[Point]"
+ "swift_type": "[Point2i]"
},
"vector_Point2f": {
"objc_type": "Point2f*",
"vector_Rect": {
"objc_type": "Rect2i*",
"v_type": "Rect2i",
- "swift_type": "[Rect]"
+ "swift_type": "[Rect2i]"
},
"vector_Rect2d": {
"objc_type": "Rect2d*",
"vector_vector_Point": {
"objc_type": "Point2i*",
"v_v_type": "Point2i",
- "swift_type": "[[Point]]"
+ "swift_type": "[[Point2i]]"
},
"vector_vector_Point2f": {
"objc_type": "Point2f*",
"""
from __future__ import print_function, unicode_literals
-import glob, os, os.path, shutil, string, sys, argparse, traceback, multiprocessing
+import glob, os, os.path, shutil, string, sys, argparse, traceback, multiprocessing, codecs, io
from subprocess import check_call, check_output, CalledProcessError
from distutils.dir_util import copy_tree
IPHONEOS_DEPLOYMENT_TARGET='9.0' # default, can be changed via command line options or environment variable
class Builder:
- def __init__(self, opencv, contrib, dynamic, bitcodedisabled, exclude, disable, enablenonfree, targets, debug, debug_info, framework_name, run_tests, build_docs):
+ def __init__(self, opencv, contrib, dynamic, bitcodedisabled, exclude, disable, enablenonfree, targets, debug, debug_info, framework_name, run_tests, build_docs, swiftdisabled):
self.opencv = os.path.abspath(opencv)
self.contrib = None
if contrib:
self.framework_name = framework_name
self.run_tests = run_tests
self.build_docs = build_docs
+ self.swiftdisabled = swiftdisabled
def checkCMakeVersion(self):
if get_xcode_version() >= (12, 2):
print("To build docs call:")
print(sys.argv[0].replace("build_framework", "build_docs") + " " + dirs[0] + "/modules/objc/framework_build")
self.copy_samples(outdir)
+ if self.swiftdisabled:
+ swift_sources_dir = os.path.join(outdir, "SwiftSources")
+ if not os.path.exists(swift_sources_dir):
+ os.makedirs(swift_sources_dir)
+ for root, dirs, files in os.walk(dirs[0]):
+ for file in files:
+ if file.endswith(".swift") and file.find("Test") == -1:
+ with io.open(os.path.join(root, file), encoding="utf-8", errors="ignore") as file_in:
+ body = file_in.read()
+ if body.find("import Foundation") != -1:
+ insert_pos = body.find("import Foundation") + len("import Foundation") + 1
+ body = body[:insert_pos] + "import " + self.framework_name + "\n" + body[insert_pos:]
+ else:
+ body = "import " + self.framework_name + "\n\n" + body
+ with codecs.open(os.path.join(swift_sources_dir, file), "w", "utf-8") as file_out:
+ file_out.write(body)
def build(self, outdir):
try:
execute(["cmake", "-DBUILD_TYPE=%s" % self.getConfiguration(), "-P", "cmake_install.cmake"], cwd = builddir)
if self.build_objc_wrapper:
cmakecmd = self.makeCMakeCmd(arch, target, builddir + "/modules/objc_bindings_generator/{}/gen".format(self.getObjcTarget(target)), cmakeargs)
- # cmakecmd.append("-DCMAKE_Swift_FLAGS=" + "-target x86_64-apple-ios13.0-macabi")
- # cmakecmd.append("-DCMAKE_EXE_LINKER_FLAGS=" + "-target x86_64-apple-ios13.0-macabi")
+ if self.swiftdisabled:
+ cmakecmd.append("-DSWIFT_DISABLED=1")
cmakecmd.append("-DBUILD_ROOT=%s" % builddir)
cmakecmd.append("-DCMAKE_INSTALL_NAME_TOOL=install_name_tool")
cmakecmd.append("--no-warn-unused-cli")
parser.add_argument('--legacy_build', default=False, dest='legacy_build', action='store_true', help='Build legacy opencv2 framework (default: False, equivalent to "--framework_name=opencv2 --without=objc")')
parser.add_argument('--run_tests', default=False, dest='run_tests', action='store_true', help='Run tests')
parser.add_argument('--build_docs', default=False, dest='build_docs', action='store_true', help='Build docs')
+ parser.add_argument('--disable-swift', default=False, dest='swiftdisabled', action='store_true', help='Disable building of Swift extensions')
args, unknown_args = parser.parse_known_args()
if unknown_args:
if iphonesimulator_archs:
targets.append((iphonesimulator_archs, "iPhoneSimulator"))
- b = iOSBuilder(args.opencv, args.contrib, args.dynamic, args.bitcodedisabled, args.without, args.disable, args.enablenonfree, targets, args.debug, args.debug_info, args.framework_name, args.run_tests, args.build_docs)
+ b = iOSBuilder(args.opencv, args.contrib, args.dynamic, args.bitcodedisabled, args.without, args.disable, args.enablenonfree, targets, args.debug, args.debug_info, args.framework_name, args.run_tests, args.build_docs, args.swiftdisabled)
b.build(args.out)
parser.add_argument('--legacy_build', default=False, dest='legacy_build', action='store_true', help='Build legacy framework (default: False, equivalent to "--framework_name=opencv2 --without=objc")')
parser.add_argument('--run_tests', default=False, dest='run_tests', action='store_true', help='Run tests')
parser.add_argument('--build_docs', default=False, dest='build_docs', action='store_true', help='Build docs')
+ parser.add_argument('--disable-swift', default=False, dest='swiftdisabled', action='store_true', help='Disable building of Swift extensions')
args, unknown_args = parser.parse_known_args()
if unknown_args:
if catalyst_archs:
targets.append((catalyst_archs, "Catalyst")),
- b = OSXBuilder(args.opencv, args.contrib, args.dynamic, True, args.without, args.disable, args.enablenonfree, targets, args.debug, args.debug_info, args.framework_name, args.run_tests, args.build_docs)
+ b = OSXBuilder(args.opencv, args.contrib, args.dynamic, True, args.without, args.disable, args.enablenonfree, targets, args.debug, args.debug_info, args.framework_name, args.run_tests, args.build_docs, args.swiftdisabled)
b.build(args.out)