-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxmake.lua
195 lines (172 loc) · 5.82 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
includes("xmake/swig.lua")
add_rules("mode.release", "mode.debug")
set_languages(is_plat("wasm") and "gnu11" or "c11")
option("language")
set_showmenu(true)
set_category("target_binding_language")
set_default("lua")
set_values("lua")
option_end()
option("lua_flavor")
set_showmenu(true)
set_category("lua_options/lua_flavor")
set_default("lua5.1")
set_values("luajit", "lua5.1", "lua5.2", "lua5.3", "lua5.4")
option_end()
option("expose_raymath")
set_showmenu(true)
set_category("expose_raymath")
set_default(true)
option_end()
option("expose_rlgl")
set_showmenu(true)
set_category("expose_rlgl")
set_default(true)
option_end()
option("use_and_expose_physac")
set_showmenu(true)
set_category("use_and_expose_physac")
set_default(false)
option_end()
local useSystemLua
local luadep
if is_plat("wasm") then
useSystemLua = false
else
useSystemLua = nil
end
if is_config("language", "lua") then
if is_config("lua_flavor", "luajit.*") then
add_requires("luajit 2.1.0-beta3", {system = useSystemLua})
luadep = function() add_packages("luajit") end
elseif is_config("lua_flavor", "lua5%.1.*") then
add_requires("lua 5.1", {system = useSystemLua})
luadep = function() add_packages("lua") end
elseif is_config("lua_flavor", "lua5%.2.*") then
add_requires("lua 5.2", {system = useSystemLua})
luadep = function() add_packages("lua") end
elseif is_config("lua_flavor", "lua5%.3.*") then
add_requires("lua 5.3", {system = useSystemLua})
luadep = function() add_packages("lua") end
elseif is_config("lua_flavor", "lua5%.4.*") then
add_requires("lua 5.4", {system = useSystemLua})
luadep = function() add_packages("lua") end
end
end
local raylibdep
local raylibflags
if is_plat("windows") or is_plat("mingw") then
raylibdep = function()
add_syslinks("gdi32", "user32", "winmm", "shell32")
end
raylibflags = {"-DPLATFORM_DESKTOP"}
elseif is_plat("linux") then
add_requires("libx11", "libxrandr", "libxrender", "libxinerama", "libxcursor", "libxi", "libxext")
raylibdep = function()
add_syslinks("pthread", "dl", "m")
add_packages("libx11", "libxrandr", "libxrender", "libxinerama", "libxcursor", "libxi", "libxext")
end
raylibflags = {"-DPLATFORM_DESKTOP", "-D_DEFAULT_SOURCE"}
elseif is_plat("bsd") then -- Untested
add_requires("libx11", "libxrandr", "libxrender", "libxinerama", "libxcursor", "libxi", "libxext")
raylibdep = function()
add_syslinks("pthread", "dl", "m")
add_packages("libx11", "libxrandr", "libxrender", "libxinerama", "libxcursor", "libxi", "libxext")
end
raylibflags = {"-DPLATFORM_DESKTOP"}
elseif is_plat("macosx") then -- Untested
raylibdep = function()
add_frameworks("CoreVideo", "CoreGraphics", "AppKit", "IOKit", "CoreFoundation", "Foundation")
end
raylibflags = {"-DPLATFORM_DESKTOP"}
elseif is_plat("android") then -- Untested
raylibdep = nil
raylibflags = {"-DPLATFORM_ANDROID", "-DGRAPHICS_API_OPENGL_ES2"}
elseif is_plat("iphoneos") then -- Untested
raylibdep = nil
raylibflags = {"-DPLATFORM_DESKTOP", "-DGRAPHICS_API_OPENGL_ES2"}
elseif is_plat("wasm") then
raylibdep = nil
raylibflags = {"-DPLATFORM_WEB", "-DGRAPHICS_API_OPENGL_ES2", "-D_GLFW_OSMESA"}
else
raylibdep = nil
raylibflags = {}
end
local swigflags = {"-Iraylib/src"}
if has_config("expose_raymath") then
table.insert(swigflags, "-DSWIGRAYLIB_EXPOSE_RAYMATH")
end
if has_config("expose_rlgl") then
table.insert(swigflags, "-DSWIGRAYLIB_EXPOSE_RLGL")
end
if has_config("use_and_expose_physac") then
table.insert(raylibflags, "-DPHYSAC_IMPLEMENTATION")
end
table.join2(swigflags, raylibflags)
local function core(useExternalGlfw, swigTargetLang)
if swigTargetLang == "lua" then
if luadep then luadep() end
table.insert(swigflags, "-no-old-metatable-bindings")
end
if raylibdep then raylibdep() end
if is_mode("release") then
add_cxflags(is_plat("wasm") and "-Os" or "-O3")
elseif is_mode("debug") then
add_cxflags("-Og")
add_cxflags("-pg")
add_ldflags("-pg")
end
add_includedirs("raylib/src")
add_files(
"raylib/src/rcore.c",
"raylib/src/rshapes.c",
"raylib/src/rtextures.c",
"raylib/src/rtext.c",
"raylib/src/rmodels.c",
"raylib/src/raudio.c",
"raylib/src/utils.c"
)
if useExternalGlfw then
add_ldflags("-lglfw")
else
add_includedirs("raylib/src/external/glfw/include")
add_files("raylib/src/rglfw.c")
end
add_rules("swig")
add_files("raylib.i", {
targetLang = swigTargetLang,
cppMode = false,
outDir = "gen/raylib.i/",
outName = "raylib.i."..tostring(swigTargetLang)..".$(plat).c",
extra = swigflags
})
add_cxflags(table.unpack(raylibflags))
end
target("swigraylib")
set_kind("shared")
set_default(true)
local langNameMapping =
{
-- [is_config("language", "lang")] = "lang",
[is_config("language", "lua")] = "lua",
}
local swigTargetLang = langNameMapping[true]
before_build(function(target)
if not swigTargetLang then
cprint("${yellow underline}Bindings to the target language are not implemented! Will do nothing. Please point to a implemented target with `xmake f --language=xxx`. ${clear}")
end
end)
local useExternalGlfw = false
if is_plat("mingw") then
add_ldflags("-static-libstdc++", "-static-libgcc")
elseif is_plat("wasm") then
useExternalGlfw = true
add_ldflags("-s USE_GLFW=3")
end
core(useExternalGlfw, swigTargetLang)
if swigTargetLang == "lua" then
set_prefixname("")
set_basename("raylib")
set_suffixname("")
end
target_end()