view buildSrc/mac.gradle @ 8968:eb272f8584c8

Automated merge with http://hg.openjdk.java.net/openjfx/8u40/rt
author kcr
date Fri, 06 Feb 2015 11:18:35 -0800
parents 4961aaff8e60
children 0efae19e83e7
line wrap: on
line source
/*
 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

ext.MAC = [:]

MAC.canBuild = IS_MAC && IS_64
if (!MAC.canBuild) return;

// All desktop related packages should be built
MAC.compileSwing = true;
MAC.compileSWT = true;
MAC.compileFXPackager = true;
MAC.compileDesignTime = true;

MAC.includeNull3d = true

// Lambda for naming the generated libs
MAC.library = { name -> return "lib${name}.dylib" as String }

MAC.libDest = "lib"

/*
 * Define settings for Mac compilation. If we don't find the preferred 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 prefSdkVersion = "10.7"
def defaultSdkPath = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${prefSdkVersion}.sdk";

// Set the minimum API version that we require (developers do not need to override this)
// Note that this is not necessarily the same as the preferred SDK version
defineProperty("MACOSX_MIN_VERSION", "10.7");

// Create $buildDir/mac_tools.properties file and load props from it
setupTools("mac_tools",
    { propFile ->
        propFile << ""
        if (!file(defaultSdkPath).isDirectory()) {
            // Get list of all macosx sdks
            ByteArrayOutputStream results = new ByteArrayOutputStream();
            exec {
                commandLine("xcodebuild", "-version", "-showsdks");
                setStandardOutput(results);
            }

            BufferedReader reader = new BufferedReader(new StringReader(results.toString().trim()));
            // If our preferred SDK is in the list use it, else use the default
            String sdk = "macosx"
            String prefSdk = sdk + prefSdkVersion
            while (true) {
                def line = reader.readLine();
                if (line == null) break;
                if (line.contains("-sdk ${prefSdk}")) {
                    sdk = prefSdk
                    break;
                }
            }

            results = new ByteArrayOutputStream();
            exec {
                commandLine("xcodebuild", "-version", "-sdk", sdk, "Path");
                setStandardOutput(results);
            }
            String sdkPath = results.toString().trim();
            propFile << "MACOSX_SDK_PATH=" << sdkPath << "\n";
        }
    },
    { 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",
        "-isysroot", "$MACOSX_SDK_PATH",
        "-arch", "x86_64"]

def ccBaseFlags = [
        commonParams,
        "-I$JDK_HOME/include",
        "-I$JDK_HOME/include/darwin"].flatten()


def ccFlags = [
        ccBaseFlags,
        "-std=c99",
        "-c",
        IS_DEBUG_NATIVE ? "-DDEBUG" : ["-O3", "-DNDEBUG"]].flatten()

def linkFlags = [
        commonParams,
        "-framework", "AppKit",
        "-framework", "ApplicationServices",
        "-framework", "OpenGL",
        "-framework", "QuartzCore",
        "-framework", "Security",
        "-dynamiclib", "-lobjc"].flatten();


def compiler = IS_COMPILE_PARFAIT ? "parfait-gcc" : "gcc";
def linker = IS_COMPILE_PARFAIT ? "parfait-g++" : "g++";

MAC.glass = [:]
MAC.glass.javahInclude = [
    "com/sun/glass/events/**",
    "com/sun/glass/ui/*",
    "com/sun/glass/ui/mac/*"]
MAC.glass.nativeSource = file("modules/graphics/src/main/native-glass/mac")
MAC.glass.compiler = compiler
MAC.glass.ccFlags = [ccFlags].flatten()
MAC.glass.linker = linker
MAC.glass.linkFlags = [linkFlags].flatten()
MAC.glass.lib = "glass"

MAC.decora = [:]
MAC.decora.compiler = compiler
MAC.decora.ccFlags = ["-O1", "-ffast-math", "-c", ccBaseFlags].flatten()
MAC.decora.linker = linker
MAC.decora.linkFlags = ["-dynamiclib", commonParams].flatten()
MAC.decora.lib = "decora_sse"

MAC.prism = [:]
MAC.prism.javahInclude = ["com/sun/prism/impl/**/*", "com/sun/prism/PresentableState*"]
MAC.prism.nativeSource = file("modules/graphics/src/main/native-prism")
MAC.prism.compiler = compiler
MAC.prism.ccFlags = ["-O3", "-DINLINE=inline", "-c", ccBaseFlags].flatten()
MAC.prism.linker = linker
MAC.prism.linkFlags = ["-dynamiclib", commonParams].flatten()
MAC.prism.lib = "prism_common"

