-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpremake5.lua
More file actions
453 lines (366 loc) · 12.7 KB
/
Copy pathpremake5.lua
File metadata and controls
453 lines (366 loc) · 12.7 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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
dofile("pal_config.lua")
targetDir = "%{wks.location}/bin/%{cfg.buildcfg}"
objDir = "%{wks.location}/build"
workspaceName = "PALWorkspace"
compilerPath = ""
intellisenseMode = ""
debuggerPath = ""
gccBasePath = ""
local function getCommandOutput(cmd)
local result, exitCode = os.outputof(cmd)
if result then
result = result:gsub("[\r\n%s]+$", "")
if (result ~= "") then
result = result:gsub("\\", "/")
return result
else
return nil
end
end
return nil
end
local function removeDuplicates(list)
local seen = {}
local out = {}
for _, v in ipairs(list) do
if not seen[v] then
seen[v] = true
table.insert(out, v)
end
end
return out
end
local function generateVscodeProperties()
print("\n=======================================================")
print("Generating .vscode/c_cpp_properties.json")
local prjDefines = {}
local prjIncludes = {}
local workspace = premake.global.getWorkspace(workspaceName)
for prj in premake.workspace.eachproject(workspace) do
for _, path in ipairs(prj.includedirs or {}) do
table.insert(prjIncludes, path)
end
for _, define in ipairs(prj.defines or {}) do
table.insert(prjDefines, define)
end
end
-- remove duplicates
prjIncludes = removeDuplicates(prjIncludes)
prjDefines = removeDuplicates(prjDefines)
-- write to file
os.mkdir(".vscode") -- ensure .vscode directory exists
local file = io.open(".vscode/c_cpp_properties.json", "w")
if file then
file:write('{\n')
file:write(' "configurations": [\n')
file:write(' {\n')
file:write(string.format(' "name": "%s",\n', workspaceName))
-- includes
file:write(' "includePath": [\n')
for i, dir in ipairs(prjIncludes) do
file:write(string.format(' "%s"%s\n', dir, i < #prjIncludes and "," or ""))
end
file:write(' ],\n')
-- defines
file:write(' "defines": [\n')
for i, define in ipairs(prjDefines) do
file:write(string.format(' "%s"%s\n', define, i < #prjDefines and "," or ""))
end
file:write(' ],\n')
file:write(string.format(' "compilerPath": "%s",\n', compilerPath))
file:write(string.format(' "intelliSenseMode": "%s",\n', intellisenseMode))
file:write(' "cStandard": "c99"\n')
file:write(' }\n')
file:write(' ],\n')
file:write(' "version": 4\n')
file:write('}\n')
file:close()
end
end
local function writeTasksConfiguration(file, actionType)
local name = ""
local isDefault = "false"
local command = ""
if actionType == "buildDebug" then
name = "build debug"
command = "make all config=debug"
isDefault = "true"
elseif actionType == "buildRelease" then
name = "build release"
command = "make all config=release"
elseif actionType == "cleanDebug" then
name = "clean debug"
command = "make clean config=debug"
elseif actionType == "cleanRelease" then
name = "clean release"
command = "make clean config=release"
end
file:write(" {\n")
file:write(' "type": "shell",\n')
file:write(string.format(' "label": "%s %s",\n', workspaceName, name))
file:write(string.format(' "command": "%s",\n', command))
file:write(' "options": {\n')
file:write(' "cwd": "${workspaceFolder}"\n')
file:write(' },\n')
file:write(' "problemMatcher": [\n')
file:write(' "$gcc",\n')
file:write(' ],\n')
file:write(' "group": {\n')
file:write(' "kind": "build",\n')
file:write(string.format(' "isDefault": %s\n', isDefault))
file:write(' }\n')
end
local function generateTasksJson()
print("\n=======================================================")
print("Generating .vscode/tasks.json")
local file = io.open(".vscode/tasks.json", "w")
if file then
file:write('{\n')
file:write(' "tasks": [\n')
writeTasksConfiguration(file, "buildDebug")
file:write(" },\n")
file:write('\n')
writeTasksConfiguration(file, "buildRelease")
file:write(" },\n")
file:write('\n')
-- clean configurations
writeTasksConfiguration(file, "cleanDebug")
file:write(" },\n")
file:write('\n')
writeTasksConfiguration(file, "cleanRelease")
file:write(" }\n")
file:write(" ],\n")
file:write(' "version": "2.0.0"\n')
file:write("}\n")
file:close()
end
end
local function writeLaunchConfiguration(file, app, isDebug)
local name = ""
local preLaunchTask = ""
local dir = ""
local cwd = ""
if isDebug then
name = "launch debug"
preLaunchTask = "build debug"
dir = "Debug"
else
name = "launch release"
preLaunchTask = "build release"
dir = "Release"
end
if app == "tests" then
cwd = "tests"
if isDebug then
name = "launch tests debug"
else
name = "launch tests release"
end
if os.target() == "windows" then
program = "tests.exe"
else
program = "tests"
end
else
cwd = "tools/abi_dump"
if isDebug then
name = "launch abi-dump debug"
else
name = "launch abi-dump release"
end
if os.target() == "windows" then
program = "abi-dump.exe"
else
program = "abi-dump"
end
end
file:write(" {\n")
file:write(string.format(' "name": "%s %s",\n', workspaceName, name))
file:write(' "type": "cppdbg",\n')
file:write(' "request": "launch",\n')
file:write(' "stopAtEntry": false,\n')
file:write(string.format(' "cwd": "${workspaceFolder}/%s",\n', cwd))
file:write(' "environment": [],\n')
file:write(' "externalConsole": false,\n')
file:write(string.format(' "preLaunchTask": "%s %s",\n', workspaceName, preLaunchTask))
file:write(string.format(' "program": "${workspaceFolder}/bin/%s/%s",\n', dir, program))
file:write(' "MIMode": "gdb",\n')
file:write(string.format(' "miDebuggerPath": "%s",\n', debuggerPath))
if isDebug then
file:write(' "setupCommands": [\n')
file:write(' {\n')
file:write(' "description": "Enable pretty printing for gdb",\n')
file:write(' "text": "-enable-pretty-printing",\n')
file:write(' "ignoreFailures": false,\n')
file:write(' },\n')
file:write(' {\n')
file:write(' "description": "Set disassembly flavor to intel",\n')
file:write(' "text": "-gdb-set disassembly-flavor intel",\n')
file:write(' "ignoreFailures": false,\n')
file:write(' }\n')
file:write(' ]\n')
end
end
local function generateLaunchJson()
print("\n=======================================================")
print("Generating .vscode/launch.json")
local file = io.open(".vscode/launch.json", "w")
if file then
file:write('{\n')
file:write(' "configurations": [\n')
writeLaunchConfiguration(file, "tests", true)
file:write(" },\n")
file:write('\n')
writeLaunchConfiguration(file, "tests", false)
file:write(" },\n")
file:write('\n')
writeLaunchConfiguration(file, "abi-dump", true)
file:write(" },\n")
file:write('\n')
writeLaunchConfiguration(file, "abi-dump", false)
file:write(" }\n")
file:write(" ],\n")
file:write(' "version": "0.2.0"\n')
file:write("}\n")
file:close()
end
end
-- generate vscode properties if using gmake
premake.override(premake.action, "call", function(base, action)
base(action)
if action == "gmake" then
generateVscodeProperties()
generateTasksJson()
generateLaunchJson()
end
end)
newoption {
trigger = "compiler",
description = "Choose a C compiler",
value = "COMPILER",
allowed = {
{ "gcc", "GNU GCC" },
{ "clang", "Clang" },
{ "msvc", "MSVC" }
}
}
workspace(workspaceName)
if PAL_BUILD_TEST_APPLICATION then
startproject("tests")
else
startproject("abi-dump")
end
if PAL_BUILD_STATIC_LIBRARY then
staticruntime "on"
else
staticruntime "off"
end
multiprocessorcompile "On"
cdialect "C99"
architecture "x64"
language "C"
configurations { "Debug", "Release" }
filter {"system:windows", "configurations:*"}
systemversion "latest"
filter "configurations:Debug"
symbols "on"
runtime "Debug"
filter "configurations:Release"
symbols "off"
runtime "Release"
optimize "full"
filter {}
if (_ACTION == "gmake") then
if os.target() == "windows" then
local gccPath = getCommandOutput("where gcc.exe 2>nul")
local gccBinPath = path.getdirectory(gccPath)
gccBasePath = path.getdirectory(gccBinPath)
debuggerPath = getCommandOutput("where gdb.exe 2>nul")
if (_OPTIONS["compiler"] == "clang") then
toolset("clang")
buildoptions {
"-target x86_64-w64-windows-gnu",
"-I" .. gccBasePath .. "/include",
"-I" .. gccBasePath .. "/ucrt/include",
"-I" .. gccBasePath .. "/mingw/include",
-- warnings
"-Wno-switch", -- for switch statements
"-Wno-switch-enum" -- for switch statements
}
linkoptions {
"-target x86_64-w64-windows-gnu",
"-L" .. gccBasePath .. "/lib",
"-L" .. gccBasePath .. "/mingw/lib"
}
intellisenseMode = "windows-clang-x64"
compilerPath = getCommandOutput("where clang.exe 2>nul")
else
-- GCC
intellisenseMode = "gcc-x64"
compilerPath = gccPath
end
else
-- linux
if (_OPTIONS["compiler"] == "clang") then
toolset("clang")
buildoptions {
-- warnings
"-Wno-switch", -- for switch statements
"-Wno-switch-enum" -- for switch statements
}
intellisenseMode = "linux-clang-x64"
compilerPath = "/usr/bin/clang"
else
-- GCC
intellisenseMode = "linux-gcc-x64"
compilerPath = "/usr/bin/gcc"
end
debuggerPath = "/usr/bin/gdb"
end
end
if (_ACTION == "vs2022") or (_ACTION == "vs2026") then
if (_OPTIONS["compiler"] == "clang") then
toolset("clang")
end
defines {
"_CRT_SECURE_NO_WARNINGS"
}
disablewarnings {
"6387",
"4018",
"4133",
"4101"
}
end
if (PAL_BUILD_SYSTEM_MODULE) then
defines { "PAL_HAS_SYSTEM_MODULE=1" }
else
defines { "PAL_HAS_SYSTEM_MODULE=0" }
end
if (PAL_BUILD_THREAD_MODULE) then
defines { "PAL_HAS_THREAD_MODULE=1" }
else
defines { "PAL_HAS_THREAD_MODULE=0" }
end
if (PAL_BUILD_VIDEO_MODULE) then
defines { "PAL_HAS_VIDEO_MODULE=1" }
else
defines { "PAL_HAS_VIDEO_MODULE=0" }
end
if (PAL_BUILD_OPENGL_MODULE) then
defines { "PAL_HAS_OPENGL_MODULE=1" }
else
defines { "PAL_HAS_OPENGL_MODULE=0" }
end
if (PAL_BUILD_GRAPHICS_MODULE) then
defines { "PAL_HAS_GRAPHICS_MODULE=1" }
else
defines { "PAL_HAS_GRAPHICS_MODULE=0" }
end
if (PAL_BUILD_TEST_APPLICATION) then
include "tests/tests.lua"
end
if (PAL_BUILD_ABI_DUMP) then
include "tools/abi_dump/abi_dump.lua"
end
include "pal.lua"