Improve external include & warning support

This commit is contained in:
Chad Engler 2021-11-13 09:16:16 -08:00
parent 24e5c8d2ab
commit 065b3acb2f
No known key found for this signature in database
GPG Key ID: 447DF683B71FB0BE
30 changed files with 527 additions and 77 deletions

View File

@ -1,7 +1,7 @@
project "curl-lib" project "curl-lib"
language "C" language "C"
kind "StaticLib" kind "StaticLib"
sysincludedirs { "include" } externalincludedirs { "include" }
includedirs { "lib", "../mbedtls/include" } includedirs { "lib", "../mbedtls/include" }
defines { "BUILDING_LIBCURL", "CURL_STATICLIB", "HTTP_ONLY" } defines { "BUILDING_LIBCURL", "CURL_STATICLIB", "HTTP_ONLY" }
warnings "off" warnings "off"

View File

@ -197,10 +197,10 @@
end end
local toolset = m.getcompiler(cfg) local toolset = m.getcompiler(cfg)
local sysincludedirs = toolset.getincludedirs(cfg, {}, cfg.sysincludedirs, cfg.frameworkdirs) local externalincludedirs = toolset.getincludedirs(cfg, {}, cfg.externalincludedirs, cfg.frameworkdirs)
local forceincludes = toolset.getforceincludes(cfg) local forceincludes = toolset.getforceincludes(cfg)
local cxxflags = table.concat(table.join(sysincludedirs, toolset.getcxxflags(cfg), forceincludes, cfg.buildoptions), ";") local cxxflags = table.concat(table.join(externalincludedirs, toolset.getcxxflags(cfg), forceincludes, cfg.buildoptions), ";")
local cflags = table.concat(table.join(sysincludedirs, toolset.getcflags(cfg), forceincludes, cfg.buildoptions), ";") local cflags = table.concat(table.join(externalincludedirs, toolset.getcflags(cfg), forceincludes, cfg.buildoptions), ";")
local asmflags = "" local asmflags = ""
local pch = p.tools.gcc.getpch(cfg) local pch = p.tools.gcc.getpch(cfg)
local usepch = "yes" local usepch = "yes"
@ -248,7 +248,7 @@
local options = table.concat(cfg.resoptions, ";") local options = table.concat(cfg.resoptions, ";")
_x(3, '<ResourceCompiler Options="%s%s" Required="yes">', defines, options) _x(3, '<ResourceCompiler Options="%s%s" Required="yes">', defines, options)
for _, includepath in ipairs(table.join(cfg.sysincludedirs, cfg.includedirs, cfg.resincludedirs)) do for _, includepath in ipairs(table.join(cfg.externalincludedirs, cfg.includedirs, cfg.resincludedirs)) do
_x(4, '<IncludePath Value="%s"/>', project.getrelative(cfg.project, includepath)) _x(4, '<IncludePath Value="%s"/>', project.getrelative(cfg.project, includepath))
end end
_p(3, '</ResourceCompiler>') _p(3, '</ResourceCompiler>')

View File

