-
Notifications
You must be signed in to change notification settings - Fork 0
/
dependencies.lua
159 lines (135 loc) · 4.16 KB
/
dependencies.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
target = string.lower(os.target()) -- Get the target platform (windows, linux, etc.)
VULKAN_SDK = os.getenv("VULKAN_SDK") -- Get the VulkanSDK path from the environment variables
--[[
The dependencies table is used to specify the dependencies of the project.
Here is an example of adding a dependency:
dependencyName = {
libName = "libName",
libDir = "path_to_lib_dir",
includeDir = "path_to_include_dir",
windows = {
debugLibName = "debugLibName",
},
configs = "Debug,Release"
}
Description of the fields:
- libName: The name of the dependency library file.
- libDir: Specifies where the lib file is located.
- includeDir: The path to the include directory of the dependency.
- windows: A scope for Windows-specific configurations. Linux, MacOS, etc. can be added in the same way.
- debugLibName: Some dependencies have different names for debug and release builds. This field is used to specify the debug library name.
- configs: A list of configurations that the dependency should be used in.
]]--
dependencies = {
vulkan = {
windows = {
libName = "vulkan-1",
libDir = "%{VULKAN_SDK}/Lib/",
},
includeDir = "%{VULKAN_SDK}/Include/",
},
glfw = {
libName = "GLFW",
includeDir = "%{wks.location}/Astranox/vendor/glfw/include",
},
glm = {
includeDir = "%{wks.location}/Astranox/vendor/glm",
},
stb_image = {
includeDir = "%{wks.location}/Astranox/vendor/stb_image",
},
tiny_obj_loader = {
includeDir = "%{wks.location}/Astranox/vendor/tiny_obj_loader",
},
vulkan_memory_allocator = {
includeDir = "%{wks.location}/Astranox/vendor/vulkan_memory_allocator",
},
shaderc = {
libName = "shaderc_shared",
includeDir = "%{wks.location}/Astranox/vendor/shaderc/glslc/src",
windows = {
debugLibName = "shaderc_sharedd",
},
},
shaderc_util = {
libName = "shaderc_util",
includeDir = "%{wks.location}/Astranox/vendor/shaderc/libshaderc_util/include",
windows = {
debugLibName = "shaderc_utild",
},
},
spirv_cross = {
libName = "spirv-cross-core",
windows = {
debugLibName = "spirv-cross-cored",
},
},
}
-- Functions for dependencies >>>
function _linkDependency(libDict, isDebug)
if libDict.libDir ~= nil then
libdirs { libDict.libDir }
end
-- Fetch the library name >>>
local libName = nil
if libDict.libName ~= nil then
libName = libDict.libName
end
-- If the configuration is debug and the debug library name is specified, use that for linking
if isDebug and libDict.debugLibName ~= nil and target == "windows" then
libName = libDict.debugLibName
end
-- <<< Fetch the library name
-- Link the library
if libName ~= nil then
links { libName }
return true
end
return false -- Indicates that the dependency was not linked
end
function _addDependencyIncludeDirs(libDict)
if libDict.includeDir ~= nil then
externalincludedirs { libDict.includeDir }
end
end
function processDependencies(configName)
for key, libDict in pairs(dependencies) do
local configMatched = true
-- If configuration is specified, only match the configuration
if configName ~= nil and libDict.configs ~= nil then
configMatched = string.find(libDict.configs, configName)
end
if configMatched then
local isDebug = configName == "Debug"
local linkSucceeded = false
-- Try to link the platform-specific scope
if libDict[target] ~= nil then
linkSucceeded = _linkDependency(libDict[target], isDebug)
_addDependencyIncludeDirs(libDict[target])
end
-- If the platform-specific scope was not linked, link the global scope
if not linkSucceeded then
_linkDependency(libDict, isDebug)
_addDependencyIncludeDirs(libDict)
end
end
end
end
function includeDependencies(configName)
for key, libDict in pairs(dependencies) do
local configMatched = true
-- If there is a configuration list, only match the configuration
if configName ~= nil and libDict.configs ~= nil then
configMatched = string.find(libDict.configs, configName)
end
if configMatched then
-- Include global scope
_addDependencyIncludeDirs(libDict)
-- Include platform-specific scope
if libDict[target] ~= nil then
_addDependencyIncludeDirs(libDict[target])
end
end
end
end
-- <<< Functions for dependencies