Add optimize(); deprecate Optimize, OptimizeSize, and OptimizeSpeed flags

This commit is contained in:
Jason Perkins 2013-09-29 11:23:39 -04:00
parent bc9ba89cce
commit 686f3f071a
14 changed files with 75 additions and 92 deletions

View File

@ -454,6 +454,18 @@
tokens = true,
}
api.register {
name = "optimize",
scope = "config",
kind = "string",
allowed = {
"Off",
"On",
"Size",
"Speed",
}
}
api.register {
name = "pchheader",
scope = "config",
@ -678,6 +690,11 @@
return DOC_URL .. "nativewchar"
end)
api.deprecateValue("flags", { "Optimize", "OptimizeSize", "OptimizeSpeed" }, function(value)
local map = { Optimize = "On", OptimizeSize = "Size", OptimizeSpeed = "Speed" }
optimize (map[value] or "Off")
return DOC_URL .. "optimize"
end)
-----------------------------------------------------------------------------

View File

@ -1275,21 +1275,8 @@
--
function vc200x.optimization(cfg)
local result = 0
-- step through the flags in the order they were specified, so
-- later flags can override an earlier value
for _, value in ipairs(cfg.flags) do
if (value == "Optimize") then
result = 3
elseif (value == "OptimizeSize") then
result = 1
elseif (value == "OptimizeSpeed") then
result = 2
end
end
return result
local map = { On = 3, Size = 1, Speed = 2 }
return map[cfg.optimize] or 0
end

View File

@ -972,17 +972,8 @@
function vc2010.optimization(cfg)
local result = "Disabled"
for _, flag in ipairs(cfg.flags) do
if flag == "Optimize" then
result = "Full"
elseif flag == "OptimizeSize" then
result = "MinSpace"
elseif flag == "OptimizeSpeed" then
result = "MaxSpeed"
end
end
_p(3,'<Optimization>%s</Optimization>', result)
local map = { On = "Full", Size = "MinSpace", Speed = "MaxSpeed" }
_p(3,'<Optimization>%s</Optimization>', map[cfg.optimize] or "Disabled")
end

View File

@ -466,15 +466,7 @@
--
function config.isDebugBuild(cfg)
-- If any of the optimize flags are set, it's a release build
if cfg.flags.Optimize or cfg.flags.OptimizeSize or cfg.flags.OptimizeSpeed then
return false
end
-- If symbols are not defined, it's a release build
if not cfg.flags.Symbols then
return false
end
return true
return cfg.flags.Symbols and not config.isOptimizedBuild(cfg)
end
@ -485,7 +477,7 @@
--
function config.isOptimizedBuild(cfg)
return cfg.flags.Optimize or cfg.flags.OptimizeSize or cfg.flags.OptimizeSpeed
return cfg.optimize ~= nil and cfg.optimize ~= "Off"
end

View File

@ -39,6 +39,7 @@
premake.MACOSX = "macosx"
premake.MAKEFILE = "Makefile"
premake.NONE = "None"
premake.OFF = "Off"
premake.POSIX = "posix"
premake.PS3 = "ps3"
premake.SHAREDLIB = "SharedLib"

View File

@ -8,25 +8,11 @@
premake.tools.dotnet = {}
local dotnet = premake.tools.dotnet
local project = premake.project
local config = premake.config
dotnet.namestyle = "windows"
--
-- Translation of Premake flags into CSC flags
--
local flags =
{
FatalWarning = "/warnaserror",
Optimize = "/optimize",
OptimizeSize = "/optimize",
OptimizeSpeed = "/optimize",
Symbols = "/debug",
Unsafe = "/unsafe"
}
--
-- Examine the file and project configurations to glean additional
-- information about a source code in a C# project.
@ -175,8 +161,21 @@
-- Returns a list of compiler flags, based on the supplied configuration.
--
dotnet.flags = {
flags = {
FatalWarning = "/warnaserror",
Symbols = "/debug",
Unsafe = "/unsafe"
},
optimize = {
On = "/optimize",
Size = "/optimize",
Speed = "/optimize",
},
}
function dotnet.getflags(cfg)
local flags = {}
local flags = config.mapFlags(cfg, dotnet.flags)
if cfg.project.icon then
local fn = project.getrelative(cfg.project, cfg.project.icon)
@ -187,8 +186,7 @@
table.insert(flags, table.implode(cfg.defines, "/d:", "", " "))
end
flags = table.join(flags, table.translate(cfg.flags, flags), cfg.buildoptions)
return flags
return table.join(flags, cfg.buildoptions)
end

View File