@ -77,7 +77,7 @@
end end
function suite.OnProjectCfg_SysIncludes() function suite.OnProjectCfg_SysIncludes()
sysincludedirs { "sysdir", "sysdir2/"} externalincludedirs { "sysdir", "sysdir2/"}
prepare() prepare()
codelite.project.compiler(cfg) codelite.project.compiler(cfg)
test.capture [[ test.capture [[
@ -188,7 +188,7 @@
function suite.OnProjectCfg_ResSysInclude() function suite.OnProjectCfg_ResSysInclude()
files { "x.rc" } files { "x.rc" }
sysincludedirs { "sysdir/" } externalincludedirs { "sysdir/" }
prepare() prepare()
codelite.project.resourceCompiler(cfg) codelite.project.resourceCompiler(cfg)
test.capture [[ test.capture [[

View File

@ -521,7 +521,7 @@ end
function make.includes(cfg, toolset) function make.includes(cfg, toolset)
local includes = toolset.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs, cfg.frameworkdirs) local includes = toolset.getincludedirs(cfg, cfg.includedirs, cfg.externalincludedirs, cfg.frameworkdirs)
_p(' INCLUDES +=%s', make.list(includes)) _p(' INCLUDES +=%s', make.list(includes))
end end

View File

@ -386,7 +386,7 @@
function cpp.includes(cfg, toolset) function cpp.includes(cfg, toolset)
local includes = toolset.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs, cfg.frameworkdirs) local includes = toolset.getincludedirs(cfg, cfg.includedirs, cfg.externalincludedirs, cfg.frameworkdirs)
p.outln('INCLUDES +=' .. gmake2.list(includes)) p.outln('INCLUDES +=' .. gmake2.list(includes))
end end
@ -531,8 +531,8 @@
end end
end end
if fcfg.includedirs or fcfg.sysincludedirs or fcfg.frameworkdirs then if fcfg.includedirs or fcfg.externalincludedirs or fcfg.frameworkdirs then
local includes = toolset.getincludedirs(cfg, fcfg.includedirs, fcfg.sysincludedirs, fcfg.frameworkdirs) local includes = toolset.getincludedirs(cfg, fcfg.includedirs, fcfg.externalincludedirs, fcfg.frameworkdirs)
if #includes > 0 then if #includes > 0 then
value = value .. gmake2.list(includes) value = value .. gmake2.list(includes)
end end

View File

@ -142,6 +142,16 @@
tokens = true, tokens = true,
} }
p.api.register {
name = "externalanglebrackets",
scope = "config",
kind = "string",
allowed = {
"On",
"Off",
},
}
p.api.register { -- DEPRECATED 2019-10-21 p.api.register { -- DEPRECATED 2019-10-21
name = "debuggerflavor", name = "debuggerflavor",
scope = "config", scope = "config",
@ -174,5 +184,6 @@
_ACTION == "vs2015" or _ACTION == "vs2015" or
_ACTION == "vs2017" or _ACTION == "vs2017" or
_ACTION == "vs2019" or _ACTION == "vs2019" or
_ACTION == "vs2022" or
false; false;
end end

View File

@ -104,5 +104,7 @@ return {
"vc2019/test_toolset_settings.lua", "vc2019/test_toolset_settings.lua",
-- Visual Studio 2022+ C/C++ Projects -- Visual Studio 2022+ C/C++ Projects
"vc2022/test_compile_settings.lua",
"vc2022/test_output_props.lua",
"vc2022/test_toolset_settings.lua" "vc2022/test_toolset_settings.lua"
} }

View File

@ -162,8 +162,8 @@ command 2</NMakeBuildCommandLine>
]] ]]
end end
function suite.onSysIncludeDirs() function suite.onExternalIncludeDirs()
sysincludedirs { "include/lua", "include/zlib" } externalincludedirs { "include/lua", "include/zlib" }
prepare() prepare()
test.capture [[ test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">

View File

@ -222,8 +222,8 @@
-- Check the handling of the VC++ Directories. -- Check the handling of the VC++ Directories.
-- --
function suite.onSystemIncludeDirs() function suite.onExternalIncludeDirs()
sysincludedirs { "$(DXSDK_DIR)/Include" } externalincludedirs { "$(DXSDK_DIR)/Include" }
prepare() prepare()
test.capture [[ test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">

View File

@ -0,0 +1,118 @@
--
-- tests/actions/vstudio/vc2022/test_compile_settings.lua
-- Validate compiler settings in Visual Studio 2022 C/C++ projects.
-- Copyright (c) 2011-2021 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("vstudio_vs2022_compile_settings")
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.clCompile(cfg)
end
--
-- Check ClCompile for ExternalWarningLevel
--
function suite.ExternalWarningLevelOff()
externalwarnings "Off"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<ExternalWarningLevel>TurnOffAllWarnings</ExternalWarningLevel>
]]
end
function suite.ExternalWarningLevelDefault()
externalwarnings "Default"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
]]
end
function suite.ExternalWarningLevelHigh()
externalwarnings "High"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<ExternalWarningLevel>Level4</ExternalWarningLevel>
]]
end
function suite.ExternalWarningLevelExtra()
externalwarnings "Extra"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<ExternalWarningLevel>Level4</ExternalWarningLevel>
]]
end
function suite.ExternalWarningLevelEverything()
externalwarnings "Everything"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<ExternalWarningLevel>Level4</ExternalWarningLevel>
]]
end
--
-- Check ClCompile for TreatAngleIncludeAsExternal
--
function suite.TreatAngleIncludeAsExternalOn()
externalanglebrackets "On"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
<TreatAngleIncludeAsExternal>true</TreatAngleIncludeAsExternal>
]]
end
function suite.TreatAngleIncludeAsExternalOff()
externalanglebrackets "Off"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
<TreatAngleIncludeAsExternal>false</TreatAngleIncludeAsExternal>
]]
end

View File

@ -0,0 +1,45 @@
--
-- tests/actions/vstudio/vc2022/test_output_props.lua
-- Validate generation of the output property groups.
-- Copyright (c) 2021 Jason Perkins and the Premake project
--
local p = premake
local suite = test.declare("vstudio_vs2022_output_props")
local vc2010 = p.vstudio.vc2010
--
-- Setup
--
local wks, prj
function suite.setup()
p.action.set("vs2022")
wks, prj = test.createWorkspace()
end
local function prepare()
local cfg = test.getconfig(prj, "Debug")
vc2010.outputProperties(cfg)
end
--
-- Check the handling of the VC++ Directories.
--
function suite.onExternalIncludeDirs()
externalincludedirs { "src/include" }
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>bin\Debug\</OutDir>
<IntDir>obj\Debug\</IntDir>
<TargetName>MyProject</TargetName>
<TargetExt>.exe</TargetExt>
<ExternalIncludePath>src\include;$(ExternalIncludePath)</ExternalIncludePath>
</PropertyGroup>
]]
end

