aboutsummaryrefslogtreecommitdiffstats
path: root/share/qbs/modules/cpp/DarwinGCC.qbs
blob: efdd97f1d0cc0d7a8bced2f70d09a63514e79365 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qbs.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

import qbs.DarwinTools
import qbs.File
import qbs.FileInfo
import qbs.ModUtils
import qbs.PathTools
import qbs.Probes
import qbs.PropertyList
import qbs.TextFile
import qbs.Utilities
import "darwin.js" as Darwin
import "gcc.js" as Gcc

UnixGCC {
    condition: false

    Depends { name: "xcode"; required: qbs.toolchain && qbs.toolchain.contains("xcode") }

    Probes.BinaryProbe {
        id: lipoProbe
        condition: !_skipAllChecks
        names: [lipoName]
        platformSearchPaths: {
            var paths = (xcode.present && xcode.devicePlatformPath)
                    ? [xcode.devicePlatformPath + "/Developer/usr/bin"]
                    : [];
            return paths.concat([toolchainInstallPath, "/usr/bin"]);
        }
    }

    property string lipoPathPrefix: Gcc.pathPrefix(lipoProbe.found
                                                   ? lipoProbe.path
                                                   : toolchainInstallPath, toolchainPrefix)

    lipoName: "lipo"
    lipoPath: lipoPathPrefix + lipoName
    property bool enableAggregationRules: product.aggregate && !product.multiplexConfigurationId

    targetVendor: "apple"
    targetSystem: "darwin"
    targetAbi: "macho"
    imageFormat: "macho"

    cxxStandardLibrary: libcxxAvailable ? "libc++" : base
    loadableModulePrefix: ""
    loadableModuleSuffix: ".bundle"
    dynamicLibrarySuffix: ".dylib"

    Properties {
        condition: product.multiplexByQbsProperties.contains("buildVariants")
                   && qbs.buildVariants && qbs.buildVariants.length > 1
                   && (!product.aggregate || !!product.multiplexConfigurationId)
                   && qbs.buildVariant !== "release"
        variantSuffix: "_" + qbs.buildVariant
    }

    separateDebugInformation: true
    debugInfoBundleSuffix: ".dSYM"
    debugInfoSuffix: ".dwarf"
    rpathOrigin: "@loader_path"
    useRPathLink: !minimumDarwinVersion
                  || Utilities.versionCompare(minimumDarwinVersion, "10.5") < 0
    rpathLinkFlag: "-L"

    toolchainInstallPath: xcode.present
                          ? FileInfo.joinPaths(xcode.toolchainPath, "usr", "bin") : base
    sysroot: xcode.present ? xcode.sdkPath : base
    sysrootFlags: sysroot ? ["-isysroot", sysroot] : []

    setupBuildEnvironment: {
        for (var key in product.cpp.buildEnv) {
            var v = new ModUtils.EnvironmentVariable(key);
            v.value = product.cpp.buildEnv[key];
            v.set();
        }
    }

    property var defaultInfoPlist: {
        var dict = {};

        if (qbs.targetOS.contains("macos")) {
            dict["NSPrincipalClass"] = "NSApplication"; // needed for Retina display support

            if (minimumMacosVersion)
                dict["LSMinimumSystemVersion"] = minimumMacosVersion;
        }

        if (qbs.targetOS.containsAny(["ios", "tvos"])) {
            dict["LSRequiresIPhoneOS"] = true;

            if (xcode.platformType === "device") {
                if (qbs.targetOS.contains("ios")) {
                    if (qbs.architecture === "arm64")
                        dict["UIRequiredDeviceCapabilities"] = ["arm64"];
                    else
                        dict["UIRequiredDeviceCapabilities"] = ["armv7"];
                }

                if (qbs.targetOS.contains("tvos"))
                    dict["UIRequiredDeviceCapabilities"] = ["arm64"];
            }
        }

        if (xcode.present) {
            var targetDevices = DarwinTools.targetedDeviceFamily(xcode.targetDevices);
            if (qbs.targetOS.contains("ios"))
                dict["UIDeviceFamily"] = targetDevices;

            if (qbs.targetOS.containsAny(["ios", "watchos"])) {
                var orientations = [
                    "UIInterfaceOrientationPortrait",
                    "UIInterfaceOrientationPortraitUpsideDown",
                    "UIInterfaceOrientationLandscapeLeft",
                    "UIInterfaceOrientationLandscapeRight"
                ];

                if (targetDevices.contains("ipad"))
                    dict["UISupportedInterfaceOrientations~ipad"] = orientations;

                if (targetDevices.contains("watch"))
                    dict["UISupportedInterfaceOrientations"] = orientations.slice(0, 2);

                if (targetDevices.contains("iphone")) {
                    orientations.splice(1, 1);
                    dict["UISupportedInterfaceOrientations"] = orientations;
                }
            }
        }

        return dict;
    }

    targetLinkerFlags: darwinArchFlags.concat(minimumDarwinVersionLinkerFlags)

    targetAssemblerFlags: !assemblerHasTargetOption ? darwinArchFlags : base;

    targetDriverFlags: !compilerHasTargetOption ? legacyTargetDriverFlags : base

    property stringList legacyTargetDriverFlags:
        base.concat(darwinArchFlags).concat(minimumDarwinVersionCompilerFlags)

    // private properties
    readonly property stringList darwinArchFlags: targetArch ? ["-arch", targetArch] : []

    readonly property stringList minimumDarwinVersionCompilerFlags:
        (minimumDarwinVersionCompilerFlag && minimumDarwinVersion)
        ? [minimumDarwinVersionCompilerFlag + "=" + minimumDarwinVersion] : []

    readonly property stringList minimumDarwinVersionLinkerFlags:
        (minimumDarwinVersionLinkerFlag && minimumDarwinVersion && compilerVersionMajor < 11)
        ? [minimumDarwinVersionLinkerFlag, minimumDarwinVersion] : []

    readonly property var buildEnv: {
        var env = {
            "ARCHS_STANDARD": xcode.standardArchitectures,
            "EXECUTABLE_NAME": product.targetName,
            "LANG": "en_US.US-ASCII",
            "PRODUCT_NAME": product.name
        }

        // Set the corresponding environment variable even if the minimum OS version is undefined,
        // because this indicates the default deployment target for that OS
        if (qbs.targetOS.contains("ios") && minimumIosVersion)
            env["IPHONEOS_DEPLOYMENT_TARGET"] = minimumIosVersion;
        if (qbs.targetOS.contains("macos") && minimumMacosVersion)
            env["MACOSX_DEPLOYMENT_TARGET"] = minimumMacosVersion;
        if (qbs.targetOS.contains("watchos") && minimumWatchosVersion)
            env["WATCHOS_DEPLOYMENT_TARGET"] = minimumWatchosVersion;
        if (qbs.targetOS.contains("tvos") && minimumTvosVersion)
            env["TVOS_DEPLOYMENT_TARGET"] = minimumTvosVersion;

        if (xcode.present)
            env["TARGETED_DEVICE_FAMILY"] =
                    DarwinTools.targetedDeviceFamily(xcode.targetDevices).join(",");
        return env;
    }

    property string minimumDarwinVersion
    property string minimumDarwinVersionCompilerFlag
    property string minimumDarwinVersionLinkerFlag

    property bool libcxxAvailable: qbs.toolchain.contains("clang") && cxxLanguageVersion !== "c++98"

    Rule {
        condition: enableAggregationRules
        inputsFromDependencies: ["application"]
        multiplex: true

        outputFileTags: ["bundle.input", "application", "primary", "debuginfo_app",
                         "debuginfo_bundle", "bundle.variant_symlink", "debuginfo_plist"]
        outputArtifacts: Darwin.lipoOutputArtifacts(product, inputs, "application", "app")

        prepare: Darwin.prepareLipo.apply(Darwin, arguments)
    }

    Rule {
        condition: enableAggregationRules
        inputsFromDependencies: ["loadablemodule"]
        multiplex: true

        outputFileTags: ["bundle.input", "loadablemodule", "primary", "debuginfo_loadablemodule"]
        outputArtifacts: Darwin.lipoOutputArtifacts(product, inputs, "loadablemodule",
                                                                     "loadablemodule")

        prepare: Darwin.prepareLipo.apply(Darwin, arguments)
    }

    Rule {
        condition: enableAggregationRules
        inputsFromDependencies: ["dynamiclibrary"]
        multiplex: true

        outputFileTags: ["bundle.input", "dynamiclibrary", "dynamiclibrary_symbols", "primary",
                         "debuginfo_dll","debuginfo_bundle","bundle.variant_symlink",
                         "debuginfo_plist"]
        outputArtifacts: Darwin.lipoOutputArtifacts(product, inputs, "dynamiclibrary", "dll")

        prepare: Darwin.prepareLipo.apply(Darwin, arguments)
    }

    Rule {
        condition: enableAggregationRules
        inputsFromDependencies: ["staticlibrary"]
        multiplex: true

        outputFileTags: ["bundle.input", "staticlibrary", "primary"]
        outputArtifacts: Darwin.lipoOutputArtifacts(product, inputs, "staticlibrary")

        prepare: Darwin.prepareLipo.apply(Darwin, arguments)
    }

    Rule {
        condition: qbs.targetOS.contains("darwin")
        multiplex: true

        Artifact {
            filePath: product.name + "-cpp-Info.plist"
            fileTags: ["partial_infoplist"]
        }

        prepare: {
            var cmd = new JavaScriptCommand();
            cmd.silent = true;
            cmd.inputData = product.cpp.defaultInfoPlist;
            cmd.outputFilePath = output.filePath;
            cmd.sourceCode = function() {
                var plist = new PropertyList();
                try {
                    plist.readFromObject(inputData);
                    plist.writeToFile(outputFilePath, "xml1");
                } finally {
                    plist.clear();
                }
            };
            return [cmd];
        }
    }
}