forked from zeromake/learnopengl-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmake.lua
119 lines (106 loc) · 3.62 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
add_rules("mode.release", "mode.debug")
rule("sokol_shader")
set_extensions(".glsl")
on_buildcmd_file(function (target, batchcmds, sourcefile, opt)
local targetfile = path.relative(sourcefile, "src")
batchcmds:mkdir(path.join("$(buildir)/sokol_shader", path.directory(targetfile)))
local targetfile = vformat(path.join("$(buildir)/sokol_shader", targetfile..".h"))
batchcmds:vrunv("sokol-shdc", {
"--ifdef",
"-l",
"hlsl5:glsl330:glsl300es:metal_macos:metal_ios",
"--input",
sourcefile,
"--output",
targetfile,
})
batchcmds:show_progress(opt.progress, "${color.build.object}glsl %s", sourcefile)
batchcmds:add_depfiles(sourcefile)
end)
rule_end()
add_rules("sokol_shader")
add_repositories("zeromake https://github.com/zeromake/xrepo.git")
add_requires("stb", "sokol", "handmade_math")
add_requires("imgui 1.x", {configs={backend="none"}})
if is_plat("windows") then
add_defines("SOKOL_WIN32_FORCE_MAIN")
add_cxflags("/utf-8")
elseif is_plat("mingw") then
add_ldflags("-static")
end
add_languages("c++20")
add_includedirs("libs/sokol")
if is_plat("windows", "mingw") then
-- add_defines("SOKOL_GLCORE33")
add_defines("SOKOL_D3D11")
elseif is_plat("macosx") then
add_defines("SOKOL_METAL")
elseif is_plat("wasm") then
add_defines("SOKOL_GLES3")
else
add_defines("SOKOL_GLCORE33")
end
local function split(input, delimiter)
if (delimiter == "") then return false end
local pos, arr = 0, {}
for st, sp in function() return string.find(input, delimiter, pos, true) end do
table.insert(arr, string.sub(input, pos, st - 1))
pos = sp + 1
end
table.insert(arr, string.sub(input, pos))
return arr
end
target("shader")
set_kind("object")
for _, f in ipairs(os.files("src/**/*.glsl")) do
add_files(f)
end
target_end()
target("sokol_wrapper")
set_kind("static")
add_packages("sokol")
if is_plat("macosx") then
add_files("libs/sokol/sokol.m")
add_frameworks(
"Appkit",
"QuartzCore",
"CoreGraphics",
"Metal",
"Metalkit"
)
else
add_files("libs/sokol/sokol.c")
end
target_end()
target("dbgui")
set_kind("static")
add_packages("sokol", "imgui")
add_files("libs/dbgui/dbgui.cc")
for _, dir in ipairs(os.filedirs("src/*")) do
if os.isdir(dir) and path.basename(dir) ~= "data" then
local includedir = path.join("$(buildir)/sokol_shader", path.basename(dir))
local arr = split(path.basename(dir), '-')
local targetname = arr[1].."-"..arr[2]
for _, f in ipairs(os.files(dir.."/*.c")) do
target(targetname.."-"..(split(path.basename(f), '-')[1]))
add_packages("stb", "sokol", "handmade_math")
add_files(f)
if is_plat("windows", "mingw") then
add_files("src/resource.rc")
elseif is_plat("wasm") then
add_ldflags("-sMAX_WEBGL_VERSION=2")
set_extension(".js")
add_ldflags("-sSTACK_SIZE=512KB")
add_ldflags("-sTOTAL_MEMORY="..(1024*1024*32))
add_ldflags("-sALLOW_MEMORY_GROWTH=1")
add_ldflags("-sMALLOC=\"emmalloc\"")
end
add_includedirs(includedir)
add_includedirs("libs")
add_deps("sokol_wrapper", "shader", "dbgui")
set_rundir("src/data")
add_defines("USE_DBG_UI")
target_end()
end
end
end