View File

@ -1,5 +1,5 @@
-- --
-- tests/actions/vstudio/vc2010/test_compile_settings.lua -- tests/actions/vstudio/vc2022/test_compile_settings.lua
-- Validate compiler settings in Visual Studio 2022 C/C++ projects. -- Validate compiler settings in Visual Studio 2022 C/C++ projects.
-- Copyright (c) 2011-2021 Jason Perkins and the Premake project -- Copyright (c) 2011-2021 Jason Perkins and the Premake project
-- --

View File

@ -395,6 +395,8 @@
m.useFullPaths, m.useFullPaths,
m.removeUnreferencedCodeData, m.removeUnreferencedCodeData,
m.compileAsWinRT, m.compileAsWinRT,
m.externalWarningLevel,
m.externalAngleBrackets,
} }
if cfg.kind == p.STATICLIB then if cfg.kind == p.STATICLIB then
@ -818,6 +820,8 @@
m.runtimeTypeInfo, m.runtimeTypeInfo,
m.warningLevelFile, m.warningLevelFile,
m.compileAsWinRT, m.compileAsWinRT,
m.externalWarningLevel,
m.externalAngleBrackets,
} }
else else
return { return {
@ -2154,9 +2158,13 @@
function m.includePath(cfg) function m.includePath(cfg)
local dirs = vstudio.path(cfg, cfg.sysincludedirs) local dirs = vstudio.path(cfg, cfg.externalincludedirs)
if #dirs > 0 then if #dirs > 0 then
m.element("IncludePath", nil, "%s;$(IncludePath)", table.concat(dirs, ";")) if _ACTION < "vs2022" then
m.element("IncludePath", nil, "%s;$(IncludePath)", table.concat(dirs, ";"))
else
m.element("ExternalIncludePath", nil, "%s;$(ExternalIncludePath)", table.concat(dirs, ";"))
end
end end
end end
@ -2596,7 +2604,8 @@
function m.resourceAdditionalIncludeDirectories(cfg) function m.resourceAdditionalIncludeDirectories(cfg)
m.additionalIncludeDirectories(cfg, table.join(cfg.includedirs, cfg.resincludedirs)) local dirs = table.join(cfg.includedirs, cfg.resincludedirs)
m.additionalIncludeDirectories(cfg, dirs)
end end
@ -2845,6 +2854,25 @@
end end
function m.externalWarningLevel(cfg)
if _ACTION >= "vs2022" then
local map = { Off = "TurnOffAllWarnings", High = "Level4", Extra = "Level4", Everything = "Level4" }
m.element("ExternalWarningLevel", nil, map[cfg.externalwarnings] or "Level3")
end
end
function m.externalAngleBrackets(cfg)
if _ACTION >= "vs2022" then
if cfg.externalanglebrackets == p.OFF then
m.element("TreatAngleIncludeAsExternal", condition, "false")
elseif cfg.externalanglebrackets == p.ON then
m.element("TreatAngleIncludeAsExternal", condition, "true")
end
end
end
function m.xmlDeclaration() function m.xmlDeclaration()
p.xmlUtf8() p.xmlUtf8()
end end

View File

@ -2398,8 +2398,8 @@
]] ]]
end end
function suite.XCBuildConfigurationProject_OnSysIncludeDirs() function suite.XCBuildConfigurationProject_OnExternalIncludeDirs()
sysincludedirs { "../include", "../libs", "../name with spaces" } externalincludedirs { "../include", "../libs", "../name with spaces" }
prepare() prepare()
xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) xcode.XCBuildConfiguration_Project(tr, tr.configs[1])
test.capture [[ test.capture [[
@ -3489,7 +3489,7 @@
}; };
]] ]]
end end
function suite.XCBuildConfigurationProject_OnCpp11() function suite.XCBuildConfigurationProject_OnCpp11()
workspace("MyWorkspace") workspace("MyWorkspace")
cppdialect("C++11") cppdialect("C++11")
@ -3567,7 +3567,7 @@
}; };
]] ]]
end end
function suite.XCBuildConfigurationProject_OnCpp1y() function suite.XCBuildConfigurationProject_OnCpp1y()
workspace("MyWorkspace") workspace("MyWorkspace")
cppdialect("C++1y") cppdialect("C++1y")
@ -3619,7 +3619,7 @@
}; };
]] ]]
end end
function suite.XCBuildConfigurationProject_OnCpp1z() function suite.XCBuildConfigurationProject_OnCpp1z()
workspace("MyWorkspace") workspace("MyWorkspace")
cppdialect("C++1z") cppdialect("C++1z")
@ -3671,7 +3671,7 @@
}; };
]] ]]
end end
function suite.XCBuildConfigurationProject_OnCpp2a() function suite.XCBuildConfigurationProject_OnCpp2a()
workspace("MyWorkspace") workspace("MyWorkspace")
cppdialect("C++2a") cppdialect("C++2a")
@ -3749,7 +3749,7 @@
}; };
]] ]]
end end
function suite.XCBuildConfigurationProject_OnCppGnu0x() function suite.XCBuildConfigurationProject_OnCppGnu0x()
workspace("MyWorkspace") workspace("MyWorkspace")
cppdialect("gnu++0x") cppdialect("gnu++0x")
@ -3801,7 +3801,7 @@
}; };
]] ]]
end end
function suite.XCBuildConfigurationProject_OnCppGnu1y() function suite.XCBuildConfigurationProject_OnCppGnu1y()
workspace("MyWorkspace") workspace("MyWorkspace")
cppdialect("gnu++1y") cppdialect("gnu++1y")
@ -3853,7 +3853,7 @@
}; };
]] ]]
end end
function suite.XCBuildConfigurationProject_OnCppGnu1z() function suite.XCBuildConfigurationProject_OnCppGnu1z()
workspace("MyWorkspace") workspace("MyWorkspace")
cppdialect("gnu++1z") cppdialect("gnu++1z")
@ -3905,7 +3905,7 @@
}; };
]] ]]
end end
function suite.XCBuildConfigurationProject_OnCppGnu2a() function suite.XCBuildConfigurationProject_OnCppGnu2a()
workspace("MyWorkspace") workspace("MyWorkspace")
cppdialect("gnu++2a") cppdialect("gnu++2a")

