Add generated files to vxcproj file.

This commit is contained in:
Tom van Dijck 2016-06-17 10:22:41 -07:00
parent 453c1eda8e
commit a2170a4f9e
2 changed files with 86 additions and 3 deletions

View File

@ -30,6 +30,7 @@
m.elements.project = function(prj)
return {
m.xmlDeclaration,
m.updateFileTable,
m.project,
m.projectConfigurations,
m.globals,
@ -57,6 +58,60 @@
end
--
-- Update the file table with generated files.
--
function m.updateFileTable(prj)
local function addGeneratedFile(cfg, source, filename)
-- mark that we have generated files.
cfg.project.hasGeneratedFiles = true
-- add generated file to the project.
local files = cfg.project._.files
local node = files[filename]
if not node then
node = fileconfig.new(filename, cfg.project)
node.vpath = path.join("Generated", node.name)
node.dependsOn = source
node.generated = true
files[filename] = node
table.insert(files, node)
end
fileconfig.addconfig(node, cfg)
end
local function addFile(cfg, node)
local filecfg = fileconfig.getconfig(node, cfg)
if not filecfg or filecfg.flags.ExcludeFromBuild then
return
end
if fileconfig.hasCustomBuildRule(filecfg) then
local buildoutputs = p.project.getrelative(cfg.project, filecfg.buildoutputs)
if buildoutputs and #buildoutputs > 0 then
for _, output in ipairs(buildoutputs) do
addGeneratedFile(cfg, node, output)
end
end
else
--addRuleFile(cfg, node)
end
end
local files = table.shallowcopy(prj._.files)
for cfg in project.eachconfig(prj) do
table.foreachi(files, function(node)
addFile(cfg, node)
end)
end
-- we need to reassign object sequences if we generated any files.
if prj.hasGeneratedFiles and p.project.iscpp(prj) then
p.oven.assignObjectSequences(prj)
end
end
--
-- Output the XML declaration and opening <Project> tag.
@ -575,6 +630,15 @@
end
function m.generatedFile(cfg, file)
if file.generated then
local path = path.translate(file.dependsOn.relpath)
m.element("AutoGen", nil, 'true')
m.element("DependentUpon", nil, path)
end
end
---
-- Write out the list of source code files, and any associated configuration.
---
@ -598,7 +662,7 @@
priority = 1,
emitFiles = function(prj, group)
m.emitFiles(prj, group, "ClInclude")
m.emitFiles(prj, group, "ClInclude", {m.generatedFile})
end,
emitFilter = function(prj, group)
@ -638,7 +702,7 @@
end
end
m.emitFiles(prj, group, "ClCompile", nil, fileCfgFunc)
m.emitFiles(prj, group, "ClCompile", {m.generatedFile}, fileCfgFunc)
end,
emitFilter = function(prj, group)
@ -655,7 +719,7 @@
priority = 3,
emitFiles = function(prj, group)
m.emitFiles(prj, group, "None")
m.emitFiles(prj, group, "None", {m.generatedFile})
end,
emitFilter = function(prj, group)

View File

@ -274,6 +274,11 @@
local tr = tree.new(prj.name)
table.foreachi(prj._.files, function(fcfg)
-- if the file is a generated file, we add those in a second pass.
if fcfg.generated then
return;
end
-- The tree represents the logical source code tree to be displayed
-- in the IDE, not the physical organization of the file system. So
-- virtual paths are used when adding nodes.
@ -300,6 +305,20 @@
setmetatable(node, { __index = fcfg })
end)
table.foreachi(prj._.files, function(fcfg)
-- if the file is not a generated file, we already added them
if not fcfg.generated then
return;
end
local parent = tree.add(tr, path.getdirectory(fcfg.dependsOn.vpath))
local node = tree.insert(parent, tree.new(path.getname(fcfg.vpath)))
-- Pass through value fetches to the file configuration
setmetatable(node, { __index = fcfg })
end)
tree.trimroot(tr)
tree.sort(tr, sorter)