@ -32,7 +32,7 @@ Adding --dynamic parameter will build {framework_name}.framework as App Store dy
"""
"""
from __future__ import print_function , unicode_literals
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 subprocess import check_call , check_output , CalledProcessError
from distutils . dir_util import copy_tree
from distutils . dir_util import copy_tree
@ -42,7 +42,7 @@ from cv_build_utils import execute, print_error, get_xcode_major, get_xcode_sett
IPHONEOS_DEPLOYMENT_TARGET = ' 9.0 ' # default, can be changed via command line options or environment variable
IPHONEOS_DEPLOYMENT_TARGET = ' 9.0 ' # default, can be changed via command line options or environment variable
class Builder :
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 . opencv = os . path . abspath ( opencv )
self . contrib = None
self . contrib = None
if contrib :
if contrib :
@ -63,6 +63,7 @@ class Builder:
self . framework_name = framework_name
self . framework_name = framework_name
self . run_tests = run_tests
self . run_tests = run_tests
self . build_docs = build_docs
self . build_docs = build_docs
self . swiftdisabled = swiftdisabled
def checkCMakeVersion ( self ) :
def checkCMakeVersion ( self ) :
if get_xcode_version ( ) > = ( 12 , 2 ) :
if get_xcode_version ( ) > = ( 12 , 2 ) :
@ -153,6 +154,22 @@ class Builder:
print ( " To build docs call: " )
print ( " To build docs call: " )
print ( sys . argv [ 0 ] . replace ( " build_framework " , " build_docs " ) + " " + dirs [ 0 ] + " /modules/objc/framework_build " )
print ( sys . argv [ 0 ] . replace ( " build_framework " , " build_docs " ) + " " + dirs [ 0 ] + " /modules/objc/framework_build " )
self . copy_samples ( outdir )
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 ) :
def build ( self , outdir ) :
try :
try :
@ -297,8 +314,8 @@ class Builder:
execute ( [ " cmake " , " -DBUILD_TYPE= %s " % self . getConfiguration ( ) , " -P " , " cmake_install.cmake " ] , cwd = builddir )
execute ( [ " cmake " , " -DBUILD_TYPE= %s " % self . getConfiguration ( ) , " -P " , " cmake_install.cmake " ] , cwd = builddir )
if self . build_objc_wrapper :
if self . build_objc_wrapper :
cmakecmd = self . makeCMakeCmd ( arch , target , builddir + " /modules/objc_bindings_generator/ {} /gen " . format ( self . getObjcTarget ( target ) ) , cmakeargs )
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")
if self . swiftdisabled :
# cmakecmd.append("-DCMAKE_EXE_LINKER_FLAGS=" + "-target x86_64-apple-ios13.0-macabi" )
cmakecmd . append ( " -DSWIFT_DISABLED=1 " )
cmakecmd . append ( " -DBUILD_ROOT= %s " % builddir )
cmakecmd . append ( " -DBUILD_ROOT= %s " % builddir )
cmakecmd . append ( " -DCMAKE_INSTALL_NAME_TOOL=install_name_tool " )
cmakecmd . append ( " -DCMAKE_INSTALL_NAME_TOOL=install_name_tool " )
cmakecmd . append ( " --no-warn-unused-cli " )
cmakecmd . append ( " --no-warn-unused-cli " )
@ -509,6 +526,7 @@ if __name__ == "__main__":
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 ( ' --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 ( ' --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 ( ' --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 ( )
args , unknown_args = parser . parse_known_args ( )
if unknown_args :
if unknown_args :
@ -562,6 +580,6 @@ if __name__ == "__main__":
if iphonesimulator_archs :
if iphonesimulator_archs :
targets . append ( ( iphonesimulator_archs , " iPhoneSimulator " ) )
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 )
b . build ( args . out )