View File

@ -1521,14 +1521,14 @@
end end
settings['USER_HEADER_SEARCH_PATHS'] = cfg.includedirs settings['USER_HEADER_SEARCH_PATHS'] = cfg.includedirs
local sysincludedirs = project.getrelative(cfg.project, cfg.sysincludedirs) local externalincludedirs = project.getrelative(cfg.project, cfg.externalincludedirs)
for i,v in ipairs(sysincludedirs) do for i,v in ipairs(externalincludedirs) do
cfg.sysincludedirs[i] = p.quoted(v) cfg.externalincludedirs[i] = p.quoted(v)
end end
if not table.isempty(cfg.sysincludedirs) then if not table.isempty(cfg.externalincludedirs) then
table.insert(cfg.sysincludedirs, "$(inherited)") table.insert(cfg.externalincludedirs, "$(inherited)")
end end
settings['SYSTEM_HEADER_SEARCH_PATHS'] = cfg.sysincludedirs settings['SYSTEM_HEADER_SEARCH_PATHS'] = cfg.externalincludedirs
for i,v in ipairs(cfg.libdirs) do for i,v in ipairs(cfg.libdirs) do
cfg.libdirs[i] = p.project.getrelative(cfg.project, cfg.libdirs[i]) cfg.libdirs[i] = p.project.getrelative(cfg.project, cfg.libdirs[i])
@ -1536,7 +1536,7 @@
for i,v in ipairs(cfg.syslibdirs) do for i,v in ipairs(cfg.syslibdirs) do
cfg.syslibdirs[i] = p.project.getrelative(cfg.project, cfg.syslibdirs[i]) cfg.syslibdirs[i] = p.project.getrelative(cfg.project, cfg.syslibdirs[i])
end end
settings['LIBRARY_SEARCH_PATHS'] = table.join (cfg.libdirs, cfg.syslibdirs) settings['LIBRARY_SEARCH_PATHS'] = table.join (cfg.libdirs, cfg.syslibdirs)
for i,v in ipairs(cfg.frameworkdirs) do for i,v in ipairs(cfg.frameworkdirs) do
cfg.frameworkdirs[i] = p.project.getrelative(cfg.project, cfg.frameworkdirs[i]) cfg.frameworkdirs[i] = p.project.getrelative(cfg.project, cfg.frameworkdirs[i])

View File

@ -1162,13 +1162,6 @@
tokens = true, tokens = true,
} }
api.register {
name = "sysincludedirs",
scope = "config",
kind = "list:directory",
tokens = true,
}
api.register { api.register {
name = "syslibdirs", name = "syslibdirs",
scope = "config", scope = "config",
@ -1469,6 +1462,38 @@
} }
} }
api.register {
name = "externalincludedirs",
scope = "config",
kind = "list:directory",
tokens = true,
}
api.register {
name = "externalwarnings",
scope = "config",
kind = "string",
allowed = {
"Off",
"Default",
"High",
"Extra",
"Everything",
}
}
api.register { -- DEPRECATED 2021-11-16
name = "sysincludedirs",
scope = "config",
kind = "list:directory",
tokens = true,
}
api.deprecateField("sysincludedirs", 'Use `externalincludedirs` instead.',
function(value)
externalincludedirs(value)
end)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- --
-- Field name aliases for backward compatibility -- Field name aliases for backward compatibility

