-
Notifications
You must be signed in to change notification settings - Fork 0
/
premake5.lua
259 lines (212 loc) · 9.68 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
--------------------------------------------------------------------------------
-- [ GLOBAL CONFIG ]
--------------------------------------------------------------------------------
root_dir = "./"
source_dir = "../../src/" -- relative to the project path
vendor_dir = "../../vendor/" -- relative to the project path
project_name = ""
premake_action = "none"
--------------------------------------------------------------------------------
-- [ WORKSPACE / SOLUTION CONFIG ]
--------------------------------------------------------------------------------
local function setup_solution()
workspace "sketchpad"
configurations { "Debug", "Release" }
platforms { "x64", "Win32" }
-- all variables are global by default unless the local keyword is used
-- _ACTION is the command line argument following premake5 (e.g. vs2019)
if _ACTION ~= nil then
premake_action = _ACTION
else
error("Please specify an action! (e.g. vs2019)")
end
-- where to place the solution files (.sln)
location(root_dir)
------------------------------------------------------------------------
-- [ COMPILER / LINKER CONFIG ]
------------------------------------------------------------------------
flags "FatalLinkWarnings" -- treat linker warnings as errors
warnings "Extra" -- set the number of warnings that are shown by the compiler to maximum level
filter { "platforms:*32" }
architecture "x86"
filter { "platforms:*64" }
architecture "x64"
filter "configurations:Debug"
defines { "DEBUG", "_DEBUG" }
symbols "On"
runtime "Debug"
filter "configurations:Release"
defines { "NDEBUG" }
optimize "On"
runtime "Release"
filter {} -- clear filter
------------------------------------------------------------------------
-- [ BUILD CONFIG ]
------------------------------------------------------------------------
filter { "system:windows", "action:vs*"} -- vs2015 ~ vs2019 build on Windows
systemversion "latest" -- use the latest version of the SDK available
flags { "MultiProcessorCompile" }
-- buildoptions { "-std=c++17" }
linkoptions {
"/ignore:4099", -- ignore library pdb warnings when running in debug
"/NODEFAULTLIB:libcmt.lib" -- fix LNK4098 warnings
}
filter {} -- clear filter
end
--------------------------------------------------------------------------------
-- [ PROJECT CONFIG ]
--------------------------------------------------------------------------------
-- this function is in global scope because it is called by each project's `build.lua` script.
-- inside this function, the working directory will be the project's folder, so be aware of relative paths.
-- [ CAVEAT: EXCEPTION ] any pre/post command must still use the root dir as the working directory.
function setup_project()
project(project_name)
kind "ConsoleApp"
language "C++"
cppdialect "C++17"
-- project's absolute path (path of the script that calls this function)
local abs_project_path = os.getcwd()
-- place the project files (.vcxproj) in the action folder under root dir
location("../../" .. premake_action .. "/")
-- this is the final application to ship, build the executable to app dir
if (project_name == "sketchpad") then
objdir("../../build/intermediates/" .. project_name .. "/%{cfg.buildcfg}/%{cfg.platform}")
targetdir("../../app/")
targetname "z-sketchpad" -- application name = z-sketchpad.exe
-- build all other sandbox chapters into the build folder
else
objdir("../../build/intermediates/" .. project_name .. "/%{cfg.buildcfg}/%{cfg.platform}")
targetdir("../../build/bin/" .. project_name .. "/%{cfg.buildcfg}/%{cfg.platform}")
targetname "Sandbox"
end
-- use main() instead of WinMain() as the application entry point
entrypoint "mainCRTStartup"
-- define macros (preprocessor definitions)
defines {
-- "FREEGLUT_STATIC", -- required only when freeglut is linked as a static lib
"GLEW_STATIC",
-- suppress C runtime secure warnings to use unsafe lib functions like scanf()
"_CRT_SECURE_NO_WARNINGS",
"_CRT_SECURE_NO_DEPRECATE",
"_SCL_SECURE_NO_WARNINGS",
-- TinyXML parser (read XML and create C++ objects, or vice versa)
"TIXML_USE_STL",
-- "DEBUG", "_DEBUG", -- will be automatically handled by Visual Studio
-- custom macros for various uses ......
"CANVAS_LOG=1", "CANVAS_CORE=1"
}
-- precompiled headers
-- pchheader "pch.h"
-- pchsource "src/pch.cpp"
------------------------------------------------------------------------
-- [ PROJECT FILES CONFIG ]
------------------------------------------------------------------------
files {
-- non-recursive search (solution level global source files, search depth = 1)
source_dir .. "*.h",
source_dir .. "*.hpp",
source_dir .. "*.c",
source_dir .. "*.cpp",
source_dir .. "*.tpp",
-- recursive search (all source files for the current project)
abs_project_path .. "/**.h",
abs_project_path .. "/**.hpp",
abs_project_path .. "/**.c",
abs_project_path .. "/**.cpp",
abs_project_path .. "/**.tpp",
abs_project_path .. "/**.glsl"
}
-- exclude template files from build so that they are not compiled
filter { "files:**.tpp" }
flags { "ExcludeFromBuild" }
-- exclude shaders from build
filter { "files:**.glsl" }
flags { "ExcludeFromBuild" }
filter {}
-- set up visual studio virtual folders
vpaths {
["Headers/*"] = {
source_dir .. "*.h",
source_dir .. "*.hpp",
abs_project_path .. "/**.h",
abs_project_path .. "/**.hpp"
},
["Sources/*"] = {
source_dir .. "*.c",
source_dir .. "*.cc",
source_dir .. "*.cpp",
abs_project_path .. "/**.c",
abs_project_path .. "/**.cc",
abs_project_path .. "/**.cpp"
},
["Shaders/*"] = {
abs_project_path .. "/**.glsl"
},
["Templates/*"] = {
source_dir .. "*.ipp",
source_dir .. "*.tpp",
abs_project_path .. "/**.tpp"
}
}
-- header files include directories
includedirs {
"../../src", -- solution level
abs_project_path, -- per project level
vendor_dir .. "GLEW/include",
vendor_dir .. "GLFW/include",
vendor_dir .. "GLUT/include",
-- header only libraries
"../../vendor",
vendor_dir .. "GLM/include",
vendor_dir .. "spdlog/include"
}
------------------------------------------------------------------------
-- [ PROJECT DEPENDENCY CONFIG ]
------------------------------------------------------------------------
-- paths for libraries (libs/dlls/etc) that are required when compiling
libdirs {
vendor_dir .. "GLEW/lib/%{cfg.platform}", -- GLEW: use the static library
vendor_dir .. "GLFW/lib-vc2019/%{cfg.platform}", -- GLFW: use the static library
-- GLUT v3.0.0 MSVC Package: only the dynamic library is available
vendor_dir .. "GLUT/lib/%{cfg.platform}"
}
-- specific library files (.lib .dll) to include
links {
"glew32s.lib",
"glfw3.lib",
"glu32", "opengl32", "gdi32", "winmm", "user32" -- Windows 10
}
------------------------------------------------------------------------
-- [ POST BUILD ACTIONS ]
------------------------------------------------------------------------
-- [ CAVEAT ] shell commands are executed later in a real build inside Visual
-- Studio, NOT here in premake, as a result, any pre/post command must use
-- the `action` folder (where .vcxproj file is stored) as the working directory.
postbuildmessage "Copying dynamic DLL file to the target path ..."
postbuildcommands {
"{COPY} ../vendor/GLUT/bin/%{cfg.platform}/freeglut.dll %{cfg.targetdir}"
}
-- keep the intermediate files after a build, we still need the `main.obj` file to debug
-- postbuildmessage "Cleaning up intermediate files ..."
-- postbuildcommands {
-- "{RMDIR} %{cfg.objdir}"
-- }
end
--------------------------------------------------------------------------------
-- [ ENTRY POINT ]
--------------------------------------------------------------------------------
local function main()
setup_solution()
local dirs = os.matchdirs("src/*")
for index, folder in ipairs(dirs) do
-- folder is relative path: e.g. "src/00_Basics"
local build_file = string.format("%s/build.lua", folder)
if (os.isfile(build_file)) then
-- index in Lua starts from 1, not 0 ...
project_name = string.sub(folder, 5)
printf("Setting up project %s", project_name)
dofile(build_file)
end
end
end
main()