@ -100,15 +100,17 @@
FatalWarnings = "-Werror",
NoWarnings = "-w",
NoFramePointer = "-fomit-frame-pointer",
Optimize = "-O2",
OptimizeSize = "-Os",
OptimizeSpeed = "-O3",
Symbols = "-g"
},
floatingpoint = {
Fast = "-ffast-math",
Strict = "-ffloat-store",
},
optimize = {
On = "-O2",
Size = "-Os",
Speed = "-O3",
},
vectorextensions = {
SSE = "-msse",
SSE2 = "-msse2",

View File

@ -16,8 +16,7 @@
--
function msc.getcppflags(cfg)
local flags = {}
return flags
return {}
end
@ -26,12 +25,18 @@
--
msc.cflags = {
SEH = "/EHa",
OptimizeSpeed = "/O2",
flags = {
SEH = "/EHa /EHsc",
Symbols = "/Z7",
},
optimize = {
Off = "/Od",
Speed = "/O2",
}
}
function msc.getcflags(cfg)
local flags = table.translate(cfg.flags, msc.cflags)
local flags = config.mapFlags(cfg, msc.cflags)
local runtime = iif(cfg.flags.StaticRuntime, "/MT", "/MD")
if config.isDebugBuild(cfg) then
@ -39,18 +44,6 @@
end
table.insert(flags, runtime)
if not config.isOptimizedBuild(cfg) then
table.insert(flags, "/Od")
end
if cfg.flags.Symbols then
table.insert(flags, "/Z7")
end
if not cfg.flags.SEH then
table.insert(flags, "/EHsc")
end
return flags
end

View File

@ -55,7 +55,7 @@
--
function suite.optimize_onOptimizeFlag()
flags { "Optimize" }
optimize "On"
prepare()
test.capture [[
<DebugType>pdbonly</DebugType>
@ -64,7 +64,7 @@
end
function suite.optimize_onOptimizeSizeFlag()
flags { "OptimizeSize" }
optimize "Size"
prepare()
test.capture [[
<DebugType>pdbonly</DebugType>
@ -73,7 +73,7 @@
end
function suite.optimize_onOptimizeSpeedFlag()
flags { "OptimizeSpeed" }
optimize "Speed"
prepare()
test.capture [[
<DebugType>pdbonly</DebugType>

View File

@ -95,7 +95,8 @@
--
function suite.looksGood_onSymbolsAndOptimizeFlags()
flags { "Symbols", "Optimize" }
flags { "Symbols" }
optimize "On"
prepare()
test.capture [[
<Tool

View File

@ -122,7 +122,7 @@
--
function suite.optimization_onOptimize()
flags "Optimize"
optimize "On"
prepare()
test.capture [[
<ClCompile>
@ -137,7 +137,7 @@
end
function suite.optimization_onOptimizeSize()
flags "OptimizeSize"
optimize "Size"
prepare()
test.capture [[
<ClCompile>
@ -152,7 +152,7 @@
end
function suite.optimization_onOptimizeSpeed()
flags "OptimizeSpeed"
optimize "Speed"
prepare()
test.capture [[
<ClCompile>
@ -534,7 +534,8 @@
--
function suite.debugFormat_onOptimizedBuild()
flags { "Symbols", "Optimize" }
flags { "Symbols" }
optimize "On"
prepare()
test.capture [[
<ClCompile>

View File

@ -49,7 +49,7 @@
--
function suite.defaultSettings_onOptimize()
flags "Optimize"
optimize "On"
prepare()
test.capture [[
<Link>
@ -298,7 +298,7 @@
--
function suite.optimizeReferences_onOptimizeFlag()
flags { "Optimize" }
optimize "On"
prepare()
test.capture [[
<Link>

View File

@ -118,7 +118,7 @@
--
function suite.noIncrementalLink_onOptimizedBuild()
flags "Optimize"
optimize "On"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">

View File

@ -15,7 +15,7 @@
--
local cset, parentset
function suite.setup()
parentset = configset.new()
cset = configset.new(parentset)
@ -57,7 +57,7 @@
--
-- Make sure that I can roundtrip a value stored into a block
-- Make sure that I can roundtrip a value stored into a block
-- with a simple matching term.
--
@ -80,7 +80,7 @@
--
function suite.skipsBlock_onTermMismatch()
configset.addvalue(cset, "targetextension", ".so")
configset.addvalue(cset, "targetextension", ".so")
configset.addblock(cset, { "Windows" })
configset.addvalue(cset, "targetextension", ".dll")
test.isequal(".so", configset.fetchvalue(cset, "targetextension", { "linux" }))
@ -168,15 +168,15 @@
--
function suite.remove_onExactValueMatch()
configset.addvalue(cset, "flags", { "Symbols", "Optimize", "NoRTTI" })
configset.removevalues(cset, "flags", { "Optimize" })
configset.addvalue(cset, "flags", { "Symbols", "Unsafe", "NoRTTI" })
configset.removevalues(cset, "flags", { "Unsafe" })
test.isequal({ "Symbols", "NoRTTI" }, configset.fetchvalue(cset, "flags", {}))
end
function suite.remove_onMultipleValues()
configset.addvalue(cset, "flags", { "Symbols", "NoExceptions", "Optimize", "NoRTTI" })
configset.addvalue(cset, "flags", { "Symbols", "NoExceptions", "Unsafe", "NoRTTI" })
configset.removevalues(cset, "flags", { "NoExceptions", "NoRTTI" })
test.isequal({ "Symbols", "Optimize" }, configset.fetchvalue(cset, "flags", {}))
test.isequal({ "Symbols", "Unsafe" }, configset.fetchvalue(cset, "flags", {}))
end