2014-07-02 03:31:57 +08:00
#!/usr/bin/env python
"""
2015-12-16 22:28:03 +08:00
The script builds OpenCV . framework for OSX .
2014-07-02 03:31:57 +08:00
"""
2015-12-16 22:28:03 +08:00
from __future__ import print_function
2017-05-02 23:48:54 +08:00
import os , os . path , sys , argparse , traceback , multiprocessing
2014-07-02 03:31:57 +08:00
2015-12-16 22:28:03 +08:00
# import common code
sys . path . insert ( 0 , os . path . abspath ( os . path . abspath ( os . path . dirname ( __file__ ) ) + ' /../ios ' ) )
from build_framework import Builder
2014-07-02 03:31:57 +08:00
2019-08-23 23:22:29 +08:00
MACOSX_DEPLOYMENT_TARGET = ' 10.12 ' # default, can be changed via command line options or environment variable
2015-12-16 22:28:03 +08:00
class OSXBuilder ( Builder ) :
2014-07-02 03:31:57 +08:00
2020-11-14 15:16:13 +08:00
def getObjcTarget ( self ) :
# Obj-C generation target
return ' osx '
2015-12-16 22:28:03 +08:00
def getToolchain ( self , arch , target ) :
return None
2014-07-02 03:31:57 +08:00
2020-08-30 06:41:54 +08:00
def getBuildCommand ( self , arch , target ) :
2015-12-16 22:28:03 +08:00
buildcmd = [
" xcodebuild " ,
2019-08-23 23:22:29 +08:00
" MACOSX_DEPLOYMENT_TARGET= " + os . environ [ ' MACOSX_DEPLOYMENT_TARGET ' ] ,
2020-08-30 06:41:54 +08:00
" ARCHS= %s " % arch ,
2015-12-16 22:28:03 +08:00
" -sdk " , target . lower ( ) ,
2019-08-23 23:22:29 +08:00
" -configuration " , " Debug " if self . debug else " Release " ,
2015-12-16 22:28:03 +08:00
" -parallelizeTargets " ,
2017-05-02 23:59:37 +08:00
" -jobs " , str ( multiprocessing . cpu_count ( ) )
2015-12-16 22:28:03 +08:00
]
return buildcmd
2014-07-02 03:31:57 +08:00
2015-12-16 22:28:03 +08:00
def getInfoPlist ( self , builddirs ) :
return os . path . join ( builddirs [ 0 ] , " osx " , " Info.plist " )
2014-07-02 03:31:57 +08:00
if __name__ == " __main__ " :
2015-12-16 22:28:03 +08:00
folder = os . path . abspath ( os . path . join ( os . path . dirname ( sys . argv [ 0 ] ) , " ../.. " ) )
parser = argparse . ArgumentParser ( description = ' The script builds OpenCV.framework for OSX. ' )
parser . add_argument ( ' out ' , metavar = ' OUTDIR ' , help = ' folder to put built framework ' )
parser . add_argument ( ' --opencv ' , metavar = ' DIR ' , default = folder , help = ' folder with opencv repository (default is " ../.. " relative to script location) ' )
parser . add_argument ( ' --contrib ' , metavar = ' DIR ' , default = None , help = ' folder with opencv_contrib repository (default is " None " - build only main framework) ' )
2016-09-29 05:32:23 +08:00
parser . add_argument ( ' --without ' , metavar = ' MODULE ' , default = [ ] , action = ' append ' , help = ' OpenCV modules to exclude from the framework ' )
2019-11-13 07:30:30 +08:00
parser . add_argument ( ' --disable ' , metavar = ' FEATURE ' , default = [ ] , action = ' append ' , help = ' OpenCV features to disable (add WITH_*=OFF) ' )
2018-12-12 22:32:19 +08:00
parser . add_argument ( ' --enable_nonfree ' , default = False , dest = ' enablenonfree ' , action = ' store_true ' , help = ' enable non-free modules (disabled by default) ' )
2019-08-23 23:22:29 +08:00
parser . add_argument ( ' --macosx_deployment_target ' , default = os . environ . get ( ' MACOSX_DEPLOYMENT_TARGET ' , MACOSX_DEPLOYMENT_TARGET ) , help = ' specify MACOSX_DEPLOYMENT_TARGET ' )
2020-08-30 06:41:54 +08:00
parser . add_argument ( ' --archs ' , default = ' x86_64 ' , help = ' Select target ARCHS (set to " x86_64,arm64 " to build Universal Binary for Big Sur and later) ' )
2019-08-23 23:22:29 +08:00
parser . add_argument ( ' --debug ' , action = ' store_true ' , help = ' Build " Debug " binaries (CMAKE_BUILD_TYPE=Debug) ' )
parser . add_argument ( ' --debug_info ' , action = ' store_true ' , help = ' Build with debug information (useful for Release mode: BUILD_WITH_DEBUG_INFO=ON) ' )
2020-06-09 02:32:53 +08:00
parser . add_argument ( ' --framework_name ' , default = ' opencv2 ' , dest = ' framework_name ' , action = ' store_true ' , help = ' Name of OpenCV framework (default: opencv2, will change to OpenCV in future version) ' )
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 " ) ' )
2020-08-09 15:39:24 +08:00
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 ' )
2019-08-23 23:22:29 +08:00
2015-12-16 22:28:03 +08:00
args = parser . parse_args ( )
2019-08-23 23:22:29 +08:00
os . environ [ ' MACOSX_DEPLOYMENT_TARGET ' ] = args . macosx_deployment_target
print ( ' Using MACOSX_DEPLOYMENT_TARGET= ' + os . environ [ ' MACOSX_DEPLOYMENT_TARGET ' ] )
2020-08-30 06:41:54 +08:00
archs = args . archs . split ( ' , ' )
print ( ' Using ARCHS= ' + str ( archs ) )
2020-06-09 02:32:53 +08:00
if args . legacy_build :
args . framework_name = " opencv2 "
if not " objc " in args . without :
args . without . append ( " objc " )
2019-08-23 23:22:29 +08:00
2019-11-13 07:30:30 +08:00
b = OSXBuilder ( args . opencv , args . contrib , False , False , args . without , args . disable , args . enablenonfree ,
2015-12-16 22:28:03 +08:00
[
2020-08-30 06:41:54 +08:00
( archs , " MacOSX " )
2020-08-09 15:39:24 +08:00
] , args . debug , args . debug_info , args . framework_name , args . run_tests , args . build_docs )
2015-12-16 22:28:03 +08:00
b . build ( args . out )