Skip to content

Commit 73ab6d4

Browse files
committed
Fix building with Xcode 6
1 parent 55715be commit 73ab6d4

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

toolchain.gypi

+18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
'sysroot%': '',
1010

1111
'variables': {
12+
# The minimum OS X SDK version to use.
13+
'mac_sdk_min%': '10.10',
14+
1215
# Set ARM architecture version.
1316
'arm_version%': 7,
1417

@@ -17,6 +20,7 @@
1720
},
1821

1922
# Copy conditionally-set variables out one scope.
23+
'mac_sdk_min%': '<(mac_sdk_min)',
2024
'arm_version%': '<(arm_version)',
2125
'arm_neon%': '<(arm_neon)',
2226

@@ -35,6 +39,11 @@
3539
'source_root': '<!(cd <(DEPTH) && pwd -P)',
3640
}], # OS!="win"
3741

42+
# Search for the available version of SDK.
43+
['OS=="mac"', {
44+
'mac_sdk%': '<!(python <(DEPTH)/tools/mac/find_sdk.py <(mac_sdk_min))',
45+
}],
46+
3847
# Set default compiler flags depending on ARM version.
3948
['arm_version==6', {
4049
'arm_arch%': 'armv6',
@@ -94,6 +103,15 @@
94103
},
95104
}], # clang==1
96105

106+
# Specify the SDKROOT.
107+
['OS=="mac"', {
108+
'target_defaults': {
109+
'xcode_settings': {
110+
'SDKROOT': 'macosx<(mac_sdk)', # -isysroot
111+
},
112+
},
113+
}],
114+
97115
# Setup sysroot environment.
98116
['OS=="linux" and target_arch in ["arm", "ia32"]', {
99117
'variables': {

tools/mac/find_sdk.py

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
"""Prints the lowest locally available SDK version greater than or equal to a
7+
given minimum sdk version to standard output.
8+
9+
Usage:
10+
python find_sdk.py 10.6 # Ignores SDKs < 10.6
11+
"""
12+
13+
import os
14+
import re
15+
import subprocess
16+
import sys
17+
18+
19+
from optparse import OptionParser
20+
21+
22+
def parse_version(version_str):
23+
"""'10.6' => [10, 6]"""
24+
return map(int, re.findall(r'(\d+)', version_str))
25+
26+
27+
def main():
28+
parser = OptionParser()
29+
parser.add_option("--verify",
30+
action="store_true", dest="verify", default=False,
31+
help="return the sdk argument and warn if it doesn't exist")
32+
parser.add_option("--sdk_path",
33+
action="store", type="string", dest="sdk_path", default="",
34+
help="user-specified SDK path; bypasses verification")
35+
parser.add_option("--print_sdk_path",
36+
action="store_true", dest="print_sdk_path", default=False,
37+
help="Additionaly print the path the SDK (appears first).")
38+
options, args = parser.parse_args()
39+
if len(args) != 1:
40+
parser.error('Please specify a minimum SDK version')
41+
min_sdk_version = args[0]
42+
43+
job = subprocess.Popen(['xcode-select', '-print-path'],
44+
stdout=subprocess.PIPE,
45+
stderr=subprocess.STDOUT)
46+
out, err = job.communicate()
47+
if job.returncode != 0:
48+
print >> sys.stderr, out
49+
print >> sys.stderr, err
50+
raise Exception(('Error %d running xcode-select, you might have to run '
51+
'|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| '
52+
'if you are using Xcode 4.') % job.returncode)
53+
# The Developer folder moved in Xcode 4.3.
54+
xcode43_sdk_path = os.path.join(
55+
out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs')
56+
if os.path.isdir(xcode43_sdk_path):
57+
sdk_dir = xcode43_sdk_path
58+
else:
59+
sdk_dir = os.path.join(out.rstrip(), 'SDKs')
60+
sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)]
61+
sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6']
62+
sdks = [s for s in sdks # ['10.5', '10.6'] => ['10.6']
63+
if parse_version(s) >= parse_version(min_sdk_version)]
64+
if not sdks:
65+
raise Exception('No %s+ SDK found' % min_sdk_version)
66+
best_sdk = sorted(sdks, key=parse_version)[0]
67+
68+
if options.verify and best_sdk != min_sdk_version and not options.sdk_path:
69+
print >> sys.stderr, ''
70+
print >> sys.stderr, ' vvvvvvv'
71+
print >> sys.stderr, ''
72+
print >> sys.stderr, \
73+
'This build requires the %s SDK, but it was not found on your system.' \
74+
% min_sdk_version
75+
print >> sys.stderr, \
76+
'Either install it, or explicitly set mac_sdk in your GYP_DEFINES.'
77+
print >> sys.stderr, ''
78+
print >> sys.stderr, ' ^^^^^^^'
79+
print >> sys.stderr, ''
80+
return min_sdk_version
81+
82+
if options.print_sdk_path:
83+
print subprocess.check_output(['xcodebuild', '-version', '-sdk',
84+
'macosx' + best_sdk, 'Path']).strip()
85+
86+
return best_sdk
87+
88+
89+
if __name__ == '__main__':
90+
if sys.platform != 'darwin':
91+
raise Exception("This script only runs on Mac")
92+
print main()
93+
sys.exit(0)

0 commit comments

Comments
 (0)