aboutsummaryrefslogtreecommitdiffstats
path: root/share/qbs/modules/cpp/DarwinGCC.qbs
blob: e5b76003a091e8d05e6cea8ced06322b1453cedc (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
import qbs 1.0
import '../utils.js' as ModUtils
import 'darwin-tools.js' as Tools

UnixGCC {
    condition: false

    compilerDefines: ["__GNUC__", "__APPLE__"]
    dynamicLibrarySuffix: ".dylib"

    property var defaultInfoPlist
    property var infoPlist: defaultInfoPlist
    property bool buildDsym: qbs.buildVariant === "release"

    Rule {
        multiplex: true
        inputs: ["qbs"]

        Artifact {
            fileName: product.targetName + ".app/" +
                      (product.moduleProperty("qbs", "targetOS") === "mac" ? "Contents/" : "") +
                      "PkgInfo"
            fileTags: ["pkginfo"]
        }

        prepare: {
            var cmd = new JavaScriptCommand();
            cmd.description = "generating PkgInfo";
            cmd.highlight = "codegen";
            var pkgType = 'APPL';
            var pkgSign = '????';
            var infoPlist = product.moduleProperty("cpp", "infoPList");
            if (infoPlist && infoPlist.hasOwnProperty('CFBundlePackageType'))
                pkgType = infoPlist['CFBundlePackageType'];
            if (infoPlist && infoPlist.hasOwnProperty('CFBundleSignature'))
                pkgSign = infoPlist['CFBundleSignature'];
            cmd.pkgInfo =  pkgType + pkgSign;
            cmd.sourceCode = function() {
                var pkginfo = new TextFile(outputs.pkginfo[0].fileName, TextFile.WriteOnly);
                pkginfo.write(pkgInfo);
                pkginfo.close();
            }
            return cmd;
        }
    }

    Rule {
        multiplex: true
        inputs: ["qbs"]

        Artifact {
            fileName: product.targetName + ".app/" +
                      (product.moduleProperty("qbs", "targetOS") === "mac" ? "Contents/" : "") +
                      "Info.plist"
            fileTags: ["infoplist"]
        }

        prepare: {
            var cmd = new JavaScriptCommand();
            cmd.description = "generating Info.plist";
            cmd.highlight = "codegen";
            cmd.infoPlist = ModUtils.moduleProperty(product, "infoPlist") || {};
            cmd.platformPath = product.moduleProperty("cpp", "platformPath");
            cmd.sourceCode = function() {
                var defaultValues = ModUtils.moduleProperty(product, "defaultInfoPlist");
                var key;
                for (key in defaultValues) {
                    if (defaultValues.hasOwnProperty(key) && !(key in infoPlist))
                        infoPlist[key] = defaultValues[key];
                }

                var process;
                if (platformPath) {
                    process = new Process();
                    process.start("plutil", ["-convert", "json", "-o", "-",
                                             platformPath + "/Info.plist"]);
                    process.waitForFinished();
                    platformInfo = JSON.parse(process.readAll());

                    var additionalProps = platformInfo["AdditionalInfo"];
                    for (key in additionalProps) {
                        if (additionalProps.hasOwnProperty(key) && !(key in infoPlist)) // override infoPlist?
                            infoPlist[key] = defaultValues[key];
                    }

                    if (product.moduleProperty("qbs", "targetOS") === "ios") {
                        key = "UIDeviceFamily";
                        if (key in platformInfo && !(key in infoPlist))
                            infoPlist[key] = platformInfo[key];
                    }
                } else {
                    print("Missing platformPath property");
                }

                process = new Process();
                process.start("sw_vers", ["-buildVersion"]);
                process.waitForFinished();
                infoPlist["BuildMachineOSBuild"] = process.readAll().trim();

                var infoplist = new TextFile(outputs.infoplist[0].fileName, TextFile.WriteOnly);
                infoplist.write(JSON.stringify(infoPlist));
                infoplist.close();

                process = new Process();
                process.start("plutil", ["-convert",
                                        product.moduleProperty("qbs", "targetOS") === "ios"
                                            ? "binary1" : "xml1",
                                        outputs.infoplist[0].fileName]);
                process.waitForFinished();
            }
            return cmd;
        }
    }

    Rule {
        condition: product.moduleProperty("cpp", "buildDsym")
        inputs: ["application"]

        Artifact {
            fileName: input.fileName + ".app.dSYM"
            fileTags: ["dsym"]
        }

        prepare: {
            var cmd = new Command("dsymutil", ["--out=" + outputs.dsym[0].fileName, input.fileName]);
            cmd.description = "generating dsym";
            cmd.highlight = "codegen";
            return cmd;
        }
    }

    Rule {
        multiplex: true
        inputs: {
            var res = ["application", "infoplist", "pkginfo"];
            // if (product.moduleProperty("cpp", "buildDsym")) // should work like that in the future
                res.push("dsym");
            if (product.moduleProperty("qbs", "targetOS") === "ios") {
                res.push("resourcerules");
                // if (ModUtils.moduleProperty(product, "buildIpa")) // ditto
                    res.push("ipa");
            }
            return res;
        }

        Artifact {
            fileName: product.targetName + ".app"
            fileTags: ["applicationbundle"]
        }

        prepare: {
            // This command is intentionally empty; it just lets the user know a bundle has been made
            var cmd = new JavaScriptCommand();
            cmd.description = "creating app bundle";
            cmd.highlight = "codegen";
            return cmd;
        }
    }
}