-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFancyBuildSystem.lua
More file actions
229 lines (183 loc) · 6.59 KB
/
FancyBuildSystem.lua
File metadata and controls
229 lines (183 loc) · 6.59 KB
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
include "SolutionItems.lua"
require "ninja/ninja"
require "compilation-database/export-compile-commands"
FBS = {
Configurations = {},
Dependencies = {},
WorkspaceDirectory = os.getcwd(),
LoadedModules = {},
}
-- Utility function for converting the first character to uppercase
function FBS.FirstToUpper(str)
return (str:gsub("^%l", string.upper))
end
-- Utility function for generating an enum from a list of keys
function FBS.Enum(keys)
local Enum = {}
for _, value in ipairs(keys) do
Enum[value] = {}
end
return Enum
end
-- Utility function for checking if a given configuration is in the list of configurations
function FBS.IsInConfiguration(config)
return table.contains(FBS.Configurations, config)
end
-- Utility function for checking if a given configuration is in a group of configurations
function FBS.IsInConfigurationGroup(configs)
for _, config in ipairs(configs) do
if FBS.IsInConfiguration(config) then
return true
end
end
return false
end
function AddDependencyIncludes(table)
if table.IncludeDirs ~= nil then
externalincludedirs { table.IncludeDirs }
end
end
function AddDependencyDefines(table)
if table.Defines ~= nil then
defines { table.Defines }
end
end
function LinkDependency(table)
if table.LibDirs ~= nil then
libdirs { table.LibDirs }
end
local libsToLink = nil
if table.LibsToLink ~= nil then
libsToLink = table.LibsToLink
end
if libsToLink ~= nil then
links { libsToLink }
return true
end
return false
end
-- Include the dependencies for the given configuration
function FBS.IncludeDependencies(deps, config)
local target = FBS.FirstToUpper(os.target())
for key, libraryData in pairs(deps) do
if config == nil or libraryData.Configurations == nil or FBS.IsInConfigurationGroup(config) then
-- Process target scope
if libraryData[target] ~= nil then
AddDependencyIncludes(libraryData[target])
end
-- Process global scope
AddDependencyIncludes(libraryData)
end
end
end
-- Include the defines for the given configuration
function FBS.IncludeDefines(deps, config)
local target = FBS.FirstToUpper(os.target())
for key, libraryData in pairs(deps) do
if config == nil or libraryData.Configurations == nil or FBS.IsInConfigurationGroup(config) then
-- Process target scope
if libraryData[target] ~= nil then
AddDependencyDefines(libraryData[target])
end
-- Process global scope
AddDependencyDefines(libraryData)
end
end
end
-- Link the dependencies for the given configuration
function FBS.LinkDependencies(deps, config)
local target = FBS.FirstToUpper(os.target())
for key, libraryData in pairs(deps) do
if config == nil or libraryData.Configurations == nil or FBS.IsInConfigurationGroup(config) then
-- Process target scope
if libraryData[target] ~= nil then
LinkDependency(libraryData[target])
end
-- Process global scope
LinkDependency(libraryData)
end
end
end
-- Process the dependencies for the given configuration
function FBS.ProcessDependencies(config)
FBS.IncludeDependencies(FBS.Dependencies, config)
FBS.IncludeDefines(FBS.Dependencies, config)
FBS.LinkDependencies(FBS.Dependencies, config)
end
-- Process the local dependencies for the given configuration
-- Instead of a gloal dependencies table, this function uses the local dependencies table
function FBS.ProcessLocalDependencies(deps, config)
FBS.IncludeDependencies(deps, config)
FBS.IncludeDefines(deps, config)
FBS.LinkDependencies(deps, config)
end
function FBS.ImportModule(modulePath)
local path = modulePath .. "/Module.lua"
if FBS.LoadedModules[modulePath] then
print("Module already loaded, importing: " .. modulePath)
return FBS.LoadedModules[modulePath]
end
print ("Importing module: " .. path)
if not os.isfile(path) then
error("Module file not found: " .. path)
end
local module = include(path)
if module == nil then
error("Failed to import module: " .. path)
end
print("Module imported: " .. path)
local content = module(modulePath)
if content == nil then
error("Module did not return any content: " .. path)
end
FBS.LoadedModules[modulePath] = content
return content
end
-- Get a module by its path
function FBS.GetModule(modulePath)
if FBS.LoadedModules[modulePath] then
return FBS.LoadedModules[modulePath]
else
error("Module not found: " .. modulePath)
end
end
-- Merge dependencies from a base table with a collection of dependency tables
-- This function will merge platform-specific dependencies and other tables like LibsToLink and IncludeDirs
function FBS.MergeDependencies(baseDeps, depsCollection)
local target = FBS.FirstToUpper(os.target())
for _, value in pairs(depsCollection) do
for subKey, subValue in pairs(value) do
if subKey ~= "Name" then
if type(subValue) == "table" and (subKey == "Windows" or subKey == "Linux" or subKey == "Mac") then
-- Handle platform-specific tables
if subKey == target then
if not baseDeps[subKey] then
baseDeps[subKey] = {}
end
for platformKey, platformValue in pairs(subValue) do
if not baseDeps[subKey][platformKey] then
baseDeps[subKey][platformKey] = {}
end
if type(platformValue) == "table" then
for _, item in ipairs(platformValue) do
table.insert(baseDeps[subKey][platformKey], item)
end
else
baseDeps[subKey][platformKey] = platformValue
end
end
end
elseif type(subValue) == "table" then
-- Handle non-platform tables like LibsToLink and IncludeDirs
if not baseDeps[subKey] then
baseDeps[subKey] = {}
end
for _, item in ipairs(subValue) do
table.insert(baseDeps[subKey], item)
end
end
end
end
end
return baseDeps
end