-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmake.lua
195 lines (167 loc) · 6.9 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
set_project("VulkanKraft")
add_requires("glfw", "glm", "stb", "vulkan-hpp", "nlohmann_json")
if is_plat("windows", "mingw") then
add_requires("libcurl", {configs = {shared = false}})
else
add_requires("libcurl", {configs = {shared = true}})
end
rule("shader")
set_extensions(".vert", ".frag", ".glsl")
on_buildcmd_file(function(target, batchcmds, sourcefile_glsl, opt)
import("lib.detect.find_tool")
local glslc = assert(find_tool("glslc"), "glslc not found!")
local hpp_gen = path.join("build", os.host(), os.arch(), "release", "hpp_gen" .. (os.host() == "windows" and ".exe" or ""))
if not os.exists(hpp_gen) then
hpp_gen = path.join("build", os.host(), os.arch(), "debug", "hpp_gen" .. (os.host() == "windows" and ".exe" or ""))
assert(os.exists(hpp_gen), "hpp_gen has not been built yet. Run \"xmake build hpp_gen\"")
end
local flags = {}
local shader_stage
if path.extension(sourcefile_glsl) == ".glsl" then
local base = path.basename(sourcefile_glsl)
if base == "vert" then
shader_stage = "vert"
table.insert(flags, "-fshader-stage=vertex")
elseif base == "frag" then
shader_stage = "frag"
table.insert(flags, "-fshader-stage=fragment")
else
assert(false, "cannot determine shader stage of " .. sourcefile_glsl)
end
elseif path.extension(sourcefile_glsl) == ".vert" then
shader_stage = "vert"
elseif path.extension(sourcefile_glsl) == ".frag" then
shader_stage = "frag"
end
local spv_file = path.join("shaders_spv", path.basename(sourcefile_glsl) .. "." .. shader_stage .. ".spv")
table.insert(flags, sourcefile_glsl)
table.insert(flags, "-o")
table.insert(flags, spv_file)
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.glsl %s", sourcefile_glsl)
batchcmds:mkdir("shaders_spv")
batchcmds:vrunv(glslc.program, flags)
batchcmds:vrunv(hpp_gen, {spv_file, path.join(os.scriptdir(), "resources/shaders"), "true"})
batchcmds:add_depfiles(sourcefile_glsl, hpp_gen)
end)
rule("texture")
set_extensions(".png")
on_buildcmd_file(function(target, batchcmds, sourcefile_png, opt)
local hpp_gen = path.join("build", os.host(), os.arch(), "release", "hpp_gen" .. (os.host() == "windows" and ".exe" or ""))
if not os.exists(hpp_gen) then
hpp_gen = path.join("build", os.host(), os.arch(), "debug", "hpp_gen" .. (os.host() == "windows" and ".exe" or ""))
assert(os.exists(hpp_gen), "hpp_gen has not been built yet. Run \"xmake build hpp_gen\"")
end
batchcmds:show_progress(opt.progress, "${color.build.object}generating.hpp %s", sourcefile_png)
batchcmds:vrunv(hpp_gen, {sourcefile_png, path.join(os.scriptdir(), "resources/textures")})
batchcmds:add_depfiles(sourcefile_png, hpp_gen)
end)
rule("font")
set_extensions(".otf", ".ttf")
on_buildcmd_file(function(target, batchcmds, sourcefile_ttf, opt)
local hpp_gen = path.join("build", os.host(), os.arch(), "release", "hpp_gen" .. (os.host() == "windows" and ".exe" or ""))
if not os.exists(hpp_gen) then
hpp_gen = path.join("build", os.host(), os.arch(), "debug", "hpp_gen" .. (os.host() == "windows" and ".exe" or ""))
assert(os.exists(hpp_gen), "hpp_gen has not been built yet. Run \"xmake build hpp_gen\"")
end
batchcmds:show_progress(opt.progress, "${color.build.object}generating.hpp %s", sourcefile_ttf)
batchcmds:vrunv(hpp_gen, {sourcefile_ttf, path.join(os.scriptdir(), "resources/fonts")})
batchcmds:add_depfiles(sourcefile_ttf, hpp_gen)
end)
rule_end()
target("hpp_gen")
set_kind("binary")
set_languages("cxx17")
add_rules("mode.release")
add_files("cmd/hpp_gen/main.cpp")
target("resources")
set_kind("static")
on_load(function (target)
-- xmake fails on startup when this folder is missing
os.mkdir("resources")
end)
add_deps("hpp_gen")
add_rules("shader", "texture", "font")
add_files("shaders/*",
"textures/*.png",
"fonts/*")
target_end()
add_rules("mode.debug", "mode.release")
target("core")
set_kind("static")
set_languages("cxx17")
add_deps("resources")
add_packages("glfw", "glm", "stb", "vulkan-hpp", "nlohmann_json", "libcurl")
if is_plat("windows") then
local vulkan_path = os.getenv("VK_SDK_PATH")
if vulkan_path == nil then
print("couldn't find an installation of the Vulkan SDK. Make sure that the VK_SDK_PATH environment variable is set")
else
add_syslinks(path.join(vulkan_path, "Lib" .. (is_arch("x86") and "32" or ""), "vulkan-1"))
end
else
if is_plat("linux") then
add_syslinks("vulkan")
end
add_syslinks("pthread")
end
add_includedirs("resources")
add_files("src/core/*.cpp",
"src/core/vulkan/*.cpp",
"src/core/text/*.cpp",
"src/core/gui/*.cpp")
add_headerfiles("src/core/*.hpp",
"src/core/vulkan/*.hpp",
"src/core/text/*.hpp",
"src/core/gui/*.hpp")
target("vulkankraft")
set_kind("binary")
set_languages("cxx17")
add_deps("core")
add_packages("glfw", "glm", "stb", "vulkan-hpp")
add_files("src/*.cpp",
"src/chunk/*.cpp",
"src/block/*.cpp",
"src/world_gen/*.cpp",
"src/physics/*.cpp",
"src/save/*.cpp",
"src/item/*.cpp")
add_headerfiles("src/*.hpp",
"src/chunk/*.hpp",
"src/block/*.hpp",
"src/world_gen/*.hpp",
"src/physics/*.hpp",
"src/save/*.cpp",
"src/scene/*.hpp",
"src/item/*.hpp")
target("perlin_noise_test")
set_enabled(is_mode("debug"))
set_kind("binary")
set_languages("cxx17")
add_deps("core")
add_packages("glfw", "glm", "stb", "vulkan-hpp")
add_files("src/world_gen/perlin_noise.cpp",
"src/world_gen/perlin_noise_test/*.cpp")
add_headerfiles("src/world_gen/perlin_noise.hpp")
add_includedirs("resources")
target("texture_2d_test")
set_enabled(is_mode("debug"))
set_kind("binary")
set_languages("cxx17")
add_deps("core")
add_packages("glfw", "glm", "stb", "vulkan-hpp")
add_files("src/core/texture_2d_test/main.cpp")
target("physics_test")
set_enabled(is_mode("debug"))
set_kind("binary")
set_languages("cxx17")
add_packages("glm")
add_files("src/physics/aabb.cpp",
"src/physics/physics_test/main.cpp")
add_headerfiles("src/physics/aabb.hpp")
target("gui_test")
set_enabled(is_mode("debug"))
set_kind("binary")
set_languages("cxx17")
add_deps("core")
add_packages("glfw", "glm", "stb", "vulkan-hpp")
add_files("src/core/gui/gui_test/main.cpp")