buildSrc/mac.gradle

Print this page
rev 8319 : RT-34388: [Mac] Update build system to properly support Xcode 5 and later


  24  */
  25 
  26 ext.MAC = [:]
  27 
  28 MAC.canBuild = IS_MAC && IS_64
  29 if (!MAC.canBuild) return;
  30 
  31 // All desktop related packages should be built
  32 MAC.compileSwing = true;
  33 MAC.compileSWT = true;
  34 MAC.compileFXPackager = true;
  35 MAC.compileDesignTime = true;
  36 
  37 MAC.includeNull3d = true
  38 
  39 // Lambda for naming the generated libs
  40 MAC.library = { name -> return "lib${name}.dylib" as String }
  41 
  42 MAC.libDest = "lib"
  43 
  44 // Define settings for Mac compilation. This is much easier than Windows because we know what version we're
  45 // compiling against and Mac always puts it in the same place. In extreme cases you can provide your own
  46 // properties in your home dir to override these settings or pass them on the command line via -P
  47 defineProperty("MACOSX_MIN_VERSION", "10.7");
  48 defineProperty("MACOSX_SDK_PATH", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${MACOSX_MIN_VERSION}.sdk");

































































  49 
  50 def commonParams = [
  51         "-mmacosx-version-min=$MACOSX_MIN_VERSION",
  52         "-isysroot", "$MACOSX_SDK_PATH",
  53         "-arch", "x86_64"]
  54 
  55 def ccBaseFlags = [
  56         commonParams,
  57         "-I$JDK_HOME/include",
  58         "-I$JDK_HOME/include/darwin"].flatten()
  59 
  60 
  61 def ccFlags = [
  62         ccBaseFlags,
  63         "-std=c99",
  64         "-c",
  65         IS_DEBUG_NATIVE ? "-DDEBUG" : ["-O3", "-DNDEBUG"]].flatten()
  66 
  67 def linkFlags = [
  68         commonParams,




  24  */
  25 
  26 ext.MAC = [:]
  27 
  28 MAC.canBuild = IS_MAC && IS_64
  29 if (!MAC.canBuild) return;
  30 
  31 // All desktop related packages should be built
  32 MAC.compileSwing = true;
  33 MAC.compileSWT = true;
  34 MAC.compileFXPackager = true;
  35 MAC.compileDesignTime = true;
  36 
  37 MAC.includeNull3d = true
  38 
  39 // Lambda for naming the generated libs
  40 MAC.library = { name -> return "lib${name}.dylib" as String }
  41 
  42 MAC.libDest = "lib"
  43 
  44 /*
  45  * Define settings for Mac compilation. If we don't find the SDK in the
  46  * default location then we will use "xcodebuild" to locate a suitable SDK.
  47  * In extreme cases you can provide your own properties in your home dir to
  48  * override these settings or pass them on the command line.
  49  */
  50 def minSdkVersion = "10.7"
  51 def defaultSdkPath = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${minSdkVersion}.sdk";
  52 
  53 // Ordered list of SDKs to search if default path is not found
  54 def macosxSdks = [
  55     "macosx10.7",
  56     "macosx10.8",
  57     "macosx10.9",
  58 ]
  59 
  60 // Set the minimum API version that we require (developers do not need to override this)
  61 defineProperty("MACOSX_MIN_VERSION", "$minSdkVersion");
  62 
  63 // Create $buildDir/mac_tools.properties file and load props from it
  64 setupTools("mac_tools",
  65     { propFile ->
  66         propFile << ""
  67         if (!file(defaultSdkPath).isDirectory()) {
  68             // Collect all macosx sdks.
  69             ByteArrayOutputStream results = new ByteArrayOutputStream();
  70             exec {
  71                 commandLine("xcodebuild", "-version", "-showsdks");
  72                 setStandardOutput(results);
  73             }
  74 
  75             BufferedReader reader = new BufferedReader(new StringReader(results.toString().trim()));
  76             def sdkList = []
  77             while (true) {
  78                 def line = reader.readLine();
  79                 if (line == null) break;
  80                 def idx = line.indexOf("-sdk macosx");
  81                 if (idx >= 0) {
  82                     sdkList += line.substring(idx+4).trim();
  83                 }
  84             }
  85 
  86             // Loop through the predefined list of SDKs that we recognize
  87             for (String sdk : macosxSdks) {
  88                 if (sdkList.contains(sdk)) {
  89                     results = new ByteArrayOutputStream();
  90                     exec {
  91                         commandLine("xcodebuild", "-version", "-sdk", "$sdk", "Path");
  92                         setStandardOutput(results);
  93                     }
  94                     String sdkPath = results.toString().trim();
  95                     if (file(sdkPath).isDirectory()) {
  96                         propFile << "MACOSX_SDK_PATH=" << sdkPath << "\n";
  97                         break;
  98                     }
  99                 }
 100             }
 101         }
 102     },
 103     { properties ->
 104         defineProperty("MACOSX_SDK_PATH", properties, "$defaultSdkPath")
 105     }
 106 )
 107 
 108 println "MACOSX_MIN_VERSION = $MACOSX_MIN_VERSION"
 109 println "MACOSX_SDK_PATH = $MACOSX_SDK_PATH"
 110 
 111 if (!file(MACOSX_SDK_PATH).isDirectory()) {
 112     throw new GradleException("FAIL: Cannot find $MACOSX_SDK_PATH")
 113 }
 114 
 115 def commonParams = [
 116         "-mmacosx-version-min=$MACOSX_MIN_VERSION",
 117         "-isysroot", "$MACOSX_SDK_PATH",
 118         "-arch", "x86_64"]
 119 
 120 def ccBaseFlags = [
 121         commonParams,
 122         "-I$JDK_HOME/include",
 123         "-I$JDK_HOME/include/darwin"].flatten()
 124 
 125 
 126 def ccFlags = [
 127         ccBaseFlags,
 128         "-std=c99",
 129         "-c",
 130         IS_DEBUG_NATIVE ? "-DDEBUG" : ["-O3", "-DNDEBUG"]].flatten()
 131 
 132 def linkFlags = [
 133         commonParams,