View File

@ -186,10 +186,10 @@
-- An array of symbols with the appropriate flag decorations. -- An array of symbols with the appropriate flag decorations.
-- --
function clang.getincludedirs(cfg, dirs, sysdirs, frameworkdirs) function clang.getincludedirs(cfg, dirs, extdirs, frameworkdirs)
-- Just pass through to GCC for now -- Just pass through to GCC for now
local flags = gcc.getincludedirs(cfg, dirs, sysdirs, frameworkdirs) local flags = gcc.getincludedirs(cfg, dirs, extdirs, frameworkdirs)
return flags return flags
end end

View File

@ -107,6 +107,12 @@
Extra = {"-Wall", "-Wextra"}, Extra = {"-Wall", "-Wextra"},
Everything = "-Weverything", Everything = "-Weverything",
}, },
externalwarnings = {
Default = "-Wsystem-headers",
High = "-Wsystem-headers",
Extra = "-Wsystem-headers",
Everything = "-Wsystem-headers",
},
symbols = function(cfg, mappings) symbols = function(cfg, mappings)
local values = gcc.getdebugformat(cfg) local values = gcc.getdebugformat(cfg)
local debugformat = values[cfg.debugformat] or "" local debugformat = values[cfg.debugformat] or ""
@ -287,7 +293,7 @@
-- Decorate include file search paths for the GCC command line. -- Decorate include file search paths for the GCC command line.
-- --
function gcc.getincludedirs(cfg, dirs, sysdirs, frameworkdirs) function gcc.getincludedirs(cfg, dirs, extdirs, frameworkdirs)
local result = {} local result = {}
for _, dir in ipairs(dirs) do for _, dir in ipairs(dirs) do
dir = project.getrelative(cfg.project, dir) dir = project.getrelative(cfg.project, dir)
@ -301,10 +307,11 @@
end end
end end
for _, dir in ipairs(sysdirs or {}) do for _, dir in ipairs(extdirs or {}) do
dir = project.getrelative(cfg.project, dir) dir = project.getrelative(cfg.project, dir)
table.insert(result, '-isystem ' .. p.quoted(dir)) table.insert(result, '-isystem ' .. p.quoted(dir))
end end
return result return result
end end

View File

