-
Notifications
You must be signed in to change notification settings - Fork 2
/
fastbuild_platforms.lua
345 lines (284 loc) · 9.97 KB
/
fastbuild_platforms.lua
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
--
-- actions/fastbuild/fastbuild_platforms.lua
-- Extend the existing exporters with support for FASTBuild
-- Copyright (c) 2017-2017 Daniel Penkała
--
local p = premake
local project = p.project
local fastbuild = p.fastbuild
--
-- Mapping tables from Premake systems and architectures to FASTBuild
-- identifiers. Broken out as tables so new values can be pushed in by
-- add-ons.
--
fastbuild.elements = { }
fastbuild.elements.architectures =
{
x86 = "x86",
x86_64 = "x64",
x64 = "x64",
}
local function architecture(system, arch)
return fastbuild.elements.architectures[arch]
end
--
-- Translate the system and architecture settings from a configuration
-- into a corresponding Visual Studio identifier. If no settings are
-- found in the configuration, a default value is returned, based on
-- the project settings.
--
-- @param cfg
-- The configuration to translate.
-- @param win32
-- If true, enables the "Win32" symbol. If false, uses "x86" instead.
-- @return
-- A Visual Studio architecture identifier.
--
function fastbuild.archFromConfig(cfg, win32)
local isnative = project.isnative(cfg.project)
local arch = architecture(cfg.system, cfg.architecture)
if not arch then
arch = isnative and "x86" or error("Invalid architecture '" .. arch .. "'!")
end
return arch
end
--
-- Attempt to translate a platform identifier into a corresponding
-- Visual Studio architecture identifier.
--
-- @param platform
-- The platform identifier to translate.
-- @return
-- A Visual Studio architecture identifier, or nil if no mapping
-- could be made.
--
function fastbuild.archFromPlatform(platform)
local system = p.api.checkValue(p.fields.system, platform)
local arch = p.api.checkValue(p.fields.architecture, platform)
return architecture(system, arch or platform:lower())
end
---
-- Assemble the list of links just the way Visual Studio likes them.
--
-- @param cfg
-- The active configuration.
-- @param explicit
-- True to explicitly include sibling project libraries; if false Visual
-- Studio's default implicit linking will be used.
-- @return
-- The list of linked libraries, ready to be used in Visual Studio's
-- AdditionalDependencies element.
---
function fastbuild.getLinks(cfg, explicit)
error("Not implemented")
return p.tools.msc.getlinks(cfg, not explicit)
end
--
-- Return true if the configuration kind is one of "Makefile" or "None". The
-- latter is generated like a Makefile project and excluded from the solution.
--
function fastbuild.isMakefile(cfg)
return (cfg.kind == p.MAKEFILE or cfg.kind == p.NONE)
end
--
-- If a dependency of a project configuration is excluded from that particular
-- build configuration or platform, Visual Studio will still try to link it.
-- This function detects that case, so that the individual actions can work
-- around it by switching to external linking.
--
-- @param cfg
-- The configuration to test.
-- @return
-- True if the configuration excludes one or more dependencies.
--
function fastbuild.needsExplicitLink(cfg)
error("To be checked")
if not cfg._needsExplicitLink then
local ex = cfg.flags.NoImplicitLink
if not ex then
local prjdeps = project.getdependencies(cfg.project, "linkOnly")
local cfgdeps = config.getlinks(cfg, "dependencies", "object")
ex = #prjdeps ~= #cfgdeps
end
cfg._needsExplicitLink = ex
end
return cfg._needsExplicitLink
end
---
-- Prepare a path value for output in a Visual Studio project or solution.
-- Converts path separators to backslashes, and makes relative to the project.
--
-- @param cfg
-- The project or configuration which contains the path.
-- @param value
-- The path to be prepared.
-- @return
-- The prepared path.
---
function fastbuild.path(cfg, value)
cfg = cfg.project or cfg
local dirs = path.translate(project.getrelative(cfg, value))
if type(dirs) == 'table' then
dirs = table.filterempty(dirs)
end
return dirs
end
--
-- Returns the Visual Studio project configuration identifier corresponding
-- to the given Premake configuration.
--
-- @param cfg
-- The configuration to query.
-- @param arch
-- An optional architecture identifier, to override the configuration.
-- @return
-- A project configuration identifier of the form
-- <project platform name>|<architecture>.
--
function fastbuild.projectConfig(cfg, arch)
local platform = fastbuild.projectPlatform(cfg)
local architecture = arch or fastbuild.archFromConfig(cfg, true)
return platform .. "_" .. architecture
end
--
-- Returns the full, absolute path to the Visual Studio project file
-- corresponding to a particular project object.
--
-- @param prj
-- The project object.
-- @return
-- The absolute path to the corresponding Visual Studio project file.
--
function fastbuild.projectfile(prj)
local extension = ".prj.bff"
return p.filename(prj, extension)
end
--
-- Returns a project configuration name corresponding to the given
-- Premake configuration. This is just the solution build configuration
-- and platform identifiers concatenated.
--
function fastbuild.projectPlatform(cfg)
local platform = cfg.platform
if platform then
local pltarch = fastbuild.archFromPlatform(cfg.platform) or platform
local cfgarch = fastbuild.archFromConfig(cfg)
if pltarch == cfgarch then
platform = nil
end
end
if platform then
return cfg.buildcfg .. " " .. platform
else
return cfg.buildcfg
end
end
--
-- Determine the appropriate Visual Studio platform identifier for a
-- solution-level configuration.
--
-- @param cfg
-- The configuration to be identified.
-- @return
-- A corresponding Visual Studio platform identifier.
--
function fastbuild.solutionPlatform(cfg)
local platform = cfg.platform
-- if a platform is specified use it, translating to the corresponding
-- Visual Studio identifier if appropriate
local platarch
if platform then
platform = fastbuild.archFromPlatform(platform) or platform
-- Value for 32-bit arch is different depending on whether this solution
-- contains C++ or C# projects or both
if platform ~= "x86" then
return platform
end
end
-- scan the contained projects to identify the platform
local hasnative = false
local hasnet = false
local slnarch
for prj in p.workspace.eachproject(cfg.workspace) do
hasnative = hasnative or project.isnative(prj)
hasnet = hasnet or project.isdotnet(prj)
-- get a VS architecture identifier for this project
local prjcfg = project.getconfig(prj, cfg.buildcfg, cfg.platform)
if prjcfg then
local prjarch = fastbuild.archFromConfig(prjcfg)
if not slnarch then
slnarch = prjarch
elseif slnarch ~= prjarch then
slnarch = "Mixed Platforms"
end
end
end
if platform then
return iif(hasnet, "x86", "Win32")
elseif slnarch then
return iif(slnarch == "x86" and not hasnet, "Win32", slnarch)
elseif hasnet and hasnative then
return "Mixed Platforms"
elseif hasnet then
return "Any CPU"
else
return "Win32"
end
end
--
-- Attempt to determine an appropriate Visual Studio architecture identifier
-- for a solution configuration.
--
-- @param cfg
-- The configuration to query.
-- @return
-- A best guess at the corresponding Visual Studio architecture identifier.
--
function fastbuild.solutionArch(cfg)
local hasnative = false
local hasdotnet = false
-- if the configuration has a platform identifier, use that as default
local arch = cfg.platform
-- if the platform identifier matches a known system or architecture,
--
for prj in p.workspace.eachproject(cfg.workspace) do
hasnative = hasnative or project.isnative(prj)
-- hasnet = hasnet or project.isdotnet(prj)
assert(hasnative, "Only native projects are supported!")
-- if hasnative and hasdotnet then
-- return "Mixed Platforms"
-- end
if not arch then
local prjcfg = project.getconfig(prj, cfg.buildcfg, cfg.platform)
if prjcfg then
if prjcfg.architecture then
arch = fastbuild.archFromConfig(prjcfg)
end
end
end
end
-- use a default if no other architecture was specified
arch = arch or iif(hasnative, "Win32", "Any CPU")
return arch
end
--
-- Returns the Visual Studio solution configuration identifier corresponding
-- to the given Premake configuration.
--
-- @param cfg
-- The configuration to query.
-- @return
-- A solution configuration identifier of the format BuildCfg|Platform,
-- corresponding to the Premake values of the same names. If no platform
-- was specified by the script, the architecture is used instead.
--
function fastbuild.solutionConfig(cfg)
local platform = cfg.platform
-- if no platform name was specified, use the architecture instead;
-- since architectures are defined in the projects and not at the
-- solution level, need to poke around to figure this out
if not platform then
platform = fastbuild.solutionArch(cfg)
end
return string.format("%s|%s", cfg.buildcfg, platform)
end