aboutsummaryrefslogtreecommitdiffstats
path: root/share/qbs/modules/cli/CLIModule.qbs
blob: b9ff259f6d734ea32f6dfe4bcb63204b96afdab7 (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
// base for Common Language Infrastructure modules
import qbs
import qbs.FileInfo
import qbs.ModUtils
import "cli.js" as CLI

Module {
    Depends { name: "bundle" }

    bundle.isBundle: false

    condition: false

    property string warningLevel: 'all' // 'none', 'all'
    property bool treatWarningsAsErrors: false
    property string architecture: "anycpu" // for the CLI this is a much better default than qbs.architecture
    property string optimization: qbs.optimization
    property bool debugInformation: qbs.debugInformation
    property stringList defines
    property stringList platformDefines: qbs.enableDebugCode ? [] : ["NDEBUG"]
    property stringList compilerDefines
    PropertyOptions {
        name: "compilerDefines"
        description: "preprocessor macros that are defined when using this particular compiler"
    }

    property pathList libraryPaths
    property string csharpCompilerName
    property string csharpCompilerPath: FileInfo.joinPaths(toolchainInstallPath, csharpCompilerName)
    property string vbCompilerName
    property string vbCompilerPath: FileInfo.joinPaths(toolchainInstallPath, vbCompilerName)
    property string fsharpCompilerName
    property string fsharpCompilerPath: FileInfo.joinPaths(toolchainInstallPath, fsharpCompilerName)
    property string resgenName: "resgen"
    property string resgenPath: FileInfo.joinPaths(toolchainInstallPath, resgenName)
    property string dynamicLibrarySuffix: ".dll"
    property string executableSuffix: ".exe"
    property string netmoduleSuffix: ".netmodule"
    property string debugInfoSuffix
    property stringList dynamicLibraries // list of names, will be linked with /reference:name
    property stringList netmodules // list of netmodule files, will be linked with /addmodule:name

    property bool generateManifestFile: true

    property string toolchainInstallPath

    property stringList compilerFlags
    PropertyOptions {
        name: "compilerFlags"
        description: "additional compiler flags"
    }

    // Platform properties. Those are intended to be set by the toolchain setup
    // and are prepended to the corresponding user properties.
    property stringList platformCompilerFlags

    FileTagger {
        patterns: ["*.cs", "*.CS"]
        fileTags: ["cli.csharp"]
    }

    FileTagger {
        patterns: ["*.vb", "*.VB"]
        fileTags: ["cli.vb"]
    }

    FileTagger {
        patterns: ["*.fs", "*.FS"]
        fileTags: ["cli.fsharp"]
    }

    FileTagger {
        patterns: ["*.fsi", "*.FSI"]
        fileTags: ["cli.fsharp_signature"]
    }

    FileTagger {
        patterns: ["*.resx", "*.RESX"]
        fileTags: ["cli.resx"]
    }

    validate: {
        var validator = new ModUtils.PropertyValidator("cli");
        validator.setRequiredProperty("toolchainInstallPath", toolchainInstallPath);
        validator.validate();
    }

    setupBuildEnvironment: {
        var v = new ModUtils.EnvironmentVariable("PATH", qbs.pathListSeparator,
                                                 qbs.hostOS.contains("windows"));
        v.prepend(toolchainInstallPath);
        v.set();
    }

    Rule {
        id: cliApplication
        multiplex: true
        inputs: ["cli.csharp", "cli.vb", "cli.fsharp"]
        inputsFromDependencies: ["cli.netmodule", "dynamiclibrary", "cli.resources"]

        Artifact {
            fileTags: ["application"]
            filePath: FileInfo.joinPaths(product.destinationDirectory,
                                         product.targetName
                                         + product.moduleProperty(product.moduleName,
                                                                  "executableSuffix"))
        }

        Artifact {
            fileTags: ["debuginfo"]
            filePath: FileInfo.joinPaths(product.destinationDirectory,
                                         product.targetName
                                         + product.moduleProperty(product.moduleName,
                                                                  "debugInfoSuffix"))
        }

        prepare: {
            return CLI.prepareCompiler(product, inputs, outputs.application[0]);
        }
    }

    Rule {
        id: cliDynamicLibrary
        multiplex: true
        inputs: ["cli.csharp", "cli.vb", "cli.fsharp"]
        inputsFromDependencies: ["cli.netmodule", "dynamiclibrary", "cli.resources"]

        Artifact {
            fileTags: ["dynamiclibrary"]
            filePath: FileInfo.joinPaths(product.destinationDirectory,
                                         product.targetName
                                         + product.moduleProperty(product.moduleName,
                                                                  "dynamicLibrarySuffix"))
        }

        Artifact {
            fileTags: ["debuginfo"]
            filePath: FileInfo.joinPaths(product.destinationDirectory,
                                         product.targetName
                                         + product.moduleProperty(product.moduleName,
                                                                  "debugInfoSuffix"))
        }

        prepare: {
            return CLI.prepareCompiler(product, inputs, outputs.dynamiclibrary[0]);
        }
    }

    Rule {
        id: netmodule
        multiplex: true
        inputs: ["cli.csharp", "cli.vb", "cli.fsharp"]
        inputsFromDependencies: ["cli.netmodule", "dynamiclibrary", "cli.resources"]

        Artifact {
            fileTags: ["cli.netmodule"]
            filePath: FileInfo.joinPaths(product.destinationDirectory,
                                         product.targetName
                                         + product.moduleProperty(product.moduleName,
                                                                  "netmoduleSuffix"))
        }

        Artifact {
            fileTags: ["debuginfo"]
            filePath: FileInfo.joinPaths(product.destinationDirectory,
                                         product.targetName
                                         + product.moduleProperty(product.moduleName,
                                                                  "debugInfoSuffix"))
        }

        prepare: {
            return CLI.prepareCompiler(product, inputs, outputs["cli.netmodule"][0]);
        }
    }

    Rule {
        inputs: ["cli.resx"]

        Artifact {
            fileTags: ["cli.resources"]
            filePath: FileInfo.joinPaths(product.destinationDirectory,
                                         input.completeBaseName + ".resources")
        }

        prepare: {
            var args = [ input.filePath, output.filePath ];
            var cmd = new Command(ModUtils.moduleProperty(product, "resgenPath"), args);
            cmd.description = "building " + input.fileName;
            cmd.highlight = "compiler";
            cmd.workingDirectory = FileInfo.path(output.filePath);
            return cmd;
        }
    }
}