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
|
import qbs.base 1.0
import qbs.fileinfo 1.0 as FileInfo
import '../utils.js' as ModUtils
import 'msvc.js' as MSVC
CppModule {
condition: qbs.hostOS == 'windows' && qbs.targetOS == 'windows' && qbs.toolchain == 'msvc'
id: module
defines: ['UNICODE', 'WIN32']
warningLevel: "default"
property bool generateManifestFiles: true
property string toolchainInstallPath: "UNKNOWN"
property string windowsSDKPath: "UNKNOWN"
property string architecture: "x86"
property int responseFileThreshold: 32000
setupBuildEnvironment: {
var v = new ModUtils.EnvironmentVariable("INCLUDE", ";", true)
v.prepend(toolchainInstallPath + "/VC/ATLMFC/INCLUDE")
v.prepend(toolchainInstallPath + "/VC/INCLUDE")
v.prepend(windowsSDKPath + "/include")
v.set()
if (architecture == 'x86') {
v = new ModUtils.EnvironmentVariable("PATH", ";", true)
v.prepend(toolchainInstallPath + "/Common7/IDE")
v.prepend(toolchainInstallPath + "/VC/bin")
v.prepend(toolchainInstallPath + "/Common7/Tools")
v.set()
v = new ModUtils.EnvironmentVariable("LIB", ";", true)
v.prepend(toolchainInstallPath + "/VC/ATLMFC/LIB")
v.prepend(toolchainInstallPath + "/VC/LIB")
v.prepend(windowsSDKPath + "/lib")
v.set()
} else if (architecture == 'x86_64') {
v = new ModUtils.EnvironmentVariable("PATH", ";", true)
v.prepend(toolchainInstallPath + "/Common7/IDE")
v.prepend(toolchainInstallPath + "/VC/bin/amd64")
v.prepend(toolchainInstallPath + "/Common7/Tools")
v.set()
v = new ModUtils.EnvironmentVariable("LIB", ";", true)
v.prepend(toolchainInstallPath + "/VC/ATLMFC/LIB/amd64")
v.prepend(toolchainInstallPath + "/VC/LIB/amd64")
v.prepend(windowsSDKPath + "/lib/x64")
v.set()
}
}
Artifact {
// This adds the filename in precompiledHeader to the set of source files.
// If its already in there, then this makes sure it has the right file tag.
condition: precompiledHeader != null
fileName: precompiledHeader
fileTags: ["hpp_pch"]
}
Rule {
id: pchCompiler
inputs: ["hpp_pch"]
Artifact {
fileTags: ['obj']
// ### make the object file dir overridable
fileName: ".obj/" + product.name + "/" + input.baseName + '.obj'
}
Artifact {
fileTags: ['c++_pch']
// ### make the object file dir overridable
fileName: ".obj/" + product.name + "/" + product.name + '.pch'
}
TransformProperties {
property var defines: ModUtils.appendAll(input, 'defines')
property var includePaths: ModUtils.appendAll(input, 'includePaths')
property var compilerFlags: ModUtils.appendAll(input, 'compilerFlags')
}
prepare: {
return MSVC.prepareCompiler(product, input, outputs)
}
}
Rule {
id: compiler
inputs: ["cpp", "c"]
explicitlyDependsOn: ["c++_pch"]
Artifact {
fileTags: ['obj']
// ### make the object file dir overridable
fileName: ".obj/" + product.name + "/" + input.baseDir + "/" + input.baseName + ".obj"
}
TransformProperties {
property var defines: ModUtils.appendAll(input, 'defines')
property var includePaths: ModUtils.appendAll(input, 'includePaths')
property var compilerFlags: ModUtils.appendAll(input, 'compilerFlags')
}
prepare: {
return MSVC.prepareCompiler(product, input, outputs, defines, includePaths, compilerFlags)
}
}
Rule {
id: applicationLinker
multiplex: true
inputs: ['obj']
usings: ['staticlibrary', 'dynamiclibrary_import']
Artifact {
fileTags: ["application"]
fileName: product.destinationDirectory + "/" + product.name + ".exe"
}
TransformProperties {
property var libraryPaths: ModUtils.appendAll(product, 'libraryPaths')
property var dynamicLibraries: ModUtils.appendAllFromArtifacts(product, inputs.dynamiclibrary_import, 'cpp', 'dynamicLibraries')
property var staticLibraries: ModUtils.appendAllFromArtifacts(product, (inputs.staticlibrary || []).concat(inputs.obj), 'cpp', 'staticLibraries')
}
prepare: {
return MSVC.prepareLinker(product, inputs, outputs, libraryPaths, dynamicLibraries, staticLibraries)
}
}
Rule {
id: dynamicLibraryLinker
multiplex: true
inputs: ['obj']
usings: ['staticlibrary', 'dynamiclibrary_import']
Artifact {
fileTags: ["dynamiclibrary"]
fileName: product.destinationDirectory + "/" + product.name + ".dll"
}
Artifact {
fileTags: ["dynamiclibrary_import"]
fileName: product.destinationDirectory + "/" + product.name + "_imp.lib"
}
TransformProperties {
property var libraryPaths: ModUtils.appendAll(product, 'libraryPaths')
property var dynamicLibraries: ModUtils.appendAll(product, 'dynamicLibraries')
property var staticLibraries: ModUtils.appendAllFromArtifacts(product, (inputs.staticlibrary || []).concat(inputs.obj), 'cpp', 'staticLibraries')
}
prepare: {
return MSVC.prepareLinker(product, inputs, outputs, libraryPaths, dynamicLibraries, staticLibraries)
}
}
Rule {
id: libtool
multiplex: true
inputs: ["obj"]
usings: ["staticlibrary"]
Artifact {
fileTags: ["staticlibrary"]
fileName: product.destinationDirectory + "/" + product.name + ".lib"
cpp.staticLibraries: {
var result = []
for (var i in inputs.staticlibrary) {
var lib = inputs.staticlibrary[i]
result.push(lib.fileName)
var impliedLibs = ModUtils.appendAll(lib, 'staticLibraries')
result.concat(impliedLibs)
}
return result
}
}
prepare: {
var toolchainInstallPath = product.module.toolchainInstallPath
var args = ['/nologo']
var nativeOutputFileName = FileInfo.toWindowsSeparators(output.fileName)
args.push('/OUT:' + nativeOutputFileName)
for (var i in inputs.obj) {
var fileName = FileInfo.toWindowsSeparators(inputs.obj[i].fileName)
args.push(fileName)
}
var is64bit = (product.module.architecture == "x86_64")
var linkerPath = toolchainInstallPath + '/VC/bin/'
if (is64bit)
linkerPath += 'amd64/'
linkerPath += 'lib.exe'
var cmd = new Command(linkerPath, args)
cmd.description = 'creating ' + FileInfo.fileName(output.fileName)
cmd.highlight = 'linker';
cmd.workingDirectory = FileInfo.path(output.fileName)
cmd.responseFileThreshold = product.module.responseFileThreshold
cmd.responseFileUsagePrefix = '@';
return cmd;
}
}
}
|