Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions modules/vstudio/tests/_tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ return {

-- Visual Studio 2022+ C/C++ Projects
"vc2022/test_compile_settings.lua",
"vc2022/test_link.lua",
"vc2022/test_output_props.lua",
"vc2022/test_toolset_settings.lua",

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


function suite.treatWarningsAsErrors_onFatalWarningsAPI()
fatalwarnings { "Compile" }
fatalwarnings { "All" }
prepare()
test.capture [[
<DefineConstants></DefineConstants>
Expand Down
4 changes: 2 additions & 2 deletions modules/vstudio/tests/vc200x/test_compiler_block.lua
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@


function suite.runtimeLibraryIsDebug_onFatalWarningsViaAPI()
fatalwarnings { "Compile" }
fatalwarnings { "All" }
prepare()
test.capture [[
<Tool
Expand Down Expand Up @@ -416,7 +416,7 @@


function suite.runtimeLibraryIsDebug_onNoWarnings_whichDisablesAllOtherWarningsFlagsViaAPI()
fatalwarnings { "Compile" }
fatalwarnings { "All" }
warnings "Off"
prepare()
test.capture [[
Expand Down
4 changes: 2 additions & 2 deletions modules/vstudio/tests/vc2010/test_compile_settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@


function suite.warningLevel_onNoWarningsOverOtherWarningsAPI()
fatalwarnings { "Compile" }
fatalwarnings { "All" }
warnings "Off"
prepare()
test.capture [[
Expand Down Expand Up @@ -571,7 +571,7 @@


function suite.treatWarningsAsError_onFatalWarningsViaAPI()
fatalwarnings { "Compile" }
fatalwarnings { "All" }
prepare()
test.capture [[
<ClCompile>
Expand Down
20 changes: 9 additions & 11 deletions modules/vstudio/tests/vc2019/test_link.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,20 @@ local project = p.project

local function prepare(platform)
local cfg = test.getconfig(prj, "Debug", platform)
vc2010.configurationProperties(cfg)
vc2010.linker(cfg)
end

--
-- Check link command for a static library using a clang toolset
--

function suite.toolsetClangAdditionalDependencies()
function suite.additionalDependencies_onSystemLinks()
links { "lua", "zlib" }
toolset "clang"
prepare()
test.capture [[
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>lua.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
]]
end
links { "lua", "zlib" }
toolset "clang"
prepare()
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>lua.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
]]
end
40 changes: 40 additions & 0 deletions modules/vstudio/tests/vc2022/test_link.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--
-- tests/actions/vstudio/vc2010/test_compile_settings.lua
-- Validate compiler settings in Visual Studio 2019 C/C++ projects.
-- Copyright (c) 2011-2020 Jess Perkins and the Premake project
--

local p = premake
local suite = test.declare("vstudio_vs2022_link")
local vc2010 = p.vstudio.vc2010
local project = p.project

--
-- Setup
--

local wks, prj

function suite.setup()
p.action.set("vs2022")
wks, prj = test.createWorkspace()
end

local function prepare(platform)
local cfg = test.getconfig(prj, "Debug", platform)
vc2010.linker(cfg)
end

--
-- Check link command for a static library using a clang toolset
--

function suite.linkerFatalWarnings()
linkerfatalwarnings { "4123", "4124" }
prepare()
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<AdditionalOptions>/wx:4123,4124 %(AdditionalOptions)</AdditionalOptions>
]]
end
26 changes: 23 additions & 3 deletions modules/vstudio/vs2010_vcxproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2162,9 +2162,29 @@


function m.additionalLinkOptions(cfg)

local opts = {}

-- Get manually added link options
if #cfg.linkoptions > 0 then
local opts = table.concat(cfg.linkoptions, " ")
m.element("AdditionalOptions", nil, "%s %%(AdditionalOptions)", opts)
opts = cfg.linkoptions
end

-- Fatal warnings are only available from VS2022 onwards
-- https://learn.microsoft.com/en-us/cpp/build/reference/wx-treat-linker-warnings-as-errors?view=msvc-170

if _ACTION >= "vs2022" then
local filteredFatalWarnings = p.filterFatalWarnings(cfg.linkerfatalwarnings)

if #filteredFatalWarnings > 0 then
-- Create a comma-separated set of warnings to elevate as errors
table.insert(opts, '/wx:'..table.implode(filteredFatalWarnings, "", "", ","))
end
end

if #opts > 0 then
local additionalOptions = table.concat(opts, " ")
m.element("AdditionalOptions", condition, '%s %%(AdditionalOptions)', additionalOptions)
end
end

Expand Down Expand Up @@ -3485,7 +3505,7 @@


function m.treatLinkerWarningAsErrors(cfg)
if p.hasFatalLinkWarnings(cfg.fatalwarnings) then
if p.hasFatalLinkWarnings(cfg.linkerfatalwarnings) then
local el = iif(cfg.kind == p.STATICLIB, "Lib", "Linker")
m.element("Treat" .. el .. "WarningAsErrors", nil, "true")
end
Expand Down
3 changes: 2 additions & 1 deletion modules/xcode/tests/test_xcode_project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2725,7 +2725,8 @@


function suite.XCBuildConfigurationProject_OnFatalWarningsViaAPI()
fatalwarnings { "Compile", "Link" }
fatalwarnings { "All" }
linkerfatalwarnings { "All" }
prepare()
xcode.XCBuildConfiguration_Project(tr, tr.configs[1])
test.capture [[
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 p.hasFatalCompileWarnings(cfg.fatalwarnings) and p.hasFatalLinkWarnings(cfg.fatalwarnings) then
if p.hasFatalCompileWarnings(cfg.fatalwarnings) or p.hasFatalLinkWarnings(cfg.linkerfatalwarnings) then
settings['GCC_TREAT_WARNINGS_AS_ERRORS'] = 'YES'
end

Expand Down
37 changes: 24 additions & 13 deletions src/_premake_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@
name = "fatalwarnings",
scope = "config",
kind = "list:string",
tokens = true,
reserved = {
"All"
}
}

api.register {
Expand Down Expand Up @@ -582,6 +584,15 @@
}
}

api.register {
name = "linkerfatalwarnings",
scope = "config",
kind = "list:string",
reserved = {
"All"
}
}

api.register {
name = "location",
scope = { "project", "rule" },
Expand Down Expand Up @@ -1116,34 +1127,34 @@
linktimeoptimization("Default")
end)

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

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

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

premake.filterFatalWarnings = function(tbl)
if type(tbl) == "table" then
return table.filter(tbl, function(warning)
return not (warning == "Compile" or warning == "Link")
return not (warning == "All")
end)
else
return tbl
Expand All @@ -1152,15 +1163,15 @@

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

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