-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathxmake.lua
More file actions
479 lines (391 loc) · 17.3 KB
/
Copy pathxmake.lua
File metadata and controls
479 lines (391 loc) · 17.3 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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
-- set minimum xmake version
set_xmakever("3.0.0")
-- set project constants
set_project("commonlib-shared")
set_arch("x64")
set_languages("c++23")
set_warnings("allextra")
set_encodings("utf-8")
-- add common rules
add_rules("mode.debug", "mode.releasedbg")
add_rules("plugin.vsxmake.autoupdate")
-- add options
option("commonlib_ini", function()
set_default(false)
set_description("enable REX::INI settings support")
end)
option("commonlib_json", function()
set_default(false)
set_description("enable REX::JSON settings support")
end)
option("commonlib_toml", function()
set_default(false)
set_description("enable REX::TOML settings support")
end)
option("commonlib_xbyak", function()
set_default(false)
set_description("enable xbyak support for Trampoline")
end)
option("commonlib_random", function ()
set_default(false)
set_description("enable REX::TRandom support")
end)
-- add packages
add_requires("spdlog v1.16.0", { configs = { header_only = false, wchar = true, std_format = true } })
-- add config packages
if has_config("commonlib_ini") then add_requires("simpleini v4.25") end
if has_config("commonlib_json") then add_requires("glaze v7.0.0") end
if has_config("commonlib_toml") then add_requires("toml11 v4.4.0") end
if has_config("commonlib_xbyak") then add_requires("xbyak v7.06") end
if has_config("commonlib_random") then add_requires("xoshiro-cpp 2021.08.04") end
target("commonlib-shared", function()
-- set target kind
set_kind("static")
-- set build by default
set_default(os.scriptdir() == os.projectdir())
-- add packages
add_packages("spdlog", { public = true })
-- add config packages
if has_config("commonlib_ini") then
add_packages("simpleini", { public = true })
add_defines("COMMONLIB_OPTION_INI=1", { public = true })
end
if has_config("commonlib_json") then
add_packages("glaze", { public = true })
add_defines("COMMONLIB_OPTION_JSON=1", { public = true })
end
if has_config("commonlib_toml") then
add_packages("toml11", { public = true })
add_defines("COMMONLIB_OPTION_TOML=1", { public = true })
end
if has_config("commonlib_xbyak") then
add_packages("xbyak", { public = true })
add_defines("COMMONLIB_OPTION_XBYAK=1", { public = true })
end
if has_config("commonlib_random") then
add_packages("xoshiro-cpp", { public = true })
add_defines("COMMONLIB_OPTION_RANDOM=1", { public = true })
end
-- add options
add_options("commonlib_ini", "commonlib_json", "commonlib_toml", "commonlib_xbyak", "commonlib_random", { public = true })
-- add system links
add_syslinks("advapi32", "bcrypt", "d3d11", "d3dcompiler", "dbghelp", "dxgi", "ole32", "shell32", "user32", "version", "ws2_32")
-- add source files
add_files("src/**.cpp")
-- add header files
add_includedirs("include", { public = true })
add_headerfiles(
"include/(REL/**.h)",
"include/(REX/**.h)"
)
-- set precompiled header
set_pcxxheader("src/REX/PCH.h")
-- add flags (public)
add_cxxflags(
"/EHsc",
"/permissive-",
{ public = true }
)
-- add flags (cl) (public)
add_cxxflags(
"cl::/bigobj",
"cl::/cgthreads8",
"cl::/diagnostics:caret",
"cl::/external:W0",
"cl::/fp:contract",
"cl::/fp:except-",
"cl::/guard:cf-",
"cl::/Zc:enumTypes",
"cl::/Zc:preprocessor",
"cl::/Zc:templateScope",
{ public = true }
)
-- add flags (cl: disable warnings) (public)
add_cxxflags(
"cl::/wd4200", -- nonstandard extension used : zero-sized array in struct/union
"cl::/wd4201", -- nonstandard extension used : nameless struct/union
"cl::/wd4324", -- structure was padded due to alignment specifier
{ public = true }
)
-- add flags (cl: warnings -> errors) (public)
add_cxxflags(
"cl::/we4715", -- not all control paths return a value
{ public = true }
)
-- add flags (clang-cl) (public)
add_cxxflags(
"clang_cl::-fms-compatibility",
"clang_cl::-fms-extensions",
{ public = true }
)
-- add flags (clang-cl: disable warnings) (public)
add_cxxflags(
"clang_cl::-Wno-delete-non-abstract-non-virtual-dtor",
"clang_cl::-Wno-deprecated-volatile",
"clang_cl::-Wno-ignored-qualifiers",
"clang_cl::-Wno-inconsistent-missing-override",
"clang_cl::-Wno-invalid-offsetof",
"clang_cl::-Wno-microsoft-include",
"clang_cl::-Wno-overloaded-virtual",
"clang_cl::-Wno-pragma-system-header-outside-header",
"clang_cl::-Wno-reinterpret-base-class",
"clang_cl::-Wno-switch",
"clang_cl::-Wno-unused-local-typedef",
"clang_cl::-Wno-unused-private-field",
{ public = true }
)
end)
rule("commonlib.plugin", function()
add_deps("win.sdk.resource")
on_config(function(target)
import("core.project.project")
import("core.base.semver")
target:set("arch", "x64")
target:set("kind", "shared")
target:set("configdir", target:autogendir())
target:add("configfiles", path.join(os.scriptdir(), "res/commonlib-plugin.rc.in"))
target:add("files", path.join(target:configdir(), "commonlib-plugin.rc"))
local data = target:data("commonlib.plugin.config") or {}
target:set("configvar", "COMMONLIB_PLUGIN_AUTHOR", data.author or "")
target:set("configvar", "COMMONLIB_PLUGIN_CONTACT", data.contact or "")
target:set("configvar", "COMMONLIB_PLUGIN_DESCRIPTION", data.description or "")
target:set("configvar", "COMMONLIB_PLUGIN_LICENSE", (target:license() or "Unknown") .. " License")
target:set("configvar", "COMMONLIB_PLUGIN_NAME", data.name or target:name())
target:set("configvar", "COMMONLIB_PLUGIN_VERSION", target:version() or "0.0.0")
target:set("configvar", "COMMONLIB_PLUGIN_VERSION_MAJOR", semver.new(target:version() or "0.0.0"):major())
target:set("configvar", "COMMONLIB_PLUGIN_VERSION_MINOR", semver.new(target:version() or "0.0.0"):minor())
target:set("configvar", "COMMONLIB_PLUGIN_VERSION_PATCH", semver.new(target:version() or "0.0.0"):patch())
target:set("configvar", "COMMONLIB_PLUGIN_XSE_VERSION_MAJOR", semver.new(data.xse_minimum or "0.0.0"):major())
target:set("configvar", "COMMONLIB_PLUGIN_XSE_VERSION_MINOR", semver.new(data.xse_minimum or "0.0.0"):minor())
target:set("configvar", "COMMONLIB_PLUGIN_XSE_VERSION_PATCH", semver.new(data.xse_minimum or "0.0.0"):patch())
target:set("configvar", "COMMONLIB_PROJECT_NAME", project.name() or "")
target:set("configvar", "COMMONLIB_PROJECT_VERSION", project.version() or "0.0.0")
target:set("configvar", "COMMONLIB_PROJECT_VERSION_MAJOR", semver.new(project.version() or "0.0.0"):major())
target:set("configvar", "COMMONLIB_PROJECT_VERSION_MINOR", semver.new(project.version() or "0.0.0"):minor())
target:set("configvar", "COMMONLIB_PROJECT_VERSION_PATCH", semver.new(project.version() or "0.0.0"):patch())
end)
on_install(function(target)
import("target.action.install")(target, { binaries = false, headers = false, libraries = false, packages = false })
end)
on_package(function(target)
import("core.project.config")
import("core.project.project")
local archivename = target:name() .. "-" .. (target:version() or "0.0.0") .. ".zip"
cprint("${dim}packaging %s .. ", archivename)
local rootdir = path.join(os.tmpdir(), "packages", project.name() or "", target:name())
os.tryrm(rootdir)
local data = target:data("commonlib.plugin.package") or {}
local installdir = path.join(rootdir, data.prefixdir or "")
os.mkdir(installdir)
local srcfiles, dstfiles = target:installfiles(installdir)
if srcfiles and #srcfiles > 0 and dstfiles and #dstfiles > 0 then
for idx, srcfile in ipairs(srcfiles) do
os.trycp(srcfile, dstfiles[idx])
end
else
return
end
local archivedir = path.absolute(path.join(config.builddir(), "packages"))
local archivefile = path.join(archivedir, archivename)
os.tryrm(archivefile)
local olddir = os.cd(rootdir)
local archivefiles = os.files("**")
os.cd(olddir)
import("utils.archive").archive(archivefile, archivefiles, { curdir = rootdir })
cprint("${dim}packaging %s to %s ... ${color.success}${text.success}", archivename, archivedir)
end)
after_build(function(target)
import("core.project.depend")
import("core.project.task")
local install = target:values("commonlib.plugin.install")
if install or install == nil then
depend.on_changed(function()
local srcfiles, dstfiles = target:installfiles()
if srcfiles and #srcfiles > 0 and dstfiles and #dstfiles > 0 then
task.run("install")
end
end, { changed = target:is_rebuilt(), files = { target:targetfile() } })
end
end)
end)
rule("commonlib.archive", function()
on_config(function(target)
target:set("kind", "phony")
target:set("targetdir", "$(builddir)/archive")
os.mkdir(target:targetdir())
if not os.getenv("XSE_BSARCH_PATH") then
cprint("${dim}%s missing env XSE_BSARCH_PATH .. ${color.failure}${text.failure}", target:name())
return
end
if not os.exists(path.join(os.getenv("XSE_BSARCH_PATH"), "BSArch.exe")) then
cprint("${dim}%s missing \"%%XSE_BRANCH_PATH%%\\BSArch.exe\" .. ${color.failure}${text.failure}", target:name())
return
end
target:data_set("commonlib.archive.pass", true)
end)
on_build(function(target)
import("core.project.project")
local pass = target:data("commonlib.archive.pass")
if not pass then
cprint("${dim}%s .. failed archive config checks, skipping build", target:name())
return
end
local data = target:data("commonlib.archive.config") or {}
if not data.options then
data.options = {
compress = true,
share = true,
multi_threaded = true
}
end
local suffix = target:data("commonlib.archive.suffix") or ""
local extension = target:data("commonlib.archive.extension") or ".bsa"
local archivename = (data.name or target:name()) .. suffix .. extension
cprint("${dim}archiving %s .. ", archivename)
local tempdir = path.join(os.tmpdir(), "archive", project.name() or "", target:name())
os.tryrm(tempdir)
os.mkdir(tempdir)
local srcfiles, dstfiles = target:extrafiles(tempdir)
if srcfiles and #srcfiles > 0 and dstfiles and #dstfiles > 0 then
for idx, srcfile in ipairs(srcfiles) do
os.trycp(srcfile, dstfiles[idx])
end
else
return
end
local archivedir = path.absolute(target:targetdir())
local archivefile = path.join(archivedir, archivename)
os.tryrm(archivefile)
local args = { "pack", tempdir, archivefile, target:data("commonlib.archive.format") }
if data.options.compress then
if type(data.options.compress) == "boolean" and data.options.compress == true then
table.append(args, "-z")
elseif data.options.compress == "zlib" then
table.append(args, "-z:zlib")
elseif data.options.compress == "lz4" then
table.append(args, "-z:lz4")
elseif data.options.compress == "lz4f" then
table.append(args, "-z:lz4f")
end
end
if data.options.share then
if data.options.shared == true then
table.append(args, "-share:yes")
else
table.append(args, "-share:no")
end
end
if data.options.multi_threaded then
if data.options.multi_threaded == true then
table.append(args, "-mt:yes")
else
table.append(args, "-mt:no")
end
end
if data.options.archive_flags then
table.append(args, format("-af:%s", tostring(data.options.archive_flags)))
end
if data.options.file_flags then
table.append(args, format("-ff:%s", tostring(data.options.file_flags)))
end
os.vrunv(path.join(os.getenv("XSE_BSARCH_PATH"), "BSArch.exe"), args)
if data.install then
local parent = project.target(data.install)
if parent then
parent:add("installfiles", archivefile, { prefixdir = data.installdir or "" })
end
end
cprint("${dim}archiving %s to %s ... ${color.success}${text.success}", archivename, archivedir)
end)
on_install(function(target)
end)
end)
rule("commonlib.papyrus", function()
on_config(function(target)
target:set("kind", "phony")
target:set("targetdir", "$(builddir)/papyrus")
os.mkdir(target:targetdir())
if not os.getenv("XSE_CAPRICA_PATH") then
cprint("${dim}%s missing env XSE_CAPRICA_PATH .. ${color.failure}${text.failure}", target:name())
return
end
if not os.exists(path.join(os.getenv("XSE_CAPRICA_PATH"), "Caprica.exe")) then
cprint("${dim}%s missing \"%%XSE_CAPRICA_PATH%%\\Caprica.exe\" .. ${color.failure}${text.failure}", target:name())
return
end
target:data_set("commonlib.papyrus.pass", true)
end)
on_build(function(target)
import("core.project.project")
local pass = target:data("commonlib.papyrus.pass")
if not pass then
cprint("${dim}%s failed papyrus config checks, skipping build .. ${color.failure}${text.failure}", target:name())
return
end
local data = target:data("commonlib.papyrus.config") or {}
if not data.options then data.options = {} end
cprint("${dim}compiling %s .. ", target:name())
local tempdir = path.join(os.tmpdir(), "papyrus", project.name() or "", target:name())
os.tryrm(tempdir)
local rootdir = path.join(tempdir, "Scripts")
os.mkdir(rootdir)
local srcfiles, dstfiles = target:extrafiles(rootdir)
if srcfiles and #srcfiles > 0 and dstfiles and #dstfiles > 0 then
for idx, srcfile in ipairs(srcfiles) do
os.trycp(srcfile, dstfiles[idx])
end
else
return
end
local args = { tempdir, format("--game=%s", target:data("commonlib.papyrus.game")), "--recurse", "--ignorecwd" }
local imports = { rootdir }
if data.options.imports then
if type(data.options.imports) ~= "table" then
cprint("${dim}%s options.imports is defined, but not a table .. ${color.failure}${text.failure}", target:name())
return
end
for _, import in ipairs(data.options.imports) do
table.append(imports, import)
end
end
if not data.options.skip_default_imports then
local gamevar = target:data("commonlib.papyrus.gamevar")
if not os.getenv(gamevar) then
cprint("${dim}%s missing env %s .. ${color.failure}${text.failure}", target:name(), gamevar)
return
end
local gamepath = os.getenv(gamevar)
local defaults = target:data("commonlib.papyrus.defaults") or {}
for _, default in ipairs(defaults) do
table.append(imports, path.join(gamepath, default))
end
end
table.append(args, format("--import=%s", table.concat(imports, ";")))
table.append(args, format("--flags=%s", target:data("commonlib.papyrus.flags")))
local scriptdir = path.absolute(target:targetdir())
table.append(args, format("--output=%s", scriptdir))
if data.options.optimize then table.append(args, "--optimize") end
if data.options.release then table.append(args, "--release") end
if data.options.final then table.append(args, "--final") end
if data.options.anonymize then table.append(args, "--anonymize") end
if data.options.parallel_compile then table.append(args, "--parallel-compile=1") end
if data.options.strict then table.append(args, "--strict") end
if data.options.language_extensions then table.append(args, "--enable-language-extensions=1") end
os.execv(path.join(os.getenv("XSE_CAPRICA_PATH"), "Caprica.exe"), args)
if data.archive then
local parent = project.target(data.archive)
if parent then
parent:add("extrafiles", format("%s/(**)", scriptdir))
end
end
if data.install then
local parent = project.target(data.install)
if parent then
parent:add("installfiles", format("%s/(**)", scriptdir), { prefixdir = data.installdir or "" })
end
end
cprint("${dim}compiling %s to %s ... ${color.success}${text.success}", target:name(), scriptdir)
end)
on_install(function(target)
end)
end)