Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions modules/vstudio/tests/cs2005/test_compiler_props.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,15 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
]]
end


function suite.treatWarningsAsErrors_onFatalWarningsAPI()
fatalwarnings { "Compile" }
prepare()
test.capture [[
<DefineConstants></DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
]]
end
42 changes: 40 additions & 2 deletions modules/vstudio/tests/vc200x/test_compiler_block.lua
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
-- Verify the correct warnings settings are used when FatalWarnings are enabled.
--

function suite.runtimeLibraryIsDebug_onFatalWarnings()
function suite.runtimeLibraryIsDebug_onFatalWarningsViaFlag()
flags { "FatalWarnings" }
prepare()
test.capture [[
Expand All @@ -373,11 +373,30 @@
end


function suite.runtimeLibraryIsDebug_onFatalWarningsViaAPI()
fatalwarnings { "Compile" }
prepare()
test.capture [[
<Tool
Name="VCCLCompilerTool"
Optimization="0"
BasicRuntimeChecks="3"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
WarnAsError="true"
DebugInformationFormat="0"
/>
]]
end


--
-- Verify the correct warnings settings are used when no warnings are enabled.
--

function suite.runtimeLibraryIsDebug_onNoWarnings_whichDisablesAllOtherWarningsFlags()
function suite.runtimeLibraryIsDebug_onNoWarnings_whichDisablesAllOtherWarningsFlagsViaFlag()
flags { "FatalWarnings" }
warnings "Off"
prepare()
Expand All @@ -396,6 +415,25 @@
end


function suite.runtimeLibraryIsDebug_onNoWarnings_whichDisablesAllOtherWarningsFlagsViaAPI()
fatalwarnings { "Compile" }
warnings "Off"
prepare()
test.capture [[
<Tool
Name="VCCLCompilerTool"
Optimization="0"
BasicRuntimeChecks="3"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="0"
DebugInformationFormat="0"
/>
]]
end


--
-- Verify the correct Detect64BitPortabilityProblems settings are used when _ACTION < "VS2008".
--
Expand Down
28 changes: 27 additions & 1 deletion modules/vstudio/tests/vc2010/test_compile_settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>TurnOffAllWarnings</WarningLevel>
<Optimization>Disabled</Optimization>
]]
end


function suite.warningLevel_onNoWarningsOverOtherWarningsAPI()
fatalwarnings { "Compile" }
warnings "Off"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>TurnOffAllWarnings</WarningLevel>
<Optimization>Disabled</Optimization>
]]
end

Expand Down Expand Up @@ -544,7 +558,7 @@
-- Add <TreatWarningAsError> if FatalWarnings flag is set.
--

function suite.treatWarningsAsError_onFatalWarnings()
function suite.treatWarningsAsError_onFatalWarningsViaFlag()
flags { "FatalCompileWarnings" }
prepare()
test.capture [[
Expand All @@ -556,6 +570,18 @@
end


function suite.treatWarningsAsError_onFatalWarningsViaAPI()
fatalwarnings { "Compile" }
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
]]
end


--
-- Check the handling of the Symbols flag.
--
Expand Down
2 changes: 1 addition & 1 deletion modules/vstudio/vs2005_dotnetbase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
dotnetbase.allowUnsafeBlocks(cfg)
end

if cfg.flags.FatalCompileWarnings then
if p.hasFatalCompileWarnings(cfg.fatalwarnings) then
_p(2,'<TreatWarningsAsErrors>true</TreatWarningsAsErrors>')
end

Expand Down
2 changes: 1 addition & 1 deletion modules/vstudio/vs200x_vcproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@


function m.warnAsError(cfg)
if cfg.flags.FatalCompileWarnings and cfg.warnings ~= p.OFF then
if p.hasFatalCompileWarnings(cfg.fatalwarnings) and cfg.warnings ~= p.OFF then
p.w('WarnAsError="true"')
end
end
Expand Down
10 changes: 6 additions & 4 deletions modules/vstudio/vs2010_vcxproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3179,7 +3179,7 @@


function m.treatLinkerWarningAsErrors(cfg)
if cfg.flags.FatalLinkWarnings then
if p.hasFatalLinkWarnings(cfg.fatalwarnings) then
local el = iif(cfg.kind == p.STATICLIB, "Lib", "Linker")
m.element("Treat" .. el .. "WarningAsErrors", nil, "true")
end
Expand All @@ -3196,7 +3196,7 @@


function m.treatWarningAsError(cfg)
if cfg.flags.FatalCompileWarnings and cfg.warnings ~= p.OFF then
if p.hasFatalCompileWarnings(cfg.fatalwarnings) and cfg.warnings ~= p.OFF then
m.element("TreatWarningAsError", nil, "true")
end
end
Expand All @@ -3212,8 +3212,10 @@


function m.treatSpecificWarningsAsErrors(cfg, condition)
if #cfg.fatalwarnings > 0 then
local fatal = table.concat(cfg.fatalwarnings, ";")
local filteredWarnings = p.filterFatalWarnings(cfg.fatalwarnings)

if #filteredWarnings > 0 then
local fatal = table.concat(filteredWarnings, ";")
fatal = fatal .. ";%%(TreatSpecificWarningsAsErrors)"
m.element('TreatSpecificWarningsAsErrors', condition, fatal)
end
Expand Down
28 changes: 27 additions & 1 deletion modules/xcode/tests/test_xcode_project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2698,7 +2698,7 @@
end


