-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvstool.lua
More file actions
414 lines (361 loc) · 9.94 KB
/
Copy pathvstool.lua
File metadata and controls
414 lines (361 loc) · 9.94 KB
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
--
-- Create an vstool namespace to isolate the additions
--
local p = premake
p.modules.vstool = {}
local m = p.modules.vstool
m._VERSION = "0.0.1"
local sln2005 = p.vstudio.sln2005
local vc2010 = p.vstudio.vc2010
local vstudio = p.vstudio
local project = p.project
local config = p.config
--
-- Helpers to see if we're dealing with a vs-tool action.
--
function m.isgcc(cfg)
return cfg.toolset == "gcc"
end
function m.isclang(cfg)
return cfg.toolset == "clang"
end
function m.isgccorclang(cfg)
return m.isgcc(cfg) or m.isclang(cfg)
end
function m.isvstool(cfg)
return _ACTION:startswith("vs") and m.isgccorclang(cfg)
end
--
-- Add vs-tool tools to vstudio actions.
--
if vstudio.vs2010_architectures ~= nil then
vstudio.vs2010_architectures.clang = "Clang"
vstudio.vs2010_architectures.mingw = "MinGW"
end
premake.override(vstudio, "archFromConfig", function(oldfn, cfg, win32)
if _ACTION:startswith("vs") then
if cfg.toolset == "gcc" then
return "MinGW"
elseif cfg.toolset == "clang" then
return "Clang"
end
end
return oldfn(cfg, win32)
end)
--
-- Extend configurationProperties.
--
premake.override(vc2010, "platformToolset", function(orig, cfg)
if m.isvstool(cfg) then
-- is there a reason to write this? default is fine.
-- local map = { gcc="mingw", clang="clang" }
-- _p(2,'<PlatformToolset>%s</PlatformToolset>', map[cfg.toolset])
else
orig(cfg)
end
end)
premake.override(vc2010, "configurationType", function(oldfn, cfg)
if m.isvstool(cfg) then
if cfg.kind then
local types = {
SharedLib = "DynamicLibrary",
StaticLib = "StaticLibrary",
ConsoleApp = "Application",
WindowedApp = "Application",
}
local type = types[cfg.kind]
if not type then
error("Invalid 'kind' for vs-tool: " .. cfg.kind, 2)
else
if m.isclang(cfg) and cfg.kind == "StaticLib" then
-- clang has some options...
if cfg.flags.OutputBC then
type = "StaticLibraryBc"
else
local libFormat = { [".o"]="StaticLibrary", [".a"]="StaticLibraryA", [".lib"]="StaticLibraryLib" }
type = libFormat[cfg.staticlibformat or ".lib"]
end
end
_p(2,'<ConfigurationType>%s</ConfigurationType>', type)
end
end
else
oldfn(cfg)
end
end)
--
-- Extend outputProperties.
--
premake.override(vc2010.elements, "outputProperties", function(oldfn, cfg)
local elements = oldfn(cfg)
if cfg.kind ~= p.UTILITY then
if m.isclang(cfg) then
elements = table.join(elements, {
m.clangPath,
})
elseif m.isgcc(cfg) then
elements = table.join(elements, {
m.mingwPath,
})
end
end
return elements
end)
function m.clangPath(cfg)
if cfg.clangpath ~= nil then
-- local dirs = project.getrelative(cfg.project, includedirs)
-- dirs = path.translate(table.concat(fatalwarnings, ";"))
_p(2,'<ClangPath>%s</ClangPath>', cfg.clangpath)
end
end
function m.mingwPath(cfg)
if cfg.mingwpath ~= nil then
-- local dirs = project.getrelative(cfg.project, includedirs)
-- dirs = path.translate(table.concat(fatalwarnings, ";"))
_p(2,'<MinGWPath>%s</MinGWPath>', cfg.mingwpath)
end
end
premake.override(vc2010, "targetExt", function(oldfn, cfg)
if m.isgccorclang(cfg) then
local ext = cfg.buildtarget.extension
if ext ~= "" then
_x(2,'<TargetExt>%s</TargetExt>', ext)
end
else
oldfn(cfg)
end
end)
--
-- Extend clCompile.
--
premake.override(vc2010.elements, "clCompile", function(oldfn, cfg)
local elements = oldfn(cfg)
if m.isvstool(cfg) then
elements = table.join(elements, {
m.debugInformation,
m.enableWarnings,
m.languageStandard,
m.generateLlvmBc,
m.targetArch,
m.instructionSet,
})
end
return elements
end)
function m.debugInformation(cfg)
-- TODO: support these
-- NoDebugInfo
-- LimitedDebugInfo
-- FullDebugInfo
_p(3,'<GenerateDebugInformation>%s</GenerateDebugInformation>', iif(cfg.flags.Symbols, "FullDebugInfo", "NoDebugInfo"))
end
function m.enableWarnings(cfg)
if #cfg.enablewarnings > 0 then
_x(3,'<EnableWarnings>%s</EnableWarnings>', table.concat(cfg.enablewarnings, ";"))
end
end
function m.languageStandard(cfg)
local map = {
c90 = "LanguageStandardC89",
gnu90 = "LanguageStandardGnu89",
c94 = "LanguageStandardC94",
c99 = "LanguageStandardC99",
gnu99 = "LanguageStandardGnu99",
-- ["c++98"] = "LanguageStandardCxx03",
-- ["gnu++98"] = "LanguageStandardGnu++98",
-- ["c++11"] = "LanguageStandardC++11",
-- ["gnu++11"] = "LanguageStandardGnu++11"
}
if cfg.languagestandard and map[cfg.languagestandard] then
_p(3,'<LanguageStandardMode>%s</LanguageStandardMode>', map[cfg.languagestandard])
end
end
function m.generateLlvmBc(cfg)
if m.isclang(cfg) then
if cfg.flags.OutputBC then
_p(3,'<GenerateLLVMByteCode>true</GenerateLLVMByteCode>')
end
end
end
function m.targetArch(cfg)
if m.isvstool(cfg) then
if cfg.architecture == "x86" then
_p(3,'<TargetArchitecture>x86</TargetArchitecture>')
elseif cfg.architecture == "x86_64" then
_p(3,'<TargetArchitecture>x64</TargetArchitecture>')
elseif cfg.architecture then
error("Invalid 'architecture' for vs-tool: " .. cfg.architecture, 2)
end
end
end
function m.instructionSet(cfg)
if m.isvstool(cfg) then
local map = {
MMX="MMX",
SSE="SSE",
SSE2="SSE2",
SSE3="SSE3",
SSSE3="SSSE3",
SSE4="SSE4",
["SSE4.1"]="SSE4.1",
["SSE4.2"]="SSE4.2",
AVX="AVX",
AVX2="AVX2",
}
if map[cfg.vectorextensions] ~= nil then
_p(3,'<InstructionSet>%s</InstructionSet>', map[cfg.vectorextensions])
end
end
end
premake.override(vc2010, "disableSpecificWarnings", function(oldfn, cfg)
if m.isvstool(cfg) then
if #cfg.disablewarnings > 0 then
local warnings = table.concat(cfg.disablewarnings, ";")
warnings = premake.esc(warnings) .. ";%%(DisableWarnings)"
vc2010.element('DisableWarnings', condition, warnings)
end
else
oldfn(cfg)
end
end)
premake.override(vc2010, "treatSpecificWarningsAsErrors", function(oldfn, cfg)
if m.isvstool(cfg) then
if #cfg.fatalwarnings > 0 then
local fatal = table.concat(cfg.fatalwarnings, ";")
fatal = premake.esc(fatal) .. ";%%(SpecificWarningsAsErrors)"
vc2010.element('SpecificWarningsAsErrors', condition, fatal)
end
else
oldfn(cfg)
end
end)
premake.override(vc2010, "undefinePreprocessorDefinitions", function(oldfn, cfg, undefines, escapeQuotes, condition)
if m.isvstool(cfg) then
if #undefines > 0 then
undefines = table.concat(undefines, ";")
if escapeQuotes then
undefines = undefines:gsub('"', '\\"')
end
undefines = premake.esc(undefines) .. ";%%(PreprocessorUndefinitions)"
vc2010.element('PreprocessorUndefinitions', condition, undefines)
end
else
oldfn(cfg, undefines, escapeQuotes, condition)
end
end)
premake.override(vc2010, "warningLevel", function(oldfn, cfg)
if m.isgccorclang(cfg) then
local map = { Off = "DisableAllWarnings", Extra = "AllWarnings" }
if map[cfg.warnings] ~= nil then
_p(3,'<Warnings>%s</Warnings>', map[cfg.warnings])
end
else
oldfn(cfg)
end
end)
premake.override(vc2010, "treatWarningAsError", function(oldfn, cfg)
if m.isgccorclang(cfg) then
if cfg.flags.FatalCompileWarnings and cfg.warnings ~= premake.OFF then
_p(3,'<WarningsAsErrors>true</WarningsAsErrors>')
end
else
oldfn(cfg)
end
end)
premake.override(vc2010, "optimization", function(oldfn, cfg, condition)
if m.isgccorclang(cfg) then
local map = { Off="O0", On="O2", Debug="O0", Full="O3", Size="Os", Speed="O3" }
local value = map[cfg.optimize]
if value or not condition then
value = value or "O0"
if m.isclang(cfg) and cfg.flags.LinkTimeOptimization and value ~= "O0" then
value = "O4"
end
vc2010.element('OptimizationLevel', condition, value)
end
else
oldfn(cfg, condition)
end
end)
premake.override(vc2010, "exceptionHandling", function(oldfn, cfg)
-- ignored for vs-tool
if not m.isvstool(cfg) then
oldfn(cfg)
end
end)
premake.override(vc2010, "additionalCompileOptions", function(oldfn, cfg, condition)
if m.isvstool(cfg) then
m.additionalOptions(cfg, condition)
end
return oldfn(cfg, condition)
end)
-- these should be silenced for vs-tool based toolsets
premake.override(vc2010, "debugInformationFormat", function(oldfn, cfg)
if not m.isgccorclang(cfg) then
oldfn(cfg)
end
end)
premake.override(vc2010, "functionLevelLinking", function(oldfn, cfg)
if not m.isgccorclang(cfg) then
oldfn(cfg)
end
end)
premake.override(vc2010, "intrinsicFunctions", function(oldfn, cfg)
if not m.isgccorclang(cfg) then
oldfn(cfg)
end
end)
premake.override(vc2010, "minimalRebuild", function(oldfn, cfg)
if not m.isgccorclang(cfg) then
oldfn(cfg)
end
end)
premake.override(vc2010, "omitFramePointers", function(oldfn, cfg)
if not m.isgccorclang(cfg) then
oldfn(cfg)
end
end)
premake.override(vc2010, "stringPooling", function(oldfn, cfg)
if not m.isgccorclang(cfg) then
oldfn(cfg)
end
end)
premake.override(vc2010, "runtimeLibrary", function(oldfn, cfg)
if not m.isgccorclang(cfg) then
oldfn(cfg)
end
end)
premake.override(vc2010, "bufferSecurityCheck", function(oldfn, cfg)
if not m.isgccorclang(cfg) then
oldfn(cfg)
end
end)
--
-- Extend Link.
--
premake.override(vc2010, "generateDebugInformation", function(oldfn, cfg)
-- Note: vs-tool specifies the debug info in the clCompile section
if not m.isvstool(cfg) then
oldfn(cfg)
end
end)
premake.override(vc2010, "entryPointSymbol", function(oldfn, cfg)
if not m.isgccorclang(cfg) then
oldfn(cfg)
end
end)
--
-- Add options unsupported by vs-tool vs-tool UI to <AdvancedOptions>.
--
function m.additionalOptions(cfg, condition)
local function alreadyHas(t, key)
for _, k in ipairs(t) do
if string.find(k, key) then
return true
end
end
return false
end
-- Eg: table.insert(cfg.buildoptions, "-option")
end
return m