Skip to content

Commit

Permalink
Merge pull request #938 from premake/staticruntime
Browse files Browse the repository at this point in the history
Added `staticruntime` API. (#163)
  • Loading branch information
tvandijck authored Nov 29, 2017
2 parents a3c80ae + 2de9966 commit 0a61717
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 27 deletions.
7 changes: 4 additions & 3 deletions modules/vstudio/tests/vc200x/test_compiler_block.lua
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,13 @@


--
-- Check handling of the ReleaseRuntime flag; should override the
-- Check handling of the runtime API; should override the
-- default behavior of linking the debug runtime when symbols are
-- enabled with no optimizations.
--

function suite.releaseRuntime_onFlag()
flags { "ReleaseRuntime" }
runtime "Release"
symbols "On"
prepare()
test.capture [[
Expand All @@ -558,7 +558,8 @@
end

function suite.releaseRuntime_onStaticAndReleaseRuntime()
flags { "ReleaseRuntime", "StaticRuntime" }
runtime "Release"
staticruntime "On"
symbols "On"
prepare()
test.capture [[
Expand Down
66 changes: 61 additions & 5 deletions modules/vstudio/tests/vc2010/test_compile_settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,23 @@


--
-- If the StaticRuntime flag is specified, add the <RuntimeLibrary> element.
-- If staticruntime is specified, add the <RuntimeLibrary> element.
--

function suite.runtimeLibrary_onDynamicRuntime()
staticruntime "Off"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
]]
end

function suite.runtimeLibrary_onStaticRuntime()
flags { "StaticRuntime" }
staticruntime "On"
prepare()
test.capture [[
<ClCompile>
Expand All @@ -417,8 +429,22 @@
]]
end

function suite.runtimeLibrary_onDynamicRuntimeAndSymbols()
staticruntime "Off"
symbols "On"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
]]
end

function suite.runtimeLibrary_onStaticRuntimeAndSymbols()
flags { "StaticRuntime" }
staticruntime "On"
symbols "On"
prepare()
test.capture [[
Expand Down Expand Up @@ -770,13 +796,43 @@


--
-- Check handling of the ReleaseRuntime flag; should override the
-- Check handling of the `runtime` API; should override the
-- default behavior of linking the debug runtime when symbols are
-- enabled with no optimizations.
--

function suite.releaseRuntime_onReleaseRuntime()
runtime "Release"
symbols "On"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
]]
end

function suite.releaseRuntime_onDynamicAndReleaseRuntime()
runtime "Release"
staticruntime "Off"
symbols "On"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
]]
end

