mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
Merge pull request #15350 from komakai:apple-debug-build
* Add debug build option to MacOs and iOS build scripts * osx: allow selection of MACOSX_DEPLOYMENT_TARGET * Add --debug_info flag to iOS and macOS builds for building with debug info
This commit is contained in:
parent
6bf6d1dc6b
commit
96d5cbd036
@ -49,7 +49,7 @@ def getXCodeMajor():
|
|||||||
raise Exception("Failed to parse Xcode version")
|
raise Exception("Failed to parse Xcode version")
|
||||||
|
|
||||||
class Builder:
|
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.opencv = os.path.abspath(opencv)
|
||||||
self.contrib = None
|
self.contrib = None
|
||||||
if contrib:
|
if contrib:
|
||||||
@ -63,6 +63,8 @@ class Builder:
|
|||||||
self.exclude = exclude
|
self.exclude = exclude
|
||||||
self.enablenonfree = enablenonfree
|
self.enablenonfree = enablenonfree
|
||||||
self.targets = targets
|
self.targets = targets
|
||||||
|
self.debug = debug
|
||||||
|
self.debug_info = debug_info
|
||||||
|
|
||||||
def getBD(self, parent, t):
|
def getBD(self, parent, t):
|
||||||
|
|
||||||
@ -125,6 +127,9 @@ class Builder:
|
|||||||
def getToolchain(self, arch, target):
|
def getToolchain(self, arch, target):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def getConfiguration(self):
|
||||||
|
return "Debug" if self.debug else "Release"
|
||||||
|
|
||||||
def getCMakeArgs(self, arch, target):
|
def getCMakeArgs(self, arch, target):
|
||||||
|
|
||||||
args = [
|
args = [
|
||||||
@ -132,14 +137,16 @@ class Builder:
|
|||||||
"-GXcode",
|
"-GXcode",
|
||||||
"-DAPPLE_FRAMEWORK=ON",
|
"-DAPPLE_FRAMEWORK=ON",
|
||||||
"-DCMAKE_INSTALL_PREFIX=install",
|
"-DCMAKE_INSTALL_PREFIX=install",
|
||||||
"-DCMAKE_BUILD_TYPE=Release",
|
"-DCMAKE_BUILD_TYPE=%s" % self.getConfiguration(),
|
||||||
] + ([
|
] + ([
|
||||||
"-DBUILD_SHARED_LIBS=ON",
|
"-DBUILD_SHARED_LIBS=ON",
|
||||||
"-DCMAKE_MACOSX_BUNDLE=ON",
|
"-DCMAKE_MACOSX_BUNDLE=ON",
|
||||||
"-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=NO",
|
"-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=NO",
|
||||||
] if self.dynamic else []) + ([
|
] if self.dynamic else []) + ([
|
||||||
"-DOPENCV_ENABLE_NONFREE=ON"
|
"-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:
|
if len(self.exclude) > 0:
|
||||||
args += ["-DBUILD_opencv_world=OFF"] if not self.dynamic else []
|
args += ["-DBUILD_opencv_world=OFF"] if not self.dynamic else []
|
||||||
@ -174,7 +181,7 @@ class Builder:
|
|||||||
|
|
||||||
buildcmd += [
|
buildcmd += [
|
||||||
"-sdk", target.lower(),
|
"-sdk", target.lower(),
|
||||||
"-configuration", "Release",
|
"-configuration", self.getConfiguration(),
|
||||||
"-parallelizeTargets",
|
"-parallelizeTargets",
|
||||||
"-jobs", str(multiprocessing.cpu_count()),
|
"-jobs", str(multiprocessing.cpu_count()),
|
||||||
] + (["-target","ALL_BUILD"] if self.dynamic else [])
|
] + (["-target","ALL_BUILD"] if self.dynamic else [])
|
||||||
@ -201,10 +208,10 @@ class Builder:
|
|||||||
shutil.rmtree(clean_dir)
|
shutil.rmtree(clean_dir)
|
||||||
buildcmd = self.getBuildCommand(arch, target)
|
buildcmd = self.getBuildCommand(arch, target)
|
||||||
execute(buildcmd + ["-target", "ALL_BUILD", "build"], cwd = builddir)
|
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):
|
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"))
|
libs = glob.glob(os.path.join(builddir, "install", "lib", "*.a"))
|
||||||
libs3 = glob.glob(os.path.join(builddir, "install", "share", "OpenCV", "3rdparty", "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)
|
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"))
|
shutil.copytree(os.path.join(builddirs[0], "install", "include", "opencv2"), os.path.join(dstdir, "Headers"))
|
||||||
|
|
||||||
# make universal static lib
|
# 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 = ["lipo", "-create"]
|
||||||
lipocmd.extend(libs)
|
lipocmd.extend(libs)
|
||||||
lipocmd.extend(["-o", os.path.join(dstdir, name)])
|
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('--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('--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('--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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
os.environ['IPHONEOS_DEPLOYMENT_TARGET'] = args.iphoneos_deployment_target
|
os.environ['IPHONEOS_DEPLOYMENT_TARGET'] = args.iphoneos_deployment_target
|
||||||
@ -304,5 +313,5 @@ if __name__ == "__main__":
|
|||||||
[
|
[
|
||||||
(iphoneos_archs, "iPhoneOS"),
|
(iphoneos_archs, "iPhoneOS"),
|
||||||
(iphonesimulator_archs, "iPhoneSimulator"),
|
(iphonesimulator_archs, "iPhoneSimulator"),
|
||||||
])
|
], args.debug, args.debug_info)
|
||||||
b.build(args.out)
|
b.build(args.out)
|
||||||
|
15
platforms/osx/build_framework.py
Normal file → Executable file
15
platforms/osx/build_framework.py
Normal file → Executable file
@ -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'))
|
sys.path.insert(0, os.path.abspath(os.path.abspath(os.path.dirname(__file__))+'/../ios'))
|
||||||
from build_framework import Builder
|
from build_framework import Builder
|
||||||
|
|
||||||
|
MACOSX_DEPLOYMENT_TARGET='10.12' # default, can be changed via command line options or environment variable
|
||||||
|
|
||||||
class OSXBuilder(Builder):
|
class OSXBuilder(Builder):
|
||||||
|
|
||||||
def getToolchain(self, arch, target):
|
def getToolchain(self, arch, target):
|
||||||
@ -18,10 +20,10 @@ class OSXBuilder(Builder):
|
|||||||
def getBuildCommand(self, archs, target):
|
def getBuildCommand(self, archs, target):
|
||||||
buildcmd = [
|
buildcmd = [
|
||||||
"xcodebuild",
|
"xcodebuild",
|
||||||
"MACOSX_DEPLOYMENT_TARGET=10.9",
|
"MACOSX_DEPLOYMENT_TARGET=" + os.environ['MACOSX_DEPLOYMENT_TARGET'],
|
||||||
"ARCHS=%s" % archs[0],
|
"ARCHS=%s" % archs[0],
|
||||||
"-sdk", target.lower(),
|
"-sdk", target.lower(),
|
||||||
"-configuration", "Release",
|
"-configuration", "Debug" if self.debug else "Release",
|
||||||
"-parallelizeTargets",
|
"-parallelizeTargets",
|
||||||
"-jobs", str(multiprocessing.cpu_count())
|
"-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('--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('--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('--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()
|
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,
|
b = OSXBuilder(args.opencv, args.contrib, False, False, args.without, args.enablenonfree,
|
||||||
[
|
[
|
||||||
(["x86_64"], "MacOSX")
|
(["x86_64"], "MacOSX")
|
||||||
])
|
], args.debug, args.debug_info)
|
||||||
b.build(args.out)
|
b.build(args.out)
|
||||||
|
Loading…
Reference in New Issue
Block a user