-
Notifications
You must be signed in to change notification settings - Fork 4
/
units.lua
executable file
·334 lines (299 loc) · 8.43 KB
/
units.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
require 'tundra.syntax.glob'
local winFilter = "win*"
local winDebugFilter = "win*-*-debug"
local winReleaseFilter = "win*-*-release"
local linuxFilter = "linux-*-*-*"
local winKernelLibs = { "kernel32.lib", "user32.lib", "gdi32.lib", "winspool.lib", "advapi32.lib", "shell32.lib", "comctl32.lib",
"uuid.lib", "ole32.lib", "oleaut32.lib", "shlwapi.lib", "OLDNAMES.lib", "wldap32.lib", "wsock32.lib",
"Psapi.lib", "Msimg32.lib", "Comdlg32.lib", "RpcRT4.lib", "Iphlpapi.lib", "Delayimp.lib" }
-- Dynamic (msvcr110.dll etc) CRT linkage
local winLibsDynamicCRTDebug = tundra.util.merge_arrays( { "msvcrtd.lib", "msvcprtd.lib", "comsuppwd.lib" }, winKernelLibs )
local winLibsDynamicCRTRelease = tundra.util.merge_arrays( { "msvcrt.lib", "msvcprt.lib", "comsuppw.lib" }, winKernelLibs )
winLibsDynamicCRTDebug.Config = winDebugFilter
winLibsDynamicCRTRelease.Config = winReleaseFilter
-- Static CRT linkage
local winLibsStaticCRTDebug = tundra.util.merge_arrays( { "libcmtd.lib", "libcpmtd.lib", "comsuppwd.lib" }, winKernelLibs )
local winLibsStaticCRTRelease = tundra.util.merge_arrays( { "libcmt.lib", "libcpmt.lib", "comsuppw.lib" }, winKernelLibs )
winLibsStaticCRTDebug.Config = winDebugFilter
winLibsStaticCRTRelease.Config = winReleaseFilter
local winDynamicOpts = {
{ "/MDd"; Config = winDebugFilter },
{ "/MD"; Config = winReleaseFilter },
}
local winStaticOpts = {
{ "/MTd"; Config = winDebugFilter },
{ "/MT"; Config = winReleaseFilter },
}
local winDefs = {
{ "_CRTDBG_MAP_ALLOC"; Config = winDebugFilter },
}
local winDynamicEnv = {
CCOPTS = winDynamicOpts,
CXXOPTS = winDynamicOpts,
CCDEFS = winDefs,
CPPDEFS = winDefs,
}
local winStaticEnv = {
CCOPTS = winStaticOpts,
CXXOPTS = winStaticOpts,
CCDEFS = winDefs,
CPPDEFS = winDefs,
}
local crtDynamic = ExternalLibrary {
Name = "crtdynamic",
Propagate = {
Env = winDynamicEnv,
Libs = {
winLibsDynamicCRTDebug,
winLibsDynamicCRTRelease,
},
},
}
local crtStatic = ExternalLibrary {
Name = "crtstatic",
Propagate = {
Env = winStaticEnv,
Libs = {
winLibsStaticCRTDebug,
winLibsStaticCRTRelease,
},
},
}
-- Return an FGlob node that has our standard filters applied
local function makeGlob(dir, options)
local filters = {
{ Pattern = "_windows"; Config = winFilter },
{ Pattern = "_linux"; Config = linuxFilter },
{ Pattern = "_android"; Config = "ignore" }, -- Android stuff is built with a different build system
{ Pattern = "[/\\]_[^/\\]*$"; Config = "ignore" }, -- Any file that starts with an underscore is ignored
}
if options.Ignore ~= nil then
for _, ignore in ipairs(options.Ignore) do
filters[#filters + 1] = { Pattern = ignore; Config = "ignore" }
end
end
return FGlob {
Dir = dir,
Extensions = { ".c", ".cpp", ".h" },
Filters = filters,
}
end
local function merge_tables(a, b)
local r = {}
for k,v in pairs(a) do
r[k] = v
end
for k,v in pairs(b) do
r[k] = v
end
return r
end
-- Swapping this out will change linkage to use MSVCR120.dll and its cousins,
-- instead of statically linking to the required MSVC runtime libraries.
-- I don't understand why, but if we build with crtStatic, then tests fail
-- due to heap corruption. I can only guess it's the old issue of two different
-- libraries using different heap properties. For example, library A allocated
-- memory with debug_alloc(), and then library B tries to free that memory with
-- regular free(). However, I cannot figure out how that is happening.
--local crt = crtStatic
local crt = crtDynamic
local directx = ExternalLibrary {
Name = "directx",
Propagate = {
Libs = {
{ "D3D11.lib", "d3dcompiler.lib"; Config = "win*" },
},
},
}
local unicode = ExternalLibrary {
Name = "unicode",
Propagate = {
Defines = { "UNICODE", "_UNICODE" },
},
}
local utfz = StaticLibrary {
Name = "utfz",
Depends = { crt, },
Sources = {
"dependencies/utfz/utfz.cpp",
}
}
-- This is not used on Linux Desktop
local expat = StaticLibrary {
Name = "expat",
Depends = { crt, },
Defines = {
"XML_STATIC",
{ "WIN32"; Config = winFilter },
},
Sources = {
makeGlob("dependencies/expat", {})
}
}
local freetype = StaticLibrary {
Name = "freetype",
Defines = {
"FT2_BUILD_LIBRARY",
},
Depends = { crt, },
SourceDir = "dependencies/freetype",
Includes = "dependencies/freetype/include",
Sources = {
"src/autofit/autofit.c",
"src/base/ftbase.c",
"src/base/ftbitmap.c",
"src/bdf/bdf.c",
"src/cff/cff.c",
"src/cache/ftcache.c",
"src/base/ftgasp.c",
"src/base/ftglyph.c",
"src/gzip/ftgzip.c",
"src/base/ftinit.c",
"src/base/ftlcdfil.c",
"src/lzw/ftlzw.c",
"src/base/ftstroke.c",
"src/base/ftsystem.c",
"src/smooth/smooth.c",
"src/base/ftbbox.c",
"src/base/ftmm.c",
"src/base/ftpfr.c",
"src/base/ftsynth.c",
"src/base/fttype1.c",
"src/base/ftwinfnt.c",
"src/pcf/pcf.c",
"src/pfr/pfr.c",
"src/psaux/psaux.c",
"src/pshinter/pshinter.c",
"src/psnames/psmodule.c",
"src/raster/raster.c",
"src/sfnt/sfnt.c",
"src/truetype/truetype.c",
"src/type1/type1.c",
"src/cid/type1cid.c",
"src/type42/type42.c",
"src/winfonts/winfnt.c",
}
}
local xo_base = {
Libs = {
{ "opengl32.lib", "user32.lib", "gdi32.lib", "winmm.lib" ; Config = "win*" },
{ "X11", "GL", "GLU", "stdc++", "expat", "pthread"; Config = "linux-*" },
},
Defines = {
"XML_STATIC", -- for expat
},
Includes = {
"xo",
"dependencies/freetype/include",
"dependencies/agg/include",
"dependencies/expat",
},
Depends = { crt, freetype, directx, utfz,
{ expat; Config = winFilter },
},
PrecompiledHeader = {
Source = "xo/pch.cpp",
Header = "pch.h",
Pass = "PchGen",
},
Sources = {
makeGlob("xo", {}),
makeGlob("dependencies/agg", {}),
makeGlob("dependencies/ConvertUTF", {}),
makeGlob("dependencies/GL", {}),
makeGlob("dependencies/hash", {}),
},
}
local xo = SharedLibrary(merge_tables(xo_base, {
Name = "xo",
}
))
local xo_static = StaticLibrary(merge_tables(xo_base, {
Name = "xo_static",
}
))
local HelloAmalgamation = Program {
Name = "HelloAmalgamation",
Libs = {
{ "opengl32.lib", "user32.lib", "gdi32.lib", "winmm.lib" ; Config = "win*" },
{ "X11", "GL", "GLU", "stdc++"; Config = "linux-*" },
},
Defines = {
"XO_AMALGAMATION"
},
Depends = {
crtStatic,
directx,
},
Sources = {
"amalgamation/xo-amalgamation.cpp",
"amalgamation/xo-amalgamation-freetype.c",
"templates/xoWinMain.cpp",
"examples/HelloAmalgamation/HelloAmalgamation.cpp",
}
}
local function XoExampleApp(use_dynamic_xo, template, name, sources)
local src = {
"templates/" .. template,
"dependencies/tsf/tsf.cpp",
}
for _, s in ipairs(sources) do
src[#src + 1] = "examples/" .. s
end
local depends = { crt }
local linux_libs = { "X11", "GL", "GLU", "stdc++", "m" }
if use_dynamic_xo then
depends[#depends + 1] = xo
else
depends[#depends + 1] = xo_static
depends[#depends + 1] = freetype
depends[#depends + 1] = utfz
linux_libs[#linux_libs + 1] = "expat"
linux_libs[#linux_libs + 1] = "pthread"
end
linux_libs.Config = "linux-*"
return Program {
Name = name,
Includes = { "xo" },
Libs = { linux_libs },
Depends = depends,
Sources = src,
}
end
local ExampleBench = XoExampleApp(true, "xoWinMain.cpp", "Bench", {"Bench.cpp"})
local ExampleCanvas = XoExampleApp(true, "xoWinMain.cpp", "Canvas", {"Canvas.cpp"})
local ExampleEvents = XoExampleApp(true, "xoWinMain.cpp", "Events", {"Events.cpp"})
local ExampleHelloWorld = XoExampleApp(true, "xoWinMain.cpp", "HelloWorld", {"HelloWorld.cpp"})
local ExampleSplineDev = XoExampleApp(true, "xoWinMain.cpp", "SplineDev", {"SplineDev.cpp"})
local ExampleLowLevel = XoExampleApp(true, "xoWinMainLowLevel.cpp", "RunAppLowLevel", {"RunAppLowLevel.cpp"})
local ExampleKitchenSink = XoExampleApp(true, "xoWinMain.cpp", "KitchenSink", {"KitchenSink.cpp", "SVGSamples.cpp"})
local ExampleKitchenSink_Static = XoExampleApp(false, "xoWinMain.cpp", "KitchenSinkStatic", {"KitchenSink.cpp", "SVGSamples.cpp"})
local ExampleReactive = XoExampleApp(true, "xoWinMain.cpp", "Reactive", {"Reactive.cpp"})
local Test = Program {
Name = "Test",
--SourceDir = ".",
Depends = {
xo,
crt,
},
Libs = {
{ "m", "stdc++", "pthread"; Config = "linux-*" },
},
PrecompiledHeader = {
Source = "tests/pch.cpp",
Header = "pch.h",
Pass = "PchGen",
},
Sources = {
makeGlob("tests", {}),
}
}
Default(xo)
Default(Test)
Default(ExampleBench)
Default(ExampleCanvas)
Default(ExampleEvents)
Default(ExampleHelloWorld)
Default(ExampleKitchenSink)
Default(ExampleLowLevel)
Default(ExampleReactive)