@ -96,6 +96,16 @@
Extra = "/W4", Extra = "/W4",
Everything = "/Wall", Everything = "/Wall",
}, },
externalwarnings = {
Off = "/external:W0",
Default = "/external:W3",
High = "/external:W4",
Extra = "/external:W4",
Everything = "/external:W4",
},
externalanglebrackets = {
On = "/external:anglebrackets",
},
staticruntime = { staticruntime = {
-- this option must always be emit (does it??) -- this option must always be emit (does it??)
_ = function(cfg) return getRuntimeFlag(cfg, false) end, _ = function(cfg) return getRuntimeFlag(cfg, false) end,
@ -237,13 +247,22 @@
-- Decorate include file search paths for the MSVC command line. -- Decorate include file search paths for the MSVC command line.
-- --
function msc.getincludedirs(cfg, dirs, sysdirs, frameworkdirs) function msc.getincludedirs(cfg, dirs, extdirs, frameworkdirs)
local result = {} local result = {}
dirs = table.join(dirs, sysdirs)
for _, dir in ipairs(dirs) do for _, dir in ipairs(dirs) do
dir = project.getrelative(cfg.project, dir) dir = project.getrelative(cfg.project, dir)
table.insert(result, '-I' .. p.quoted(dir)) table.insert(result, '-I' .. p.quoted(dir))
end end
for _, dir in ipairs(extdirs or {}) do
dir = project.getrelative(cfg.project, dir)
if cfg.toolset and cfg.toolset >= "msc-v143" then
table.insert(result, '/external:I' .. p.quoted(dir))
else
table.insert(result, '-I' .. p.quoted(dir))
end
end
return result return result
end end

View File

@ -80,6 +80,12 @@
test.contains({ "-w" }, gcc.getcflags(cfg)) test.contains({ "-w" }, gcc.getcflags(cfg))
end end
function suite.cflags_onDefaultWarnings()
warnings "Default"
prepare()
test.excludes({ "-w", "-Wall", "-Wextra", "-Weverything" }, gcc.getcflags(cfg))
end
function suite.cflags_onHighWarnings() function suite.cflags_onHighWarnings()
warnings "High" warnings "High"
prepare() prepare()
@ -112,6 +118,36 @@
test.contains({ "-Wenable", "-Wno-disable", "-Werror=fatal" }, gcc.getcflags(cfg)) test.contains({ "-Wenable", "-Wno-disable", "-Werror=fatal" }, gcc.getcflags(cfg))
end end
function suite.cflags_onNoExternalWarnings()
externalwarnings "Off"
prepare()
test.excludes({ "-Wsystem-headers" }, gcc.getcflags(cfg))
end
function suite.cflags_onDefaultExternalWarnings()
externalwarnings "Default"
prepare()
test.contains({ "-Wsystem-headers" }, gcc.getcflags(cfg))
end
function suite.cflags_onHighExternalWarnings()
externalwarnings "High"
prepare()
test.contains({ "-Wsystem-headers" }, gcc.getcflags(cfg))
end
function suite.cflags_onExtraExternalWarnings()
externalwarnings "Extra"
prepare()
test.contains({ "-Wsystem-headers" }, gcc.getcflags(cfg))
end
function suite.cflags_onEverythingExternalWarnings()
externalwarnings "Everything"
prepare()
test.contains({ "-Wsystem-headers" }, gcc.getcflags(cfg))
end
function suite.cflags_onFloastFast() function suite.cflags_onFloastFast()
floatingpoint "Fast" floatingpoint "Fast"
prepare() prepare()
@ -393,7 +429,7 @@
prepare() prepare()
test.contains({ "-dynamiclib" }, gcc.getldflags(cfg)) test.contains({ "-dynamiclib" }, gcc.getldflags(cfg))
end end
-- --
-- Check Mac OS X deployment target flags -- Check Mac OS X deployment target flags
-- --
@ -404,14 +440,14 @@
prepare() prepare()
test.contains({ "-mmacosx-version-min=10.9" }, gcc.getcflags(cfg)) test.contains({ "-mmacosx-version-min=10.9" }, gcc.getcflags(cfg))
end end
function suite.cxxflags_macosx_systemversion() function suite.cxxflags_macosx_systemversion()
system "MacOSX" system "MacOSX"
systemversion "10.9:10.15" systemversion "10.9:10.15"
prepare() prepare()
test.contains({ "-mmacosx-version-min=10.9" }, gcc.getcxxflags(cfg)) test.contains({ "-mmacosx-version-min=10.9" }, gcc.getcxxflags(cfg))
end end
function suite.cxxflags_macosx_systemversion_unspecified() function suite.cxxflags_macosx_systemversion_unspecified()
system "MacOSX" system "MacOSX"
prepare() prepare()
@ -600,8 +636,9 @@
function suite.includeDirsAreRelative() function suite.includeDirsAreRelative()
includedirs { "../include", "src/include" } includedirs { "../include", "src/include" }
externalincludedirs { "test/include" }
prepare() prepare()
test.isequal({ '-I../include', '-Isrc/include' }, gcc.getincludedirs(cfg, cfg.includedirs)) test.isequal({ '-I../include', '-Isrc/include', '-isystem test/include' }, gcc.getincludedirs(cfg, cfg.includedirs, cfg.externalincludedirs))
end end
@ -623,14 +660,16 @@
function suite.includeDirs_onSpaces() function suite.includeDirs_onSpaces()
includedirs { "include files" } includedirs { "include files" }
externalincludedirs { "test include" }
prepare() prepare()
test.isequal({ '-I"include files"' }, gcc.getincludedirs(cfg, cfg.includedirs)) test.isequal({ '-I"include files"', '-isystem "test include"' }, gcc.getincludedirs(cfg, cfg.includedirs, cfg.externalincludedirs))
end end
function suite.includeDirs_onEnvVars() function suite.includeDirs_onEnvVars()
includedirs { "$(IntDir)/includes" } includedirs { "$(IntDir)/includes" }
externalincludedirs { "$(BinDir)/include" }
prepare() prepare()
test.isequal({ '-I"$(IntDir)/includes"' }, gcc.getincludedirs(cfg, cfg.includedirs)) test.isequal({ '-I"$(IntDir)/includes"', '-isystem "$(BinDir)/include"' }, gcc.getincludedirs(cfg, cfg.includedirs, cfg.externalincludedirs))
end end
@ -668,12 +707,6 @@
-- Check handling of system search paths. -- Check handling of system search paths.
-- --
function suite.includeDirs_onSysIncludeDirs()
sysincludedirs { "/usr/local/include" }
prepare()
test.contains("-isystem /usr/local/include", gcc.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs))
end
function suite.libDirs_onSysLibDirs() function suite.libDirs_onSysLibDirs()
syslibdirs { "/usr/local/lib" } syslibdirs { "/usr/local/lib" }
prepare() prepare()
@ -700,9 +733,9 @@
function suite.includeDirs_macosx_onFrameworkDirs() function suite.includeDirs_macosx_onFrameworkDirs()
system "MacOSX" system "MacOSX"
location "subdir" location "subdir"
frameworkdirs { frameworkdirs {
"/Library/Frameworks", "/Library/Frameworks",
"subdir/Relative/Frameworks" "subdir/Relative/Frameworks"
} }
prepare() prepare()
test.contains("-F/Library/Frameworks", gcc.getincludedirs(cfg, {}, {}, cfg.frameworkdirs)) test.contains("-F/Library/Frameworks", gcc.getincludedirs(cfg, {}, {}, cfg.frameworkdirs))
@ -712,7 +745,7 @@
function suite.libDirs_macosx_onFrameworkDirs() function suite.libDirs_macosx_onFrameworkDirs()
system "MacOSX" system "MacOSX"
location "subdir" location "subdir"
frameworkdirs { frameworkdirs {
"/Library/Frameworks", "/Library/Frameworks",
"subdir/Relative/Frameworks" "subdir/Relative/Frameworks"
} }

View File

@ -257,6 +257,58 @@
end end
--
-- Check handling externalwarnings.
--
function suite.cflags_onNoExternalWarnings()
externalwarnings "Off"
prepare()
test.contains("/external:W0", msc.getcflags(cfg))
end
function suite.cflags_onHighExternalWarnings()
externalwarnings "High"
prepare()
test.contains("/external:W4", msc.getcflags(cfg))
end
function suite.cflags_onExtraExternalWarnings()
externalwarnings "Extra"
prepare()
test.contains("/external:W4", msc.getcflags(cfg))
end
--
-- Check handling externalanglebrackets.
--
function suite.cflags_onExternalAngleBrackets()
externalanglebrackets "On"
prepare()
test.contains("/external:anglebrackets", msc.getcflags(cfg))
end
--
-- Check handling externalincludedirs.
--
function suite.cflags_onExternalIncludeDirs()
externalincludedirs { "/usr/local/include" }
prepare()
test.contains("-I/usr/local/include", msc.getincludedirs(cfg, cfg.includedirs, cfg.externalincludedirs))
end
function suite.cflags_onVs2022ExternalIncludeDirs()
p.action.set("vs2022")
externalincludedirs { "/usr/local/include" }
prepare()
test.contains("/external:I/usr/local/include", msc.getincludedirs(cfg, cfg.includedirs, cfg.externalincludedirs))
end
-- --
-- Check handling of library search paths. -- Check handling of library search paths.
-- --
@ -481,12 +533,6 @@
-- Check handling of system search paths. -- Check handling of system search paths.
-- --
function suite.includeDirs_onSysIncludeDirs()
sysincludedirs { "/usr/local/include" }
prepare()
test.contains("-I/usr/local/include", msc.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs))
end
function suite.libDirs_onSysLibDirs() function suite.libDirs_onSysLibDirs()
syslibdirs { "/usr/local/lib" } syslibdirs { "/usr/local/lib" }
prepare() prepare()

