Use all available cpu cores in iOS/OSX build procedure
[platform/upstream/opencv.git] / platforms / osx / build_framework.py
1 #!/usr/bin/env python
2 """
3 The script builds OpenCV.framework for OSX.
4 """
5
6 from __future__ import print_function
7 import os, os.path, sys, argparse, traceback, multiprocessing
8
9 # import common code
10 sys.path.insert(0, os.path.abspath(os.path.abspath(os.path.dirname(__file__))+'/../ios'))
11 from build_framework import Builder
12
13 class OSXBuilder(Builder):
14
15     def getToolchain(self, arch, target):
16         return None
17
18     def getBuildCommand(self, archs, target):
19         buildcmd = [
20             "xcodebuild",
21             "MACOSX_DEPLOYMENT_TARGET=10.9",
22             "ARCHS=%s" % archs[0],
23             "-sdk", target.lower(),
24             "-configuration", "Release",
25             "-parallelizeTargets",
26             "-jobs", multiprocessing.cpu_count()
27         ]
28         return buildcmd
29
30     def getInfoPlist(self, builddirs):
31         return os.path.join(builddirs[0], "osx", "Info.plist")
32
33
34 if __name__ == "__main__":
35     folder = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "../.."))
36     parser = argparse.ArgumentParser(description='The script builds OpenCV.framework for OSX.')
37     parser.add_argument('out', metavar='OUTDIR', help='folder to put built framework')
38     parser.add_argument('--opencv', metavar='DIR', default=folder, help='folder with opencv repository (default is "../.." relative to script location)')
39     parser.add_argument('--contrib', metavar='DIR', default=None, help='folder with opencv_contrib repository (default is "None" - build only main framework)')
40     parser.add_argument('--without', metavar='MODULE', default=[], action='append', help='OpenCV modules to exclude from the framework')
41     args = parser.parse_args()
42
43     b = OSXBuilder(args.opencv, args.contrib, False, False, args.without,
44         [
45             (["x86_64"], "MacOSX")
46         ])
47     b.build(args.out)