function suite.releaseRuntime_onStaticAndReleaseRuntime()
flags { "ReleaseRuntime", "StaticRuntime" }
runtime "Release"
staticruntime "On"
symbols "On"
prepare()
test.capture [[
Expand Down
5 changes: 3 additions & 2 deletions modules/vstudio/tests/vc2010/test_config_props.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@
end

function suite.useOfMfc_onStaticRuntime()
flags { "MFC", "StaticRuntime" }
flags { "MFC" }
staticruntime "On"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down Expand Up @@ -217,7 +218,7 @@
--

function suite.releaseRuntime_onFlag()
flags { "ReleaseRuntime" }
runtime "Release"
symbols "On"
prepare()
test.capture [[
Expand Down
11 changes: 9 additions & 2 deletions modules/vstudio/vs200x_vcproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,14 @@
SharedRelease = 2,
SharedDebug = 3,
}
p.w('RuntimeLibrary="%s"', runtimes[config.getruntime(cfg)])
local runtime = config.getruntime(cfg)
if runtime then
p.w('RuntimeLibrary="%s"', runtimes[runtime])
else
-- TODO: this path should probably be omitted and left for default
-- ...but I can't really test this, so I'm a leave it how I found it
p.w('RuntimeLibrary="%s"', iif(config.isDebugBuild(cfg), 3, 2))
end
end
end

Expand Down Expand Up @@ -1596,7 +1603,7 @@

function m.useOfMFC(cfg)
if (cfg.flags.MFC) then
p.w('UseOfMFC="%d"', iif(cfg.flags.StaticRuntime, 1, 2))
p.w('UseOfMFC="%d"', iif(cfg.staticruntime == "On", 1, 2))
end
end

Expand Down
14 changes: 7 additions & 7 deletions modules/vstudio/vs2010_vcxproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@

function m.basicRuntimeChecks(cfg, condition)
local prjcfg, filecfg = p.config.normalize(cfg)
local runtime = config.getruntime(prjcfg)
local runtime = config.getruntime(prjcfg) or iif(config.isDebugBuild(cfg), "Debug", "Release")
if filecfg then
if filecfg.flags.NoRuntimeChecks or (config.isOptimizedBuild(filecfg) and runtime:endswith("Debug")) then
m.element("BasicRuntimeChecks", condition, "Default")
Expand Down Expand Up @@ -2271,12 +2271,12 @@
local runtimes = {
StaticDebug = "MultiThreadedDebug",
StaticRelease = "MultiThreaded",
StaticDLLDebug = "MultiThreadedDebugDLL",
StaticDLLRelease = "MultiThreadedDLL"
SharedDebug = "MultiThreadedDebugDLL",
SharedRelease = "MultiThreadedDLL"
}
local runtime = runtimes[config.getruntime(cfg)]
local runtime = config.getruntime(cfg)
if runtime then
m.element("RuntimeLibrary", nil, runtime)
m.element("RuntimeLibrary", nil, runtimes[runtime])
end
end

Expand Down Expand Up @@ -2420,14 +2420,14 @@


function m.useDebugLibraries(cfg)
local runtime = config.getruntime(cfg)
local runtime = config.getruntime(cfg) or iif(config.isDebugBuild(cfg), "Debug", "Release")
m.element("UseDebugLibraries", nil, tostring(runtime:endswith("Debug")))
end


function m.useOfMfc(cfg)
if cfg.flags.MFC then
m.element("UseOfMfc", nil, iif(cfg.flags.StaticRuntime, "Static", "Dynamic"))
m.element("UseOfMfc", nil, iif(cfg.staticruntime == "On", "Static", "Dynamic"))
end
end

Expand Down
23 changes: 22 additions & 1 deletion src/_premake_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@
"RelativeLinks",
"ReleaseRuntime", -- DEPRECATED
"ShadowedVariables",
"StaticRuntime",
"StaticRuntime", -- DEPRECATED
"Symbols", -- DEPRECATED
"UndefinedIdentifiers",
"WinMain", -- DEPRECATED
Expand Down Expand Up @@ -1060,6 +1060,17 @@
tokens = true,
}

api.register {
name = "staticruntime",
scope = "config",
kind = "string",
allowed = {
"Default",
"On",
"Off"
}
}

api.register {
name = "strictaliasing",
scope = "config",
Expand Down Expand Up @@ -1531,6 +1542,16 @@
entrypoint "mainCRTStartup"
end)

-- 31 October 2017

api.deprecateValue("flags", "StaticRuntime", 'Use `staticruntime "On"` instead',
function(value)
staticruntime "On"
end,
function(value)
staticruntime "Default"
end)

-----------------------------------------------------------------------------
--
-- Install Premake's default set of command line arguments.
Expand Down
9 changes: 5 additions & 4 deletions src/base/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,12 @@
--

function config.getruntime(cfg)
local linkage = iif(cfg.flags.StaticRuntime, "Static", "Shared")

if cfg.clr == "On" and cfg.flags.StaticRuntime then
linkage = linkage .. "DLL"
if (not cfg.staticruntime or cfg.staticruntime == "Default") and not cfg.runtime then
return nil -- indicate that no runtime was explicitly selected
end

local linkage = iif(cfg.staticruntime == "On", "Static", "Shared") -- assume 'Shared' is default?

if not cfg.runtime then
return linkage .. iif(config.isDebugBuild(cfg), "Debug", "Release")
else
Expand Down
12 changes: 9 additions & 3 deletions src/tools/msc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
MultiProcessorCompile = "/MP",
NoFramePointer = "/Oy",
NoMinimalRebuild = "/Gm-",
OmitDefaultLibrary = "/Zl",
StaticRuntime = function(cfg) return iif(config.isDebugBuild(cfg), "/MTd", "/MT") end,
_StaticRuntime = function(cfg) return iif(config.isDebugBuild(cfg), "/MDd", "/MD") end
OmitDefaultLibrary = "/Zl"
},
floatingpoint = {
Fast = "/fp:fast",
Expand Down Expand Up @@ -87,6 +85,14 @@
High = "/W4",
Off = "/W0",
},
staticruntime = {
-- this option must always be emit (does it??)
_ = function(cfg) return iif(config.isDebugBuild(cfg), "/MDd", "/MD") end,
-- runtime defaults to dynamic in VS
Default = function(cfg) return iif(config.isDebugBuild(cfg), "/MDd", "/MD") end,
On = function(cfg) return iif(config.isDebugBuild(cfg), "/MTd", "/MT") end,
Off = function(cfg) return iif(config.isDebugBuild(cfg), "/MDd", "/MD") end,
},
stringpooling = {
On = "/GF",
Off = "/GF-",
Expand Down

0 comments on commit 0a61717

Please sign in to comment.