Merged in TurkeyMan/premake-dev/undefines (pull request #151)

Added 'undefines' api.
This commit is contained in:
Jason Perkins 2015-03-10 17:11:52 -04:00
commit 57880d8182
10 changed files with 111 additions and 3 deletions

View File

@ -790,6 +790,13 @@
end,
}
api.register {
name = "undefines",
scope = "config",
kind = "list:string",
tokens = true,
}
api.register {
name = "usingdirs",
scope = "config",
@ -849,7 +856,6 @@
}
-----------------------------------------------------------------------------
--
-- Handlers for deprecated fields and values.

View File

@ -380,7 +380,7 @@
function make.defines(cfg, toolset)
_p(' DEFINES +=%s', make.list(toolset.getdefines(cfg.defines)))
_p(' DEFINES +=%s', make.list(table.join(toolset.getdefines(cfg.defines), toolset.getundefines(cfg.undefines))))
end

View File

@ -460,6 +460,7 @@
m.additionalIncludeDirectories,
m.wholeProgramOptimization,
m.preprocessorDefinitions,
m.undefinePreprocessorDefinitions,
m.minimalRebuild,
m.basicRuntimeChecks,
m.bufferSecurityCheck,
@ -487,6 +488,7 @@
m.additionalExternalCompilerOptions,
m.additionalIncludeDirectories,
m.preprocessorDefinitions,
m.undefinePreprocessorDefinitions,
m.usePrecompiledHeader,
m.programDataBaseFileName,
m.debugInformationFormat,
@ -623,6 +625,7 @@
m.cleanCommandLine,
m.output,
m.preprocessorDefinitions,
m.undefinePreprocessorDefinitions,
m.includeSearchPath,
m.forcedIncludes,
m.assemblySearchPath,
@ -1393,6 +1396,12 @@
end
function m.undefinePreprocessorDefinitions(cfg)
if #cfg.undefines > 0 then
p.x('UndefinePreprocessorDefinitions="%s"', table.concat(cfg.undefines, ";"))
end
end
function m.programDatabaseFile(cfg, toolset)
if toolset then

View File

@ -293,6 +293,7 @@
m.treatWarningAsError,
m.basicRuntimeChecks,
m.clCompilePreprocessorDefinitions,
m.clCompileUndefinePreprocessorDefinitions,
m.clCompileAdditionalIncludeDirectories,
m.clCompileAdditionalUsingDirectories,
m.forceIncludes,
@ -605,6 +606,7 @@
local condition = m.condition(cfg)
m.objectFileName(fcfg)
m.clCompilePreprocessorDefinitions(fcfg, condition)
m.clCompileUndefinePreprocessorDefinitions(fcfg, condition)
m.optimization(fcfg, condition)
m.forceIncludes(fcfg, condition)
m.precompiledHeader(cfg, fcfg, condition)
@ -961,6 +963,11 @@
end
function m.clCompileUndefinePreprocessorDefinitions(cfg, condition)
m.undefinePreprocessorDefinitions(cfg, cfg.undefines, false, condition)
end
function m.clrSupport(cfg)
local value
if cfg.clr == "On" or cfg.clr == "Unsafe" then
@ -1429,6 +1436,18 @@
end
function m.undefinePreprocessorDefinitions(cfg, undefines, escapeQuotes, condition)
if #undefines > 0 then
undefines = table.concat(undefines, ";")
if escapeQuotes then
undefines = undefines:gsub('"', '\\"')
end
undefines = premake.esc(undefines) .. ";%%(UndefinePreprocessorDefinitions)"
m.element('UndefinePreprocessorDefinitions', condition, undefines)
end
end
function m.programDataBaseFileName(cfg)
-- just a placeholder for overriding; will use the default VS name
end

View File

@ -89,6 +89,14 @@
end
function clang.getundefines(undefines)
-- Just pass through to GCC for now
local flags = gcc.getundefines(undefines)
return flags
end
--

View File

@ -114,6 +114,14 @@
return result
end
function gcc.getundefines(undefines)
local result = {}
for _, undefine in ipairs(undefines) do
table.insert(result, '-U' .. undefine)
end
return result
end
--
-- Returns a list of forced include files, decorated for the compiler

View File

@ -104,7 +104,15 @@
function msc.getdefines(defines)
local result = {}
for _, define in ipairs(defines) do
table.insert(result, '-D' .. define)
table.insert(result, '/D"' .. define .. '"')
end
return result
end
function msc.getundefines(undefines)
local result = {}
for _, undefine in ipairs(undefines) do
table.insert(result, '/U"' .. undefine .. '"')
end
return result
end

View File

@ -236,6 +236,22 @@
end
--
-- If undefines are specified, the <UndefinePreprocessorDefinitions> element should be added.
--
function suite.preprocessorDefinitions_onUnDefines()
undefines { "DEBUG", "_DEBUG" }
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<UndefinePreprocessorDefinitions>DEBUG;_DEBUG;%(UndefinePreprocessorDefinitions)</UndefinePreprocessorDefinitions>
]]
end
--
-- If build options are specified, the <AdditionalOptions> element should be specified.
--

View File

@ -107,6 +107,23 @@
end
--
-- Check the defines and undefines.
--
function suite.defines()
defines "DEF"
prepare()
test.contains({ "-DDEF" }, gcc.getdefines(cfg.defines))
end
function suite.undefines()
undefines "UNDEF"
prepare()
test.contains({ "-UUNDEF" }, gcc.getundefines(cfg.undefines))
end
--
-- Check the optimization flags.
--

View File

@ -169,6 +169,23 @@
end
--
-- Check the defines and undefines.
--
function suite.defines()
defines "DEF"
prepare()
test.contains({ '/D"DEF"' }, msc.getdefines(cfg.defines))
end
function suite.undefines()
undefines "UNDEF"
prepare()
test.contains({ '/U"UNDEF"' }, msc.getundefines(cfg.undefines))
end
--
-- Check compilation options.
--