View File

@ -76,7 +76,10 @@
| [entrypoint](entrypoint.md) | Specify the program entry point function | | [entrypoint](entrypoint.md) | Specify the program entry point function |
| [exceptionhandling](exceptionhandling.md) | Enable or disable exception handling | | [exceptionhandling](exceptionhandling.md) | Enable or disable exception handling |
| [external](external.md) | | | [external](external.md) | |
| [externalanglebrackets](externalanglebrackets.md) | |
| [externalincludedirs](externalincludedirs.md) | |
| [externalrule](externalrule.md) | | | [externalrule](externalrule.md) | |
| [externalwarnings](externalwarnings.md) | |
| [fatalwarnings](fatalwarnings.md) | | | [fatalwarnings](fatalwarnings.md) | |
| [fileextension](fileextension.md) | | | [fileextension](fileextension.md) | |
| [filename](filename.md) | | | [filename](filename.md) | |

View File

@ -70,6 +70,9 @@ title: What's New in 5.0
* [entrypoint](entrypoint.md) (new) * [entrypoint](entrypoint.md) (new)
* [exceptionhandling](exceptionhandling.md) (new) * [exceptionhandling](exceptionhandling.md) (new)
* [external](external.md) (new) * [external](external.md) (new)
* [externalanglebrackets](externalanglebrackets.md) (new)
* [externalincludedirs](externalincludedirs.md) (new)
* [externalwarnings](externalwarnings.md) (new)
* [externalproject](externalproject.md) (new) * [externalproject](externalproject.md) (new)
* [externalrule](externalrule.md) (new) * [externalrule](externalrule.md) (new)
* [fatalwarnings](fatalwarnings.md) (new) * [fatalwarnings](fatalwarnings.md) (new)

