Exclude resource elements from Visual Studio when no resource files are present

This commit is contained in:
Jason Perkins 2014-12-23 20:05:40 -05:00
parent 247018cef0
commit e507d1a2fb
3 changed files with 50 additions and 22 deletions

View File

@ -338,10 +338,18 @@
end
function m.resourceCompile(cfg)
if cfg.system ~= premake.XBOX360 then
p.push('<ResourceCompile>')
p.callArray(m.elements.resourceCompile, cfg)
p.pop('</ResourceCompile>')
if cfg.system ~= premake.XBOX360 and config.hasResourceFiles(cfg) then
local contents = p.capture(function ()
p.push()
p.callArray(m.elements.resourceCompile, cfg)
p.pop()
end)
if #contents > 0 then
p.push('<ResourceCompile>')
p.outln(contents)
p.pop('</ResourceCompile>')
end
end
end

View File

@ -393,6 +393,22 @@
--
-- Determine if a configuration contains one or more resource files.
--
function config.hasResourceFiles(self)
local files = self.files
for i = 1, #files do
if path.isresourcefile(files[i]) then
return true
end
end
return false
end
--
-- Determine if the specified library or assembly reference should be copied
-- to the build's target directory. "Copy Local" is the terminology used by

View File

@ -26,16 +26,27 @@
end
--
-- Check the basic element structure with default settings.
--
-- Should only write the element if it is needed.
--
function suite.defaultSettings()
function suite.excluded_onNoResourceFiles()
prepare()
test.capture [[
<ResourceCompile>
</ResourceCompile>
]]
test.isemptycapture()
end
function suite.excluded_onNoSettings()
files { "hello.rc" }
prepare()
test.isemptycapture()
end
function suite.skips_onXbox360()
files { "hello.rc" }
defines { "DEBUG" }
system "Xbox360"
prepare()
test.isemptycapture()
end
@ -44,6 +55,7 @@
--
function suite.preprocessorDefinitions_onDefines()
files { "hello.rc" }
defines { "DEBUG" }
resdefines { "RESOURCES" }
prepare()
@ -59,6 +71,7 @@
--
function suite.additionalIncludeDirs_onIncludeDirs()
files { "hello.rc" }
includedirs { "include/lua" }
resincludedirs { "include/zlib" }
prepare()
@ -69,22 +82,12 @@
end
--
-- Xbox 360 doesn't use the resource compiler.
--
function suite.skips_onXbox360()
system "Xbox360"
prepare()
test.isemptycapture()
end
--
-- Test special escaping for preprocessor definition with quotes.
--
function suite.preprocessorDefinitions_onDefinesEscaping()
files { "hello.rc" }
defines { 'VERSION_STRING="1.0.0 (testing)"' }
prepare()
test.capture [[
@ -99,6 +102,7 @@
--
function suite.culture_en_US()
files { "hello.rc" }
locale "en-US"
prepare()
test.capture [[