Skip to content

Commit

Permalink
Merge pull request opencv#15350 from komakai:apple-debug-build
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
komakai authored and alalek committed Aug 23, 2019
1 parent 6bf6d1d commit 96d5cbd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
25 changes: 17 additions & 8 deletions platforms/ios/build_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -63,6 +63,8 @@ def __init__(self, opencv, contrib, dynamic, bitcodedisabled, exclude, enablenon
self.exclude = exclude
self.enablenonfree = enablenonfree
self.targets = targets
self.debug = debug
self.debug_info = debug_info

def getBD(self, parent, t):

Expand Down Expand Up @@ -125,21 +127,26 @@ def build(self, outdir):
def getToolchain(self, arch, target):
return None

def getConfiguration(self):
return "Debug" if self.debug else "Release"

def getCMakeArgs(self, arch, target):

args = [
"cmake",
"-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 []
Expand Down Expand Up @@ -174,7 +181,7 @@ def getBuildCommand(self, archs, target):

buildcmd += [
"-sdk", target.lower(),
"-configuration", "Release",
"-configuration", self.getConfiguration(),
"-parallelizeTargets",
"-jobs", str(multiprocessing.cpu_count()),
] + (["-target","ALL_BUILD"] if self.dynamic else [])
Expand All @@ -201,10 +208,10 @@ def buildOne(self, arch, target, builddir, cmakeargs = []):
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)
Expand All @@ -230,7 +237,7 @@ def makeFramework(self, outdir, builddirs):
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)])
Expand Down Expand Up @@ -288,6 +295,8 @@ def getCMakeArgs(self, arch, target):
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
Expand All @@ -304,5 +313,5 @@ def getCMakeArgs(self, arch, target):
[
(iphoneos_archs, "iPhoneOS"),
(iphonesimulator_archs, "iPhoneSimulator"),
])
], args.debug, args.debug_info)
b.build(args.out)
15 changes: 12 additions & 3 deletions platforms/osx/build_framework.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
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):
Expand All @@ -18,10 +20,10 @@ def getToolchain(self, arch, target):
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())
]
Expand All @@ -39,10 +41,17 @@ def getInfoPlist(self, builddirs):
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)

0 comments on commit 96d5cbd

Please sign in to comment.