generated from TheCherno/ProjectTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolutionItems.lua
99 lines (92 loc) · 3 KB
/
SolutionItems.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
-- REF: https://github.com/premake/premake-core/issues/1061#issuecomment-1472057890
require("vstudio")
premake.api.register {
name = "solutionitems",
scope = "workspace",
kind = "table",
}
function recursiveSolutionItemsProject(wks, tbl)
for _, file in pairs(tbl) do
if type(_) ~= "number" then
local name = _
local tbl = file
premake.push('Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "'..name..'", "'..name..'", "{' .. os.uuid("Solution Items:"..wks.name..":"..name) .. '}"')
premake.push("ProjectSection(SolutionItems) = preProject")
local children = false
for _, file in pairs(file) do
if type(_) == "number" and type(file) == "string" then
for _, file in ipairs(os.matchfiles(file)) do
file = path.rebase(file, ".", wks.location)
premake.w(file.." = "..file)
end
end
if type(_) ~= "number" then
children = true
end
end
premake.pop("EndProjectSection")
premake.pop("EndProject")
if children then
recursiveSolutionItemsProject(wks, tbl)
end
end
end
end
premake.override(premake.vstudio.sln2005, "projects", function(base, wks)
if wks.solutionitems and #wks.solutionitems > 0 then
-- root level
premake.push('Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{' .. os.uuid("Solution Items:"..wks.name) .. '}"')
premake.push("ProjectSection(SolutionItems) = preProject")
for _, file in pairs(wks.solutionitems) do
if type(_) == "number" and type(file) == "string" then
for _, file in ipairs(os.matchfiles(file)) do
file = path.rebase(file, ".", wks.location)
premake.w(file.." = "..file)
end
end
end
premake.pop("EndProjectSection")
premake.pop("EndProject")
-- subprojects
recursiveSolutionItemsProject(wks, wks.solutionitems)
end
base(wks)
end)
function recursiveSolutionItemsNestedProjectLines(wks, parent, tbl)
local parent_uuid
if parent == "Solution Items" then
parent_uuid = os.uuid("Solution Items:"..wks.name)
else
parent_uuid = os.uuid("Solution Items:"..wks.name..":"..parent)
end
for _, file in pairs(tbl) do
if type(_) ~= "number" then
local name = _
local new_tbl = file
project_uuid = os.uuid("Solution Items:"..wks.name..":"..name)
premake.w("{%s} = {%s}", project_uuid, parent_uuid)
--print("child:", name, "parent:", parent)
recursiveSolutionItemsNestedProjectLines(wks, name, new_tbl)
end
end
end
premake.override(premake.vstudio.sln2005, "nestedProjects", function(base, wks)
premake.push("GlobalSection(NestedProjects) = preSolution")
-- base copy-paste START
local tr = premake.workspace.grouptree(wks)
if premake.tree.hasbranches(tr) then
premake.tree.traverse(tr, {
onnode = function(n)
if n.parent.uuid then
premake.w("{%s} = {%s}", (n.project or n).uuid, n.parent.uuid)
end
end
})
end
-- base copy-paste END
-- our START
parent = "Solution Items"
recursiveSolutionItemsNestedProjectLines(wks, parent, wks.solutionitems)
-- our END
premake.pop("EndGlobalSection")
end)