-
Notifications
You must be signed in to change notification settings - Fork 31
/
premake5.lua
executable file
·335 lines (259 loc) · 8.26 KB
/
premake5.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
334
335
local sep = "/"
local ext = ""
-- On Windows we have to use specific separator and executable extension.
if os.ishost("windows") then
sep = "\\"
ext = ".exe"
end
-- On Linux We have to query the dependencies of gtk+3 for NFD, and convert them to a list of libraries, we do this on the host for now.
if os.ishost("linux") then
gtkList, code = os.outputof("pkg-config --libs gtk+-3.0")
gtkLibs = string.explode(string.gsub(gtkList, "-l", ""), " ")
end
cwd = os.getcwd()
projects = {}
-- Options
newoption {
trigger = "skip_shader_validation",
description = "Do not validate shaders at application/tool compilation."
}
newoption {
trigger = "skip_internal",
description = "Do not generate any existing internal projects."
}
newoption {
trigger = "env_vulkan_sdk",
description = "Force the use of the Vulkan SDK at the location defined by the VULKAN_SDK environment variable"
}
-- Workspace definition.
workspace("Rendu")
-- Configurations
configurations({ "Release", "Dev"})
location("build")
targetdir ("build/%{prj.name}/%{cfg.longname}")
debugdir ("build/%{prj.name}/%{cfg.longname}")
architecture("x64")
systemversion("latest")
filter("system:macosx")
systemversion("10.12:latest")
filter({})
-- Configuration specific settings.
filter("configurations:Release")
defines({ "NDEBUG" })
optimize("On")
filter("configurations:Dev")
defines({ "DEBUG" })
symbols("On")
filter({})
startproject("ALL")
-- Helper functions for the projects.
function CommonSetup(relativeSrcRoot)
-- C++ settings
language("C++")
cppdialect("C++11")
-- Compiler flags
filter("toolset:not msc*")
buildoptions({ "-Wall", "-Wextra", "-Wno-unknown-pragmas" })
filter("toolset:msc*")
-- Ignore unknown pragmas.
buildoptions({ "-W3", "-wd4068"})
-- Ignore missing PDBs.
linkoptions({ "/IGNORE:4099"})
filter({})
-- System headers are used to support angled brackets in Xcode.
externalincludedirs({ relativeSrcRoot.."/libs/", relativeSrcRoot.."/libs/glfw/include/"})
filter({})
-- Vulkan dependencies
if _OPTIONS["env_vulkan_sdk"] then
externalincludedirs({ "$(VULKAN_SDK)/include" })
libdirs({ "$(VULKAN_SDK)/lib" })
else
filter("system:windows")
externalincludedirs({ "$(VULKAN_SDK)/include" })
libdirs({ "$(VULKAN_SDK)/lib" })
filter("system:macosx or linux")
externalincludedirs({ "/usr/local/include/" })
libdirs({ "/usr/local/lib" })
end
filter({})
end
function LinkSystemLibraries()
links({"nfd", "glfw3"})
-- Libraries for each platform.
filter("system:macosx")
links({"Cocoa.framework", "IOKit.framework", "CoreVideo.framework", "AppKit.framework", "pthread"})
filter("system:linux")
-- We have to query the dependencies of gtk+3 for NFD, and convert them to a list of libraries.
links({"X11", "Xi", "Xrandr", "Xxf86vm", "Xinerama", "Xcursor", "Xext", "Xrender", "Xfixes", "xcb", "Xau", "Xdmcp", "rt", "m", "pthread", "dl", gtkLibs})
filter("system:windows")
links({"comctl32"})
filter({})
-- Vulkan dependencies
filter("system:macosx or linux")
links({"glslang", "MachineIndependent", "GenericCodeGen", "OGLCompiler", "SPIRV", "SPIRV-Tools-opt", "SPIRV-Tools", "OSDependent", "spirv-cross-core", "spirv-cross-cpp" })
filter({"system:windows", "configurations:Dev"})
links({"glslangd", "OGLCompilerd", "SPIRVd", "OSDependentd", "MachineIndependentd", "GenericCodeGend", "SPIRV-Tools-optd", "SPIRV-Toolsd", "spirv-cross-cored", "spirv-cross-cppd" })
filter({"system:windows", "configurations:Release" })
links({"glslang", "OGLCompiler", "SPIRV", "OSDependent", "MachineIndependent", "GenericCodeGen", "SPIRV-Tools-opt", "SPIRV-Tools", "spirv-cross-core", "spirv-cross-cpp"})
filter({})
end
function ExecutableSetup()
kind("ConsoleApp")
CommonSetup("src")
-- Link with compiled librarires
includedirs({ "src/engine" })
links({"Engine"})
LinkSystemLibraries();
-- Register in the projects list for the ALL target.
table.insert(projects, project().name)
end
function ShaderValidation()
if _OPTIONS["skip_shader_validation"] then
return
end
-- Run the shader validator on all existing shaders.
-- Output IDE compatible error messages.
dependson({"ShaderValidator"})
filter("configurations:*")
postbuildcommands({
path.translate(cwd.."/build/ShaderValidator/%{cfg.longname}/ShaderValidator"..ext.." "..cwd.."/resources/", sep)
})
filter({})
end
function RegisterSourcesAndShaders(srcPath, shdPath)
files({ srcPath, shdPath })
removefiles({"**.DS_STORE", "**.thumbs"})
-- Reorganize file hierarchy in the IDE project.
vpaths({
["*"] = {srcPath},
["Shaders/*"] = {shdPath}
})
end
function AppSetup(appName)
ExecutableSetup()
ShaderValidation()
-- Declare src and resources files.
RegisterSourcesAndShaders("src/apps/"..appName.."/**", "resources/"..appName.."/shaders/**")
end
-- Projects
project("Engine")
CommonSetup("src")
kind("StaticLib")
includedirs({ "src/engine" })
-- Some additional files (README, scenes) are hidden, but you can display them in the project by uncommenting them below.
files({ "src/engine/**.hpp", "src/engine/**.cpp",
"resources/common/shaders/**",
"src/libs/**.hpp", "src/libs/*/*.cpp", "src/libs/**.h", "src/libs/*/*.c",
"premake5.lua",
"README.md",
-- "resources/**.scene"
})
removefiles { "src/libs/nfd/*" }
removefiles { "src/libs/glfw/*" }
removefiles({"**.DS_STORE", "**.thumbs"})
-- Virtual path allow us to get rid of the on-disk hierarchy.
vpaths({
["Engine/*"] = {"src/engine/**"},
["Shaders/*"] = {"resources/common/shaders/**"},
["Libraries/*"] = {"src/libs/**"},
[""] = { "*.*" },
-- ["Scenes/*"] = {"resources/**.scene"},
})
filter("system:macosx")
defines({"VK_USE_PLATFORM_MACOS_MVK"})
filter("system:windows")
defines({"VK_USE_PLATFORM_WIN32_KHR"})
filter("system:linux")
defines({"VK_USE_PLATFORM_XCB_KHR"})
group("Apps")
project("PBRDemo")
AppSetup("pbrdemo")
project("Playground")
AppSetup("playground")
project("Atmosphere")
AppSetup("atmosphere")
project("SnakeGame")
AppSetup("snakegame")
project("PathTracer")
AppSetup("pathtracer")
project("ImageFiltering")
AppSetup("imagefiltering")
project("ShaderBench")
AppSetup("shaderbench")
project("Island")
AppSetup("island")
project("Stenciled")
AppSetup("stenciled")
group("Tools")
project("BRDFEstimator")
ExecutableSetup()
ShaderValidation()
files({ "src/tools/BRDFEstimator.cpp" })
project("ControllerTest")
ExecutableSetup()
files({ "src/tools/ControllerTest.cpp" })
project("ImageViewer")
ExecutableSetup()
ShaderValidation()
RegisterSourcesAndShaders("src/tools/ImageViewer.cpp", "resources/imageviewer/shaders/**")
project("ObjToScene")
ExecutableSetup()
files({ "src/tools/objtoscene/*.cpp", "src/tools/objtoscene/*.hpp" })
project("SceneEditor")
ExecutableSetup()
ShaderValidation()
files({ "src/tools/sceneeditor/*.cpp", "src/tools/sceneeditor/*.hpp" })
project("ShaderValidator")
ExecutableSetup()
files({ "src/tools/ShaderValidator.cpp" })
group("Meta")
project("ALL")
kind("ConsoleApp")
CommonSetup("src")
dependson({ "Engine" })
dependson( projects )
-- We need a dummy file to execute.
files({ "src/tools/ALL.cpp" })
project("DOCS")
kind("ConsoleApp")
prebuildcommands({
path.translate("cd "..cwd),
path.translate("doxygen"..ext.." docs/Doxyfile")
})
-- We need a dummy file to execute.
files({ "src/tools/ALL.cpp" })
group("Dependencies")
-- Include NFD and GLFW premake files.
include("src/libs/nfd/premake5.lua")
include("src/libs/glfw/premake5.lua")
-- Actions
newaction {
trigger = "clean",
description = "Clean the build directory",
execute = function ()
print("Cleaning...")
os.rmdir("./build")
print("Done.")
end
}
newaction {
trigger = "docs",
description = "Build the documentation using Doxygen",
execute = function ()
print("Generating documentation...")
os.execute("doxygen"..ext.." docs/Doxyfile")
print("Done.")
end
}
newaction {
trigger = "list",
description = "List projects that will be built in the 'ALL' project",
execute = function ()
print("Found "..#projects.." projects:")
for i,v in ipairs(projects) do print(" * "..v) end
end
}
-- Internal private projects can be added here.
if (not _OPTIONS["skip_internal"]) and os.isfile("src/internal/premake5.lua") then
include("src/internal/premake5.lua")
end