2014-08-11 21:02:36 +00:00
|
|
|
---
|
|
|
|
-- vs2010_rules_props.lua
|
|
|
|
-- Generate a Visual Studio 201x custom rules properties file.
|
|
|
|
-- Copyright (c) 2014 Jason Perkins and the Premake project
|
|
|
|
--
|
|
|
|
|
2014-08-27 14:40:36 +00:00
|
|
|
|
2014-08-11 21:02:36 +00:00
|
|
|
local p = premake
|
2017-04-25 05:44:13 +00:00
|
|
|
p.vstudio.vs2010.rules = {}
|
|
|
|
p.vstudio.vs2010.rules.props = {}
|
2014-08-11 21:02:36 +00:00
|
|
|
|
2017-04-25 05:44:13 +00:00
|
|
|
local m = p.vstudio.vs2010.rules.props
|
|
|
|
m.elements = {}
|
2014-08-11 21:02:36 +00:00
|
|
|
|
|
|
|
|
2014-08-14 21:37:35 +00:00
|
|
|
---
|
|
|
|
-- Entry point; generate the root <Project> element.
|
|
|
|
---
|
|
|
|
|
2014-08-14 21:45:44 +00:00
|
|
|
m.elements.project = function(r)
|
2014-08-11 21:50:55 +00:00
|
|
|
return {
|
|
|
|
p.vstudio.projectElement,
|
2014-08-14 21:37:35 +00:00
|
|
|
m.targetsGroup,
|
|
|
|
m.dependsOnGroup,
|
|
|
|
m.ruleGroup,
|
2014-08-11 21:50:55 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2014-08-14 21:45:44 +00:00
|
|
|
function m.generate(r)
|
2015-03-26 00:02:39 +00:00
|
|
|
p.xmlUtf8()
|
2014-08-14 21:45:44 +00:00
|
|
|
p.callArray(m.elements.project, r)
|
2014-08-11 21:50:55 +00:00
|
|
|
p.pop()
|
|
|
|
p.out('</Project>')
|
2014-08-11 21:02:36 +00:00
|
|
|
end
|
2014-08-14 21:37:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
-- Generate the targets property group element.
|
|
|
|
---
|
|
|
|
|
|
|
|
m.elements.targetsGroup = function(r)
|
|
|
|
return {
|
|
|
|
m.beforeTargets,
|
|
|
|
m.afterTargets,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function m.targetsGroup(r)
|
|
|
|
p.w('<PropertyGroup')
|
|
|
|
p.push(' Condition="\'$(%sBeforeTargets)\' == \'\' and \'$(%sAfterTargets)\' == \'\' and \'$(ConfigurationType)\' != \'Makefile\'">',
|
|
|
|
r.name, r.name)
|
|
|
|
p.callArray(m.elements.targetsGroup, r)
|
|
|
|
p.pop('</PropertyGroup>')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
-- Generate the dependencies property group element.
|
|
|
|
---
|
|
|
|
|
|
|
|
m.elements.dependsOnGroup = function(r)
|
|
|
|
return {
|
|
|
|
m.dependsOn,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function m.dependsOnGroup(r)
|
|
|
|
p.push('<PropertyGroup>')
|
|
|
|
p.callArray(m.elements.dependsOnGroup, r)
|
|
|
|
p.pop('</PropertyGroup>')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
-- Generate the rule itemm group element.
|
|
|
|
---
|
|
|
|
|
|
|
|
m.elements.ruleGroup = function(r)
|
|
|
|
return {
|
2014-08-27 14:40:36 +00:00
|
|
|
m.propertyDefaults,
|
2014-09-03 20:14:42 +00:00
|
|
|
m.commandLineTemplates,
|
|
|
|
m.executionDescription,
|
|
|
|
m.additionalDependencies,
|
2014-08-14 21:37:35 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function m.ruleGroup(r)
|
|
|
|
p.push('<ItemDefinitionGroup>')
|
|
|
|
p.push('<%s>', r.name)
|
2014-08-27 14:40:36 +00:00
|
|
|
p.callArray(m.elements.ruleGroup, r)
|
2014-08-14 21:37:35 +00:00
|
|
|
p.pop('</%s>', r.name)
|
|
|
|
p.pop('</ItemDefinitionGroup>')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-27 14:40:36 +00:00
|
|
|
---
|
|
|
|
-- Output the default values for all of the property definitions.
|
|
|
|
---
|
|
|
|
|
|
|
|
function m.propertyDefaults(r)
|
2015-05-05 18:46:00 +00:00
|
|
|
local defs = r.propertydefinition
|
2014-08-27 14:40:36 +00:00
|
|
|
for i = 1, #defs do
|
|
|
|
local def = defs[i]
|
2014-09-11 14:20:13 +00:00
|
|
|
local value = def.value
|
2014-08-27 14:40:36 +00:00
|
|
|
if value then
|
|
|
|
if def.kind == "path" then
|
|
|
|
value = path.translate(value)
|
|
|
|
end
|
|
|
|
p.w('<%s>%s</%s>', def.name, value, def.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-14 21:37:35 +00:00
|
|
|
---
|
|
|
|
-- Implementations of individual elements.
|
|
|
|
---
|
|
|
|
|
2014-09-03 20:14:42 +00:00
|
|
|
function m.additionalDependencies(r)
|
2015-05-05 18:46:00 +00:00
|
|
|
local deps = table.concat(r.builddependencies, ";")
|
2014-09-03 20:14:42 +00:00
|
|
|
p.x('<AdditionalDependencies>%s</AdditionalDependencies>', deps)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-14 21:37:35 +00:00
|
|
|
function m.afterTargets(r)
|
|
|
|
p.w('<%sAfterTargets>CustomBuild</%sAfterTargets>', r.name, r.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function m.beforeTargets(r)
|
|
|
|
p.w('<%sBeforeTargets>Midl</%sBeforeTargets>', r.name, r.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-09-03 20:14:42 +00:00
|
|
|
|
|
|
|
function m.commandLineTemplates(r)
|
2016-08-02 17:19:56 +00:00
|
|
|
-- create shadow context.
|
|
|
|
local env = p.rule.createEnvironment(r, "[%s]")
|
|
|
|
local ctx = p.context.extent(r, env)
|
2016-07-29 23:57:41 +00:00
|
|
|
|
2016-08-02 17:19:56 +00:00
|
|
|
-- now use the shadow context to detoken.
|
|
|
|
local buildcommands = ctx.buildcommands
|
2016-07-29 23:57:41 +00:00
|
|
|
|
2016-08-02 17:19:56 +00:00
|
|
|
-- write out the result.
|
|
|
|
if buildcommands and #buildcommands > 0 then
|
|
|
|
local cmds = os.translateCommands(buildcommands, p.WINDOWS)
|
2014-11-29 19:51:49 +00:00
|
|
|
cmds = table.concat(cmds, p.eol())
|
2017-04-27 10:47:33 +00:00
|
|
|
p.x('<CommandLineTemplate>%s</CommandLineTemplate>', cmds)
|
2014-09-03 20:14:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-14 21:37:35 +00:00
|
|
|
function m.dependsOn(r)
|
2016-08-01 21:40:40 +00:00
|
|
|
p.w('<%sDependsOn', r.name)
|
|
|
|
p.w(' Condition="\'$(ConfigurationType)\' != \'Makefile\'">_SelectedFiles;$(%sDependsOn)</%sDependsOn>',
|
|
|
|
r.name, r.name, r.name)
|
2014-08-14 21:37:35 +00:00
|
|
|
end
|
|
|
|
|
2014-09-03 20:14:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
function m.executionDescription(r)
|
2016-08-02 17:19:56 +00:00
|
|
|
-- create shadow context.
|
|
|
|
local env = p.rule.createEnvironment(r, "%%(%s)")
|
|
|
|
local ctx = p.context.extent(r, env)
|
2014-09-03 20:14:42 +00:00
|
|
|
|
2016-08-02 17:19:56 +00:00
|
|
|
-- now use the shadow context to detoken.
|
|
|
|
local buildmessage = ctx.buildmessage
|
2014-09-03 20:14:42 +00:00
|
|
|
|
2016-08-02 17:19:56 +00:00
|
|
|
-- write out the result.
|
|
|
|
if buildmessage and #buildmessage > 0 then
|
|
|
|
p.x('<ExecutionDescription>%s</ExecutionDescription>', buildmessage)
|
2014-09-03 20:14:42 +00:00
|
|
|
end
|
|
|
|
end
|
2016-08-02 17:19:56 +00:00
|
|
|
|