MAC.prismSW = [:]
MAC.prismSW.javahInclude = ["com/sun/pisces/**/*"]
MAC.prismSW.nativeSource = file("modules/graphics/src/main/native-prism-sw")
MAC.prismSW.compiler = compiler
MAC.prismSW.ccFlags = [MAC.prism.ccFlags].flatten()
MAC.prismSW.linker = linker
MAC.prismSW.linkFlags = [MAC.prism.linkFlags].flatten()
MAC.prismSW.lib = "prism_sw"

MAC.launcher = [:]
MAC.launcher.compiler = compiler
MAC.launcher.ccFlags = [
        "-std=c99",
        ccBaseFlags,
        "-framework", "Cocoa",
        IS_DEBUG_NATIVE ? ["-DDEBUG", "-O0"] : ["-O3", "-DNDEBUG"]].flatten()
MAC.launcher.linker = linker
MAC.launcher.linkFlags = ["-ldl"]

MAC.launcherlibrary = [:]
MAC.launcherlibrary.compiler = compiler
MAC.launcherlibrary.ccFlags = [
        "-c",
        ccBaseFlags,
        IS_DEBUG_NATIVE ? ["-DDEBUG", "-O0"] : ["-O3", "-DNDEBUG"]].flatten()
// 10.7 doesn't have libstdc++ as an option for stdlib, so filter it out
if (!(MACOSX_MIN_VERSION in ['10.7', '10.8'])) {
    MAC.launcherlibrary.ccFlags += "-stdlib=libstdc++"
}
MAC.launcherlibrary.linker = linker
MAC.launcherlibrary.linkFlags = ["-ldl", "-dynamiclib",
        "-framework", "Cocoa",
        "-stdlib=libstdc++"]

MAC.iio = [:]
MAC.iio.javahInclude = ["com/sun/javafx/iio/**/*"]
MAC.iio.nativeSource = [
    file("modules/graphics/src/main/native-iio"),
    file("modules/graphics/src/main/native-iio/libjpeg7")]
MAC.iio.compiler = compiler
MAC.iio.ccFlags = [ccFlags].flatten()
MAC.iio.linker = linker
MAC.iio.linkFlags = [linkFlags].flatten()
MAC.iio.lib = "javafx_iio"

MAC.prismES2 = [:]
MAC.prismES2.javahInclude = ["com/sun/prism/es2/**/*"]
MAC.prismES2.nativeSource = [
    file("modules/graphics/src/main/native-prism-es2"),
    file("modules/graphics/src/main/native-prism-es2/GL"),
    file("modules/graphics/src/main/native-prism-es2/macosx")
]
MAC.prismES2.compiler = compiler
MAC.prismES2.ccFlags = ["-DMACOSX", ccFlags].flatten()
MAC.prismES2.linker = linker
MAC.prismES2.linkFlags = [linkFlags].flatten()
MAC.prismES2.lib = "prism_es2"

def closedDir = file("$projectDir/../rt-closed")
MAC.font = [:]
MAC.font.javahInclude = [
        "com/sun/javafx/font/**/*",
        "com/sun/javafx/text/**/*"]
MAC.font.nativeSource = [file("modules/graphics/src/main/native-font")]
MAC.font.compiler = compiler
MAC.font.ccFlags = ["-DJFXFONT_PLUS", ccFlags].flatten()
MAC.font.linker = linker
MAC.font.linkFlags = [linkFlags].flatten()
MAC.font.lib = "javafx_font"

MAC.fontT2K = [:]
MAC.fontT2K.javahInclude = ["com/sun/javafx/font/t2k/**/*"]
MAC.fontT2K.nativeSource = [
        file("$closedDir/javafx-font-t2k-native/src"),
        file("$closedDir/javafx-font-t2k-native/src/layout")]
MAC.fontT2K.compiler = compiler
MAC.fontT2K.ccFlags = ["-DJFXFONT_PLUS", "-DLE_STANDALONE", ccFlags].flatten()
MAC.fontT2K.linker = linker
MAC.fontT2K.linkFlags = [linkFlags].flatten()
MAC.fontT2K.lib = "javafx_font_t2k"

MAC.media = [:]
MAC.media.compiler = compiler
MAC.media.linker = linker
MAC.media.lib = "libtool"