diff --git a/platforms/ios/build_framework.py b/platforms/ios/build_framework.py index 37c8fc046c..a863f41e34 100755 --- a/platforms/ios/build_framework.py +++ b/platforms/ios/build_framework.py @@ -49,7 +49,7 @@ def getXCodeMajor(): raise Exception("Failed to parse Xcode version") class Builder: - def __init__(self, opencv, contrib, dynamic, bitcodedisabled, exclude, enablenonfree, targets): + def __init__(self, opencv, contrib, dynamic, bitcodedisabled, exclude, enablenonfree, targets, debug, debug_info): self.opencv = os.path.abspath(opencv) self.contrib = None if contrib: @@ -63,6 +63,8 @@ class Builder: self.exclude = exclude self.enablenonfree = enablenonfree self.targets = targets + self.debug = debug + self.debug_info = debug_info def getBD(self, parent, t): @@ -125,6 +127,9 @@ class Builder: def getToolchain(self, arch, target): return None + def getConfiguration(self): + return "Debug" if self.debug else "Release" + def getCMakeArgs(self, arch, target): args = [ @@ -132,14 +137,16 @@ class Builder: "-GXcode", "-DAPPLE_FRAMEWORK=ON", "-DCMAKE_INSTALL_PREFIX=install", - "-DCMAKE_BUILD_TYPE=Release", + "-DCMAKE_BUILD_TYPE=%s" % self.getConfiguration(), ] + ([ "-DBUILD_SHARED_LIBS=ON", "-DCMAKE_MACOSX_BUNDLE=ON", "-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=NO", ] if self.dynamic else []) + ([ "-DOPENCV_ENABLE_NONFREE=ON" - ] if self.enablenonfree else []) + ] if self.enablenonfree else []) + ([ + "-DBUILD_WITH_DEBUG_INFO=ON" + ] if self.debug_info else []) if len(self.exclude) > 0: args += ["-DBUILD_opencv_world=OFF"] if not self.dynamic else [] @@ -174,7 +181,7 @@ class Builder: buildcmd += [ "-sdk", target.lower(), - "-configuration", "Release", + "-configuration", self.getConfiguration(), "-parallelizeTargets", "-jobs", str(multiprocessing.cpu_count()), ] + (["-target","ALL_BUILD"] if self.dynamic else []) @@ -201,10 +208,10 @@ class Builder: shutil.rmtree(clean_dir) buildcmd = self.getBuildCommand(arch, target) execute(buildcmd + ["-target", "ALL_BUILD", "build"], cwd = builddir) - execute(["cmake", "-P", "cmake_install.cmake"], cwd = builddir) + execute(["cmake", "-DBUILD_TYPE=%s" % self.getConfiguration(), "-P", "cmake_install.cmake"], cwd = builddir) def mergeLibs(self, builddir): - res = os.path.join(builddir, "lib", "Release", "libopencv_merged.a") + res = os.path.join(builddir, "lib", self.getConfiguration(), "libopencv_merged.a") libs = glob.glob(os.path.join(builddir, "install", "lib", "*.a")) libs3 = glob.glob(os.path.join(builddir, "install", "share", "OpenCV", "3rdparty", "lib", "*.a")) print("Merging libraries:\n\t%s" % "\n\t".join(libs + libs3), file=sys.stderr) @@ -230,7 +237,7 @@ class Builder: shutil.copytree(os.path.join(builddirs[0], "install", "include", "opencv2"), os.path.join(dstdir, "Headers")) # make universal static lib - libs = [os.path.join(d, "lib", "Release", libname) for d in builddirs] + libs = [os.path.join(d, "lib", self.getConfiguration(), libname) for d in builddirs] lipocmd = ["lipo", "-create"] lipocmd.extend(libs) lipocmd.extend(["-o", os.path.join(dstdir, name)]) @@ -288,6 +295,8 @@ if __name__ == "__main__": parser.add_argument('--iphoneos_archs', default='armv7,armv7s,arm64', help='select iPhoneOS target ARCHS') parser.add_argument('--iphonesimulator_archs', default='i386,x86_64', help='select iPhoneSimulator target ARCHS') parser.add_argument('--enable_nonfree', default=False, dest='enablenonfree', action='store_true', help='enable non-free modules (disabled by default)') + parser.add_argument('--debug', default=False, dest='debug', action='store_true', help='Build "Debug" binaries (disabled by default)') + parser.add_argument('--debug_info', default=False, dest='debug_info', action='store_true', help='Build with debug information (useful for Release mode: BUILD_WITH_DEBUG_INFO=ON)') args = parser.parse_args() os.environ['IPHONEOS_DEPLOYMENT_TARGET'] = args.iphoneos_deployment_target @@ -304,5 +313,5 @@ if __name__ == "__main__": [ (iphoneos_archs, "iPhoneOS"), (iphonesimulator_archs, "iPhoneSimulator"), - ]) + ], args.debug, args.debug_info) b.build(args.out) diff --git a/platforms/osx/build_framework.py b/platforms/osx/build_framework.py old mode 100644 new mode 100755 index 2425fa158a..5897192108 --- a/platforms/osx/build_framework.py +++ b/platforms/osx/build_framework.py @@ -10,6 +10,8 @@ import os, os.path, sys, argparse, traceback, multiprocessing sys.path.insert(0, os.path.abspath(os.path.abspath(os.path.dirname(__file__))+'/../ios')) from build_framework import Builder +MACOSX_DEPLOYMENT_TARGET='10.12' # default, can be changed via command line options or environment variable + class OSXBuilder(Builder): def getToolchain(self, arch, target): @@ -18,10 +20,10 @@ class OSXBuilder(Builder): def getBuildCommand(self, archs, target): buildcmd = [ "xcodebuild", - "MACOSX_DEPLOYMENT_TARGET=10.9", + "MACOSX_DEPLOYMENT_TARGET=" + os.environ['MACOSX_DEPLOYMENT_TARGET'], "ARCHS=%s" % archs[0], "-sdk", target.lower(), - "-configuration", "Release", + "-configuration", "Debug" if self.debug else "Release", "-parallelizeTargets", "-jobs", str(multiprocessing.cpu_count()) ] @@ -39,10 +41,17 @@ if __name__ == "__main__": parser.add_argument('--contrib', metavar='DIR', default=None, help='folder with opencv_contrib repository (default is "None" - build only main framework)') parser.add_argument('--without', metavar='MODULE', default=[], action='append', help='OpenCV modules to exclude from the framework') 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('--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)') + args = parser.parse_args() + os.environ['MACOSX_DEPLOYMENT_TARGET'] = args.macosx_deployment_target + print('Using MACOSX_DEPLOYMENT_TARGET=' + os.environ['MACOSX_DEPLOYMENT_TARGET']) + b = OSXBuilder(args.opencv, args.contrib, False, False, args.without, args.enablenonfree, [ (["x86_64"], "MacOSX") - ]) + ], args.debug, args.debug_info) b.build(args.out)