1 /* 2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 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, 134 "-framework", "AppKit", 135 "-framework", "ApplicationServices", 136 "-framework", "OpenGL", 137 "-framework", "QuartzCore", 138 "-framework", "Security", 139 "-dynamiclib", "-lobjc"].flatten(); 140 141 142 def compiler = IS_COMPILE_PARFAIT ? "parfait-gcc" : "gcc"; 143 def linker = IS_COMPILE_PARFAIT ? "parfait-g++" : "g++"; 144 145 MAC.glass = [:] 146 MAC.glass.javahInclude = [ 147 "com/sun/glass/events/**", 148 "com/sun/glass/ui/*", 149 "com/sun/glass/ui/mac/*"] 150 MAC.glass.nativeSource = file("modules/graphics/src/main/native-glass/mac") 151 MAC.glass.compiler = compiler 152 MAC.glass.ccFlags = [ccFlags].flatten() 153 MAC.glass.linker = linker 154 MAC.glass.linkFlags = [linkFlags].flatten() 155 MAC.glass.lib = "glass" 156 157 MAC.decora = [:] 158 MAC.decora.compiler = compiler 159 MAC.decora.ccFlags = ["-O1", "-ffast-math", "-c", ccBaseFlags].flatten() 160 MAC.decora.linker = linker 161 MAC.decora.linkFlags = ["-dynamiclib", commonParams].flatten() 162 MAC.decora.lib = "decora_sse" 163 164 MAC.prism = [:] 165 MAC.prism.javahInclude = ["com/sun/prism/impl/**/*", "com/sun/prism/PresentableState*"] 166 MAC.prism.nativeSource = file("modules/graphics/src/main/native-prism") 167 MAC.prism.compiler = compiler 168 MAC.prism.ccFlags = ["-O3", "-DINLINE=inline", "-c", ccBaseFlags].flatten() 169 MAC.prism.linker = linker 170 MAC.prism.linkFlags = ["-dynamiclib", commonParams].flatten() 171 MAC.prism.lib = "prism_common" 172 173 MAC.prismSW = [:] 174 MAC.prismSW.javahInclude = ["com/sun/pisces/**/*"] 175 MAC.prismSW.nativeSource = file("modules/graphics/src/main/native-prism-sw") 176 MAC.prismSW.compiler = compiler 177 MAC.prismSW.ccFlags = [MAC.prism.ccFlags].flatten() 178 MAC.prismSW.linker = linker 179 MAC.prismSW.linkFlags = [MAC.prism.linkFlags].flatten() 180 MAC.prismSW.lib = "prism_sw" 181 182 MAC.launcher = [:] 183 MAC.launcher.compiler = compiler 184 MAC.launcher.ccFlags = [ 185 "-std=c99", 186 ccBaseFlags, 187 "-framework", "Cocoa", 188 IS_DEBUG_NATIVE ? ["-DDEBUG", "-O0"] : ["-O3", "-DNDEBUG"]].flatten() 189 MAC.launcher.linker = linker 190 MAC.launcher.linkFlags = ["-ldl"] 191 192 MAC.launcherlibrary = [:] 193 MAC.launcherlibrary.compiler = compiler 194 MAC.launcherlibrary.ccFlags = [ 195 "-c", 196 ccBaseFlags, 197 IS_DEBUG_NATIVE ? ["-DDEBUG", "-O0"] : ["-O3", "-DNDEBUG"]].flatten() 198 // 10.7 doesn't have libstdc++ as an option for stdlib, so filter it out 199 if (!(MACOSX_MIN_VERSION in ['10.7', '10.8'])) { 200 MAC.launcherlibrary.ccFlags += "-stdlib=libstdc++" 201 } 202 MAC.launcherlibrary.linker = linker 203 MAC.launcherlibrary.linkFlags = ["-ldl", "-dynamiclib", 204 "-framework", "Cocoa", 205 "-stdlib=libstdc++"] 206 207 MAC.iio = [:] 208 MAC.iio.javahInclude = ["com/sun/javafx/iio/**/*"] 209 MAC.iio.nativeSource = [ 210 file("modules/graphics/src/main/native-iio"), 211 file("modules/graphics/src/main/native-iio/libjpeg7")] 212 MAC.iio.compiler = compiler 213 MAC.iio.ccFlags = [ccFlags].flatten() 214 MAC.iio.linker = linker 215 MAC.iio.linkFlags = [linkFlags].flatten() 216 MAC.iio.lib = "javafx_iio" 217 218 MAC.prismES2 = [:] 219 MAC.prismES2.javahInclude = ["com/sun/prism/es2/**/*"] 220 MAC.prismES2.nativeSource = [ 221 file("modules/graphics/src/main/native-prism-es2"), 222 file("modules/graphics/src/main/native-prism-es2/GL"), 223 file("modules/graphics/src/main/native-prism-es2/macosx") 224 ] 225 MAC.prismES2.compiler = compiler 226 MAC.prismES2.ccFlags = ["-DMACOSX", ccFlags].flatten() 227 MAC.prismES2.linker = linker 228 MAC.prismES2.linkFlags = [linkFlags].flatten() 229 MAC.prismES2.lib = "prism_es2" 230 231 def closedDir = file("$projectDir/../rt-closed") 232 MAC.font = [:] 233 MAC.font.javahInclude = [ 234 "com/sun/javafx/font/**/*", 235 "com/sun/javafx/text/**/*"] 236 MAC.font.nativeSource = [file("modules/graphics/src/main/native-font")] 237 MAC.font.compiler = compiler 238 MAC.font.ccFlags = ["-DJFXFONT_PLUS", ccFlags].flatten() 239 MAC.font.linker = linker 240 MAC.font.linkFlags = [linkFlags].flatten() 241 MAC.font.lib = "javafx_font" 242 243 MAC.fontT2K = [:] 244 MAC.fontT2K.javahInclude = ["com/sun/javafx/font/t2k/**/*"] 245 MAC.fontT2K.nativeSource = [ 246 file("$closedDir/javafx-font-t2k-native/src"), 247 file("$closedDir/javafx-font-t2k-native/src/layout")] 248 MAC.fontT2K.compiler = compiler 249 MAC.fontT2K.ccFlags = ["-DJFXFONT_PLUS", "-DLE_STANDALONE", ccFlags].flatten() 250 MAC.fontT2K.linker = linker 251 MAC.fontT2K.linkFlags = [linkFlags].flatten() 252 MAC.fontT2K.lib = "javafx_font_t2k" 253 254 MAC.media = [:] 255 MAC.media.compiler = compiler 256 MAC.media.linker = linker 257 MAC.media.lib = "libtool"