More modernizing of VC 201x for extensibility

This commit is contained in:
Jason Perkins 2014-08-07 18:07:32 -04:00
parent 9044ece96f
commit 22d46ce57c
5 changed files with 119 additions and 70 deletions

View File

@ -247,7 +247,7 @@
return {
m.clCompile,
m.resourceCompile,
m.link,
m.linker,
m.manifest,
m.buildEvents,
m.imageXex,
@ -347,66 +347,87 @@
-- Write out the linker tool block.
--
m.elements.link = function(cfg, explicit)
m.elements.linker = function(cfg, explicit)
return {
m.subSystem,
m.generateDebugInformation,
m.optimizeReferences,
m.linkDynamic,
m.link,
m.lib,
m.linkLibraryDependencies,
}
end
m.elements.linkDynamic = function(cfg, explicit)
return {
m.additionalDependencies,
m.additionalLibraryDirectories,
m.importLibrary,
m.entryPointSymbol,
m.generateMapFile,
m.moduleDefinitionFile,
m.treatLinkerWarningAsErrors,
m.additionalLinkOptions,
}
end
m.elements.linkStatic = function(cfg, explicit)
return {
m.treatLinkerWarningAsErrors,
m.additionalLinkOptions,
}
end
function m.link(cfg)
_p(2,'<Link>')
function m.linker(cfg)
local explicit = vstudio.needsExplicitLink(cfg)
p.callArray(m.elements.link, cfg, explicit)
_p(2,'</Link>')
if cfg.kind == premake.STATICLIB then
m.linkStatic(cfg, explicit)
end
m.linkLibraryDependencies(cfg, explicit)
p.callArray(m.elements.linker, cfg, explicit)
end
function m.linkDynamic(cfg, explicit)
if cfg.kind ~= premake.STATICLIB then
p.callArray(m.elements.linkDynamic, cfg, explicit)
m.elements.link = function(cfg, explicit)
if cfg.kind == p.STATICLIB then
return {
m.subSystem,
m.generateDebugInformation,
m.optimizeReferences,
}
else
return {
m.subSystem,
m.generateDebugInformation,
m.optimizeReferences,
m.additionalDependencies,
m.additionalLibraryDirectories,
m.importLibrary,
m.entryPointSymbol,
m.generateMapFile,
m.moduleDefinitionFile,
m.treatLinkerWarningAsErrors,
m.additionalLinkOptions,
}
end
end
function m.linkStatic(cfg, explicit)
function m.link(cfg, explicit)
local contents = p.capture(function ()
p.callArray(m.elements.linkStatic, cfg, explicit)
p.push()
p.callArray(m.elements.link, cfg, explicit)
p.pop()
end)
if #contents > 0 then
_p(2,'<Lib>')
_p("%s", contents)
_p(2,'</Lib>')
p.push('<Link>')
p.outln(contents)
p.pop('</Link>')
end
end
m.elements.lib = function(cfg, explicit)
if cfg.kind == p.STATICLIB then
return {
m.treatLinkerWarningAsErrors,
m.additionalLinkOptions,
}
else
return {
}
end
end
function m.lib(cfg, explicit)
local contents = p.capture(function ()
p.push()
p.callArray(m.elements.lib, cfg, explicit)
p.pop()
end)
if #contents > 0 then
p.push('<Lib>')
p.outln(contents)
p.pop('</Lib>')
end
end
--
-- Write the manifest section.
--
@ -832,7 +853,7 @@
if #links > 0 then
links = path.translate(table.concat(links, ";"))
_x(3,'<AdditionalDependencies>%s;%%(AdditionalDependencies)</AdditionalDependencies>', links)
p.x('<AdditionalDependencies>%s;%%(AdditionalDependencies)</AdditionalDependencies>', links)
end
end

View File

@ -18,56 +18,84 @@
vc2010.xmlDeclaration()
vc2010.project()
for cfg in project.eachconfig(prj) do
_p(1,'<PropertyGroup %s>', vc2010.condition(cfg))
vc2010.debugsettings(cfg)
_p(1,'</PropertyGroup>')
p.push('<PropertyGroup %s>', vc2010.condition(cfg))
vc2010.debugSettings(cfg)
p.pop('</PropertyGroup>')
end
_p('</Project>')
end
function vc2010.debugsettings(cfg)
vc2010.localDebuggerCommand(cfg)
vc2010.localDebuggerWorkingDirectory(cfg)
vc2010.debuggerFlavor(cfg)
vc2010.localDebuggerCommandArguments(cfg)
vc2010.localDebuggerEnvironment(cfg)
vc2010.elements.debugSettings = function(cfg)
return {
vc2010.localDebuggerCommand,
vc2010.localDebuggerWorkingDirectory,
vc2010.debuggerFlavor,
vc2010.localDebuggerCommandArguments,
vc2010.localDebuggerEnvironment,
vc2010.localDebuggerMergeEnvironment,
}
end
function vc2010.debugSettings(cfg)
p.callArray(vc2010.elements.debugSettings, cfg)
end
function vc2010.debuggerFlavor(cfg)
if cfg.debugdir or cfg.debugcommand then
_p(2,'<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>')
p.w('<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>')
end
end
function vc2010.localDebuggerCommand(cfg)
if cfg.debugcommand then
local dir = project.getrelative(cfg.project, cfg.debugcommand)
_p(2,'<LocalDebuggerCommand>%s</LocalDebuggerCommand>', path.translate(dir))
p.w('<LocalDebuggerCommand>%s</LocalDebuggerCommand>', path.translate(dir))
end
end
function vc2010.localDebuggerCommandArguments(cfg)
if #cfg.debugargs > 0 then
_x(2,'<LocalDebuggerCommandArguments>%s</LocalDebuggerCommandArguments>', table.concat(cfg.debugargs, " "))
p.x('<LocalDebuggerCommandArguments>%s</LocalDebuggerCommandArguments>', table.concat(cfg.debugargs, " "))
end
end
function vc2010.localDebuggerWorkingDirectory(cfg)
if cfg.debugdir then
local dir = project.getrelative(cfg.project, cfg.debugdir)
_x(2,'<LocalDebuggerWorkingDirectory>%s</LocalDebuggerWorkingDirectory>', path.translate(dir))
p.x('<LocalDebuggerWorkingDirectory>%s</LocalDebuggerWorkingDirectory>', path.translate(dir))
end
end
function vc2010.localDebuggerEnvironment(cfg)
if #cfg.debugenvs > 0 then
local envs = table.concat(cfg.debugenvs, "\n")
if cfg.flags.DebugEnvsInherit then
envs = envs .. "\n$(LocalDebuggerEnvironment)"
end
_p(2,'<LocalDebuggerEnvironment>%s</LocalDebuggerEnvironment>', envs)
p.w('<LocalDebuggerEnvironment>%s</LocalDebuggerEnvironment>', envs)
if cfg.flags.DebugEnvsDontMerge then
_p(2,'<LocalDebuggerMergeEnvironment>false</LocalDebuggerMergeEnvironment>')
p.w(2,'<LocalDebuggerMergeEnvironment>false</LocalDebuggerMergeEnvironment>')
end
end
end
function vc2010.localDebuggerMergeEnvironment(cfg)
if #cfg.debugenvs > 0 and cfg.flags.DebugEnvsDontMerge then
p.w(2,'<LocalDebuggerMergeEnvironment>false</LocalDebuggerMergeEnvironment>')
end
end

View File

@ -21,7 +21,7 @@
local function prepare()
local cfg = test.getconfig(prj, "Debug")
vc2010.debugsettings(cfg)
vc2010.debugSettings(cfg)
end
@ -42,8 +42,8 @@
debugcommand "bin/emulator.exe"
prepare()
test.capture [[
<LocalDebuggerCommand>bin\emulator.exe</LocalDebuggerCommand>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommand>bin\emulator.exe</LocalDebuggerCommand>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
]]
end
@ -56,8 +56,8 @@
debugdir "bin/debug"
prepare()
test.capture [[
<LocalDebuggerWorkingDirectory>bin\debug</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerWorkingDirectory>bin\debug</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
]]
end
@ -69,7 +69,7 @@
debugargs { "arg1", "arg2" }
prepare()
test.capture [[
<LocalDebuggerCommandArguments>arg1 arg2</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>arg1 arg2</LocalDebuggerCommandArguments>
]]
end
@ -81,7 +81,7 @@
debugenvs { "key=value" }
prepare()
test.capture [[
<LocalDebuggerEnvironment>key=value</LocalDebuggerEnvironment>
<LocalDebuggerEnvironment>key=value</LocalDebuggerEnvironment>
]]
end
@ -93,7 +93,7 @@
debugenvs { "key=value", "foo=bar" }
prepare()
test.capture [[
<LocalDebuggerEnvironment>key=value
<LocalDebuggerEnvironment>key=value
foo=bar</LocalDebuggerEnvironment>
]]
end

View File

@ -36,7 +36,7 @@
local function prepare(platform)
local cfg = test.getconfig(prj, "Debug", platform)
vc2010.link(cfg)
vc2010.linker(cfg)
end

View File

@ -23,7 +23,7 @@
local function prepare(platform)
local cfg = test.getconfig(prj, "Debug", platform)
vc2010.link(cfg)
vc2010.linker(cfg)
end