function suite.XCBuildConfigurationProject_OnFatalWarnings()
function suite.XCBuildConfigurationProject_OnFatalWarningsViaFlag()
flags { "FatalWarnings" }
prepare()
xcode.XCBuildConfiguration_Project(tr, tr.configs[1])
Expand All @@ -2724,6 +2724,32 @@
end


function suite.XCBuildConfigurationProject_OnFatalWarningsViaAPI()
fatalwarnings { "Compile", "Link" }
prepare()
xcode.XCBuildConfiguration_Project(tr, tr.configs[1])
test.capture [[
A14350AC4595EE5E57CE36EC /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(NATIVE_ARCH_ACTUAL)";
CONFIGURATION_BUILD_DIR = "$(SYMROOT)";
CONFIGURATION_TEMP_DIR = "$(OBJROOT)";
GCC_OPTIMIZATION_LEVEL = 0;
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
OBJROOT = obj/Debug;
ONLY_ACTIVE_ARCH = NO;
SYMROOT = bin/Debug;
};
name = Debug;
};
]]
end


function suite.XCBuildConfigurationProject_OnFloatFast()
floatingpoint "Fast"
prepare()
Expand Down
2 changes: 1 addition & 1 deletion modules/xcode/xcode_common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@
settings['GCC_CHAR_IS_UNSIGNED_CHAR'] = iif(cfg.unsignedchar, "YES", "NO")
end

if cfg.flags.FatalWarnings then
if p.hasFatalCompileWarnings(cfg.fatalwarnings) and p.hasFatalLinkWarnings(cfg.fatalwarnings) then
settings['GCC_TREAT_WARNINGS_AS_ERRORS'] = 'YES'
end

Expand Down
58 changes: 53 additions & 5 deletions src/_premake_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,9 @@
"DebugEnvsDontMerge",
"DebugEnvsInherit",
"ExcludeFromBuild",
"FatalCompileWarnings",
"FatalLinkWarnings",
"FatalCompileWarnings", -- DEPRECATED
"FatalLinkWarnings", -- DEPRECATED
"FatalWarnings", -- DEPRECATED
"LinkTimeOptimization", -- DEPRECATED
"Maps",
"MFC",
Expand All @@ -357,9 +358,6 @@
"UndefinedIdentifiers",
"WPF",
},
aliases = {
FatalWarnings = { "FatalWarnings", "FatalCompileWarnings", "FatalLinkWarnings" },
},
}

api.register {
Expand Down Expand Up @@ -1113,6 +1111,56 @@
linktimeoptimization("Default")
end)

api.deprecateValue("flags", "FatalWarnings", "Use `fatalwarnings { \"Compile\", \"Link\" }` instead.",
function(value)
fatalwarnings({ "Compile", "Link" })
end,
function(value)
removefatalwarnings({ "Compile", "Link" })
end)

api.deprecateValue("flags", "FatalCompileWarnings", "Use `fatalwarnings { \"Compile\" }` instead.",
function(value)
fatalwarnings({ "Compile" })
end,
function(value)
removefatalwarnings({ "Compile" })
end)

api.deprecateValue("flags", "FatalLinkWarnings", "Use `fatalwarnings { \"Link\" }` instead.",
function(value)
fatalwarnings({ "Link" })
end,
function(value)
removefatalwarnings({ "Link" })
end)

premake.filterFatalWarnings = function(tbl)
if type(tbl) == "table" then
return table.filter(tbl, function(warning)
return not (warning == "Compile" or warning == "Link")
end)
else
return tbl
end
end

premake.hasFatalCompileWarnings = function(tbl)
if (type(tbl) == "table") then
return table.contains(tbl, "Compile")
else
return false
end
end

premake.hasFatalLinkWarnings = function(tbl)
if (type(tbl) == "table") then
return table.contains(tbl, "Link")
else
return false
end
end


-----------------------------------------------------------------------------
--
Expand Down
6 changes: 6 additions & 0 deletions src/tools/clang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@

clang.shared = {
architecture = gcc.shared.architecture,
fatalwarnings = {
Compile = "-Werror"
},
flags = gcc.shared.flags,
floatingpoint = {
Fast = "-ffast-math",
Expand Down Expand Up @@ -227,6 +230,9 @@
x86 = "-m32",
x86_64 = "-m64",
},
fatalwarnings = {
Link = "-Wl,--fatal-warnings",
},
linktimeoptimization = clang.shared.linktimeoptimization,
kind = {
SharedLib = function(cfg)
Expand Down
9 changes: 7 additions & 2 deletions src/tools/gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@
x86 = "-m32",
x86_64 = "-m64",
},
fatalwarnings = {
Compile = "-Werror",
},
flags = {
FatalCompileWarnings = "-Werror",
ShadowedVariables = "-Wshadow",
UndefinedIdentifiers = "-Wundef",
},
Expand Down Expand Up @@ -194,7 +196,7 @@
for _, disable in ipairs(cfg.disablewarnings) do
table.insert(result, '-Wno-' .. disable)
end
for _, fatal in ipairs(cfg.fatalwarnings) do
for _, fatal in ipairs(p.filterFatalWarnings(cfg.fatalwarnings)) do
table.insert(result, '-Werror=' .. fatal)
end
return result
Expand Down Expand Up @@ -473,6 +475,9 @@
x86 = "-m32",
x86_64 = "-m64",
},
fatalwarnings = {
Link = "-Wl,--fatal-warnings",
},
linktimeoptimization = gcc.shared.linktimeoptimization,
kind = {
SharedLib = function(cfg)
Expand Down
Loading