Skip to content

Commit

Permalink
Universal Build for Big Sur (3rd attempt)
Browse files Browse the repository at this point in the history
  • Loading branch information
komakai committed Aug 13, 2020
1 parent 949fe93 commit e2c9156
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 14 additions & 3 deletions platforms/ios/build_framework.py
Expand Up @@ -235,12 +235,22 @@ def getBuildCommand(self, archs, target):
def getInfoPlist(self, builddirs):
return os.path.join(builddirs[0], "ios", "Info.plist")

def makeCMakeCmd(self, arch, target, dir, cmakeargs = []):
toolchain = self.getToolchain(arch, target)
cmakecmd = self.getCMakeArgs(arch, target) + \
def makeCMakeCmd(self, archs, target, dir, cmakeargs = []):
toolchain = self.getToolchain(archs, target)
cmakecmd = self.getCMakeArgs(archs, target) + \
(["-DCMAKE_TOOLCHAIN_FILE=%s" % toolchain] if toolchain is not None else [])
if target.lower().startswith("iphoneos"):
cmakecmd.append("-DCPU_BASELINE=DETECT")
arch = archs[0]
if target.lower() == "macosx":
current_arch = check_output(["uname", "-m"]).rstrip()
if current_arch != arch:
cmakecmd.append("-DCMAKE_SYSTEM_PROCESSOR=" + arch)
cmakecmd.append("-DCMAKE_OSX_ARCHITECTURES=" + arch)
cmakecmd.append("-DCPU_BASELINE=DETECT")
if arch != "x86_64":
cmakecmd.append("-DWITH_IPP=OFF")

cmakecmd.append(dir)
cmakecmd.extend(cmakeargs)
return cmakecmd
Expand Down Expand Up @@ -344,6 +354,7 @@ def makeFramework(self, outdir, builddirs):
"x86_64": "x86_64-apple-ios-simulator",
} if builddirs[0].find("iphone") != -1 else {
"x86_64": "x86_64-apple-macos",
"arm64": "arm64-apple-macos",
}
for d in builddirs:
copy_tree(os.path.join(d, "install", "lib", name + ".framework", "Modules"), os.path.join(dstdir, "Modules"))
Expand Down
6 changes: 5 additions & 1 deletion platforms/osx/build_framework.py
Expand Up @@ -43,6 +43,7 @@ def getInfoPlist(self, builddirs):
parser.add_argument('--disable', metavar='FEATURE', default=[], action='append', help='OpenCV features to disable (add WITH_*=OFF)')
parser.add_argument('--enable_nonfree', default=False, dest='enablenonfree', action='store_true', help='enable non-free modules (disabled by default)')
parser.add_argument('--macosx_deployment_target', default=os.environ.get('MACOSX_DEPLOYMENT_TARGET', MACOSX_DEPLOYMENT_TARGET), help='specify MACOSX_DEPLOYMENT_TARGET')
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)')
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)')
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)')
Expand All @@ -54,13 +55,16 @@ def getInfoPlist(self, builddirs):

os.environ['MACOSX_DEPLOYMENT_TARGET'] = args.macosx_deployment_target
print('Using MACOSX_DEPLOYMENT_TARGET=' + os.environ['MACOSX_DEPLOYMENT_TARGET'])
archs = args.archs.split(',')
print('Using ARCHS=' + str(archs))

if args.legacy_build:
args.framework_name = "opencv2"
if not "objc" in args.without:
args.without.append("objc")

b = OSXBuilder(args.opencv, args.contrib, False, False, args.without, args.disable, args.enablenonfree,
[
(["x86_64"], "MacOSX")
(archs, "MacOSX")
], args.debug, args.debug_info, args.framework_name, args.run_tests, args.build_docs)
b.build(args.out)

0 comments on commit e2c9156

Please sign in to comment.