--- old/buildSrc/mac.gradle 2014-11-04 14:32:57.684267600 -0800 +++ new/buildSrc/mac.gradle 2014-11-04 14:32:56.926224200 -0800 @@ -41,11 +41,76 @@ MAC.libDest = "lib" -// Define settings for Mac compilation. This is much easier than Windows because we know what version we're -// compiling against and Mac always puts it in the same place. In extreme cases you can provide your own -// properties in your home dir to override these settings or pass them on the command line via -P -defineProperty("MACOSX_MIN_VERSION", "10.7"); -defineProperty("MACOSX_SDK_PATH", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${MACOSX_MIN_VERSION}.sdk"); +/* + * Define settings for Mac compilation. If we don't find the SDK in the + * default location then we will use "xcodebuild" to locate a suitable SDK. + * In extreme cases you can provide your own properties in your home dir to + * override these settings or pass them on the command line. + */ +def minSdkVersion = "10.7" +def defaultSdkPath = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${minSdkVersion}.sdk"; + +// Ordered list of SDKs to search if default path is not found +def macosxSdks = [ + "macosx10.7", + "macosx10.8", + "macosx10.9", +] + +// Set the minimum API version that we require (developers do not need to override this) +defineProperty("MACOSX_MIN_VERSION", "$minSdkVersion"); + +// Create $buildDir/mac_tools.properties file and load props from it +setupTools("mac_tools", + { propFile -> + propFile << "" + if (!file(defaultSdkPath).isDirectory()) { + // Collect all macosx sdks. + ByteArrayOutputStream results = new ByteArrayOutputStream(); + exec { + commandLine("xcodebuild", "-version", "-showsdks"); + setStandardOutput(results); + } + + BufferedReader reader = new BufferedReader(new StringReader(results.toString().trim())); + def sdkList = [] + while (true) { + def line = reader.readLine(); + if (line == null) break; + def idx = line.indexOf("-sdk macosx"); + if (idx >= 0) { + sdkList += line.substring(idx+4).trim(); + } + } + + // Loop through the predefined list of SDKs that we recognize + for (String sdk : macosxSdks) { + if (sdkList.contains(sdk)) { + results = new ByteArrayOutputStream(); + exec { + commandLine("xcodebuild", "-version", "-sdk", "$sdk", "Path"); + setStandardOutput(results); + } + String sdkPath = results.toString().trim(); + if (file(sdkPath).isDirectory()) { + propFile << "MACOSX_SDK_PATH=" << sdkPath << "\n"; + break; + } + } + } + } + }, + { properties -> + defineProperty("MACOSX_SDK_PATH", properties, "$defaultSdkPath") + } +) + +println "MACOSX_MIN_VERSION = $MACOSX_MIN_VERSION" +println "MACOSX_SDK_PATH = $MACOSX_SDK_PATH" + +if (!file(MACOSX_SDK_PATH).isDirectory()) { + throw new GradleException("FAIL: Cannot find $MACOSX_SDK_PATH") +} def commonParams = [ "-mmacosx-version-min=$MACOSX_MIN_VERSION",