View File

@ -0,0 +1,28 @@
Treats all headers included by `#include <header>`, where the header file is enclosed in angle brackets (`< >`), as external headers.
```lua
externalanglebrackets "value"
```
### Parameters ###
`value` is one of:
| Value | Description |
|---------|---------------------------------------------------|
| On | Treat headers included with angle brackets as external. |
| Off | Default. Headers are treated normally. |
### Applies To ###
Project configurations.
### Availability ###
Premake 5.0 or later.
Visual Studio 2022 version 17.0 or later.
### See Also ###
* [externalincludedirs](externalincludedirs.md)
* [externalwarnings](externalwarnings.md)

View File

@ -0,0 +1,41 @@
Specifies the include file search paths for the compiler, treating headers included from these paths as external.
```lua
externalincludedirs { "paths" }
```
For Visual Studio, these paths are placed in the "VC++ Directories" properties panel. For GCC and Clang, they are preceded with the `-isystem` flag, rather than `-I`. For toolsets which do not support the concept of external include directories, they are treated as a normal include directory.
Include files located via an external include directory are treated specially, see [externalwarnings](externalwarnings.md).
### Parameters ###
`paths` specifies a list of include file search directories. Paths should be specified relative to the currently running script file.
### Applies To ###
Project configurations.
### Availability ###
Premake 5.0 or later.
### Examples ###
Define two external include file search paths.
```lua
externalincludedirs { "../lua/include", "../zlib" }
```
You can also use wildcards to match multiple directories. The * will match against a single directory, ** will recurse into subdirectories as well.
```lua
externalincludedirs { "../includes/**" }
```
### See Also ###
* [externalanglebrackets](externalanglebrackets.md)
* [externalwarnings](externalwarnings.md)
* [includedirs](includedirs.md)

View File

@ -0,0 +1,40 @@
Controls the level of warnings that are shown by the compiler for headers that are considered external.
```lua
externalwarnings "value"
```
If no value is set for a configuration, the toolset's default warning level will be used.
### Parameters ###
`value` specifies the desired level of warning:
| Value | Description |
|-------------|--------------------------------------------------------|
| Off | Do not show any warning messages. |
| Default | Use the toolset's default warning level. |
| Extra | Enable the toolset's maximum warning level. |
| High | Enable the toolset's maximum warning level. |
| Everything | Enable the toolset's maximum warning level. |
### Applies To ###
Project configurations.
### Availability ###
Premake 5.0 or later.
Visual Studio 2022 version 17.0 or later.
### Examples ###
```lua
externalwarnings "Off"
```
### See Also ###
* [externalanglebrackets](externalanglebrackets.md)
* [externalincludedirs](externalincludedirs.md)
* [warnings](warnings.md)

View File

@ -1,12 +1,10 @@
Specifies the system include file search paths. Alias of [externalincludedirs](externalincludedirs.md).
```lua ```lua
sysincludedirs { "paths" } sysincludedirs { "paths" }
``` ```
For Visual Studio, these paths are placed in the "VC++ Directories" properties panel. For GCC and Clang, they are preceded with the `-isystem` flag, rather than `-I`. For toolsets which do not support the concept of system include directories, they are treated as a normal include directory. **This function has been deprecated in Premake 5.0 beta2.** Use the new [externalincludedirs](externalincludedirs.md) function instead. `sysincludedirs` will be not supported in Premake 6.
Include files located via a system include directory are treated as correct: no warnings will be shown for the contents of the file.
### Parameters ### ### Parameters ###
@ -36,5 +34,4 @@ sysincludedirs { "../includes/**" }
### See Also ### ### See Also ###
* [includedirs](includedirs.md) * [externalincludedirs](externalincludedirs.md)
* [syslibdirs](syslibdirs.md)

View File

@ -34,5 +34,6 @@ syslibdirs { "../libs/**" }
### See Also ### ### See Also ###
* [externalincludedirs](externalincludedirs.md)
* [libdirs](libdirs.md) * [libdirs](libdirs.md)
* [sysincludedirs](sysincludedirs.md) * [sysincludedirs](sysincludedirs.md)

View File

@ -1,4 +1,4 @@
Controls the number of warnings that are shown by the compiler. Controls the level of warnings that are shown by the compiler.
```lua ```lua
warnings "value" warnings "value"

View File

@ -142,8 +142,11 @@ module.exports = {
'entrypoint', 'entrypoint',
'exceptionhandling', 'exceptionhandling',
'external', 'external',
'externalanglebrackets',
'externalincludedirs',
'externalproject', 'externalproject',
'externalrule', 'externalrule',
'externalwarnings',
'fastuptodate', 'fastuptodate',
'fatalwarnings', 'fatalwarnings',
'fileextension', 'fileextension',