-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmake.lua
290 lines (230 loc) · 7.96 KB
/
xmake.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
add_repositories("local-repo Xmake")
add_requires("imgui v1.91.0-docking", { configs = { sdl2 = true }})
add_requires("libsdl", "pfd", "libsdl_image", "sol2", "tiny-process-library")
add_rules("mode.debug", "mode.release")
set_languages("cxx20")
if is_mode("debug") then
add_defines("MLX_UT_DEBUG")
elseif is_mode("release") then
add_defines("MLX_UT_RELEASE")
set_fpmodels("fast")
add_vectorexts("sse", "sse2", "sse3", "ssse3")
end
set_objectdir("build/Objs/$(os)_$(arch)")
set_targetdir("build/Bin/$(os)_$(arch)")
set_rundir("build/Bin/$(os)_$(arch)")
set_dependir("build/.deps")
set_optimize("fastest")
local os_interfaces = {
Unix = {
dir = "Drivers/",
enabled = is_plat("linux")
},
MacOS = {
dir = "Drivers/",
enabled = is_plat("macosx"),
custom = function(subdir)
add_files("Runtime/" .. subdir .. "/Sources/Drivers/MacOS/**.mm")
end
},
Windows = {
dir = "Drivers/",
enabled = is_plat("windows")
}
}
option("unitybuild", { description = "Build the engine using unity build", default = false })
function ModuleTargetConfig(name, module, subdir)
-- Add header and source files
for _, ext in ipairs({".h", ".hpp", ".inl"}) do
if module.dir then
add_headerfiles("Runtime/" .. subdir .. "/Includes/" .. module.dir .. name .. "/**" .. ext)
add_headerfiles("Runtime/" .. subdir .. "/Sources/" .. module.dir .. name .. "/**" .. ext, { prefixdir = "private", install = false })
else
add_headerfiles("Runtime/" .. subdir .. "/Includes/" .. name .. "/**" .. ext)
add_headerfiles("Runtime/" .. subdir .. "/Sources/" .. name .. "/**" .. ext, { prefixdir = "private", install = false })
end
end
if module.dir then
remove_headerfiles("Runtime/" .. subdir .. "/Sources/" .. module.dir .. name .. "/Resources/**.h")
else
remove_headerfiles("Runtime/" .. subdir .. "/Sources/" .. name .. "/Resources/**.h")
end
if module.dir then
set_pcxxheader("Runtime/" .. subdir .. "/Includes/" .. module.dir .. name .. "/PreCompiled.h")
else
set_pcxxheader("Runtime/" .. subdir .. "/Includes/" .. name .. "/PreCompiled.h")
end
if module.packages then
add_packages(table.unpack(module.packages))
end
if module.publicPackages then
for _, pkg in ipairs(module.publicPackages) do
add_packages(pkg, { public = true })
end
end
if module.deps then
add_deps(table.unpack(module.deps))
end
if module.dir then
add_files("Runtime/" .. subdir .. "/Sources/" .. module.dir .. name .. "/**.cpp")
else
add_files("Runtime/" .. subdir .. "/Sources/" .. name .. "/**.cpp")
end
if module.custom then
module.custom(subdir)
end
end
function CraeteEmbeddedResources(target)
if is_mode("debug") and not os.exists("$(buildir)/Bin/$(os)_$(arch)/Resources") then
os.ln("$(scriptdir)/Resources", "$(buildir)/Bin/$(os)_$(arch)/Resources")
print("Created resources symlink")
end
if is_mode("release") then
if os.exists("Runtime/Software/Includes/Embedded") then
os.rm("Runtime/Software/Includes/Embedded")
end
os.mkdir("Runtime/Software/Includes/Embedded")
io.writefile("Runtime/Software/Includes/Embedded/Logo.h", [[
#ifndef MLX_UT_EMBEDDED_LOGO
#define MLX_UT_EMBEDDED_LOGO
// Generated File
#include <vector>
#include <cstdint>
static const std::vector<std::uint8_t> logo_data = {
#include <Logo.png.h>
};
#endif // MLX_UT_EMBEDDED_LOGO]])
local references = ""
local references_names = ""
for _, file in ipairs(os.files("Resources/Assets/TestsReferences/*.png")) do
_, filename, _ = file:match("^(.-)([^\\/]-)%.([^\\/%.]-)%.?$")
references = references .. "static const std::vector<std::uint8_t> " .. filename .. "_data = {\n\t#include <" .. filename .. ".png.h>\n};\n"
references_names = references_names .. "if(name == \"" .. filename .. "\")\n\t\treturn " .. filename .. "_data;\n\t"
end
io.writefile("Runtime/Software/Includes/Embedded/References.h", [[
#ifndef MLX_UT_EMBEDDED_REFERENCES
#define MLX_UT_EMBEDDED_REFERENCES
// Generated File
#include <vector>
#include <cstdint>
#include <string_view>
]] .. references ..[[
inline const std::vector<std::uint8_t> GetDataFromFilename(std::string_view name)
{
// Ugly generated function
]] .. references_names .. [[return {};
}
#endif // MLX_UT_EMBEDDED_REFERENCES]])
local fonts = ""
for _, file in ipairs(os.files("Resources/Fonts/**.ttf")) do
_, filename, _ = file:match("^(.-)([^\\/]-)%.([^\\/%.]-)%.?$")
fonts = fonts .. "static const std::vector<std::uint8_t> " .. filename .. "_data = {\n\t#include <" .. filename .. ".ttf.h>\n};\n"
end
io.writefile("Runtime/Software/Includes/Embedded/Fonts.h", [[
#ifndef MLX_UT_EMBEDDED_FONTS
#define MLX_UT_EMBEDDED_FONTS
// Generated File
#include <vector>
#include <cstdint>
]] .. fonts ..[[
#endif // MLX_UT_EMBEDDED_FONTS]])
if os.exists("Runtime/Runner/Includes/Embedded") then
os.rm("Runtime/Runner/Includes/Embedded")
end
os.mkdir("Runtime/Runner/Includes/Embedded")
local tests = ""
local tests_names = ""
for _, file in ipairs(os.files("Resources/Tests/**.lua")) do
_, filename, _ = file:match("^(.-)([^\\/]-)%.([^\\/%.]-)%.?$")
tests = tests .. "static const std::string " .. filename .. "_data = R\"test(\n" .. io.readfile(file) .. ")test\";\n\n"
tests_names = tests_names .. "if(name == \"" .. filename .. "\")\n\t\treturn " .. filename .. "_data;\n\t"
end
io.writefile("Runtime/Runner/Includes/Embedded/Tests.h", [[
#ifndef MLX_UT_EMBEDDED_TESTS
#define MLX_UT_EMBEDDED_TESTS
// Generated File
#include <string>
]] .. tests ..[[
inline const std::string GetDataFromFilename(std::string_view name)
{
// Ugly generated function
]] .. tests_names .. [[return {};
}
#endif // MLX_UT_EMBEDDED_TESTS]])
end
end
target("MacroUnitTest")
set_license("MIT")
set_kind("binary")
add_packages("libsdl", "pfd", "libsdl_image", "imgui", "tiny-process-library")
if is_mode("release") then
add_rules("utils.bin2c", { extensions = { ".png", ".ttf" } } )
add_files("Resources/Assets/**.png")
add_files("Resources/Fonts/**.ttf")
end
if has_config("unitybuild") then
add_rules("c++.unity_build", { batchsize = 6 })
end
set_pcxxheader("Runtime/Software/Includes/PreCompiled.h")
add_includedirs("Runtime/Software/Includes", "Runtime/Software/Sources", "Runtime/ThirdParty")
add_includedirs("Runtime/Common/Includes", "Runtime/Common/Sources")
add_files("Runtime/Software/Sources/**.cpp|Drivers/**.cpp")
for name, module in table.orderpairs(os_interfaces) do
if module.enabled then
ModuleTargetConfig(name, module, "Common")
end
end
before_build(CraeteEmbeddedResources)
on_clean(function(target)
if target:objectfiles() then
for _, file in ipairs(target:objectfiles()) do
if os.exists(file) then
print("Removing " .. file)
os.rm(file)
end
end
end
if target:targetfile() and os.exists(target:targetfile()) then
print("Removing " .. target:targetfile())
os.rm(target:targetfile())
end
end)
add_defines("SDL_MAIN_HANDLED")
target_end()
target("TestRunner")
set_license("MIT")
set_kind("binary")
add_packages("libsdl", "sol2")
if has_config("unitybuild") then
add_rules("c++.unity_build", { batchsize = 6 })
end
set_pcxxheader("Runtime/Runner/Includes/PreCompiled.h")
add_includedirs("Runtime/Runner/Includes", "Runtime/Runner/Sources", "Runtime/ThirdParty")
add_includedirs("Runtime/Common/Includes", "Runtime/Common/Sources")
add_files("Runtime/Runner/Sources/**.cpp")
for name, module in table.orderpairs(os_interfaces) do
if module.enabled then
ModuleTargetConfig(name, module, "Common")
end
end
on_load(function(target)
if not os.exists("$(buildir)/Bin/$(os)_$(arch)/Resources") then
os.ln("$(scriptdir)/Resources", "$(buildir)/Bin/$(os)_$(arch)/Resources")
print("Created resources symlink")
end
end)
on_clean(function(target)
if target:objectfiles() then
for _, file in ipairs(target:objectfiles()) do
if os.exists(file) then
print("Removing " .. file)
os.rm(file)
end
end
end
if target:targetfile() and os.exists(target:targetfile()) then
print("Removing " .. target:targetfile())
os.rm(target:targetfile())
end
end)
target_end()