Skip to content

Commit

Permalink
msc Fix several flags.
Browse files Browse the repository at this point in the history
- Link-time optimizations now sets cl and ld flags.
- Run-Time selection now adheres to `runtime` setting.
- Set Subsystem for WindowedApp
  • Loading branch information
JoelLinn committed Nov 8, 2020
1 parent 82e5036 commit 0ca1576
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 6 deletions.
21 changes: 16 additions & 5 deletions src/tools/msc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
-- Returns list of C compiler flags for a configuration.
--

local function getRuntimeFlag(cfg, isstatic)
local rt = cfg.runtime
local flag = iif(isstatic, "/MT", "/MD")
if (rt == "Debug") or (rt == nil and config.isDebugBuild(cfg)) then
flag = flag .. "d"
end
return flag
end

msc.shared = {
clr = {
On = "/clr",
Expand All @@ -37,6 +46,7 @@
},
flags = {
FatalCompileWarnings = "/WX",
LinkTimeOptimization = "/GL",
MultiProcessorCompile = "/MP",
NoMinimalRebuild = "/Gm-",
OmitDefaultLibrary = "/Zl"
Expand Down Expand Up @@ -87,11 +97,11 @@
},
staticruntime = {
-- this option must always be emit (does it??)
_ = function(cfg) return iif(config.isDebugBuild(cfg), "/MDd", "/MD") end,
_ = function(cfg) return getRuntimeFlag(cfg, false) 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,
Default = function(cfg) return getRuntimeFlag(cfg, false) end,
On = function(cfg) return getRuntimeFlag(cfg, true) end,
Off = function(cfg) return getRuntimeFlag(cfg, false) end,
},
stringpooling = {
On = "/GF",
Expand Down Expand Up @@ -239,13 +249,14 @@
msc.linkerFlags = {
flags = {
FatalLinkWarnings = "/WX",
LinkTimeOptimization = "/GL",
LinkTimeOptimization = "/LTCG",
NoIncrementalLink = "/INCREMENTAL:NO",
NoManifest = "/MANIFEST:NO",
OmitDefaultLibrary = "/NODEFAULTLIB",
},
kind = {
SharedLib = "/DLL",
WindowedApp = "/SUBSYSTEM:WINDOWS"
},
symbols = {
On = "/DEBUG"
Expand Down
61 changes: 60 additions & 1 deletion tests/tools/test_msc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@
test.excludes("/Oy", msc.getcflags(cfg))
end

function suite.cflags_onLinkTimeOptimizations()
flags "LinkTimeOptimization"
prepare()
test.contains("/GL", msc.getcflags(cfg))
end

function suite.ldflags_onLinkTimeOptimizations()
flags "LinkTimeOptimization"
prepare()
test.contains("/GL", msc.getldflags(cfg))
test.contains("/LTCG", msc.getldflags(cfg))
end

function suite.cflags_onStringPoolingOn()
Expand Down Expand Up @@ -512,3 +518,56 @@
prepare()
test.isequal({ "/WX", "/MD", "/EHsc" }, msc.getcxxflags(cfg))
end


--
-- Check handling of Run-Time Library flags.
--

function suite.cflags_onStaticRuntime()
staticruntime "On"
prepare()
test.isequal({ "/MT" }, msc.getcflags(cfg))
end

function suite.cflags_onDynamicRuntime()
staticruntime "Off"
prepare()
test.isequal({ "/MD" }, msc.getcflags(cfg))
end

function suite.cflags_onStaticRuntimeAndDebug()
staticruntime "On"
runtime "Debug"
prepare()
test.isequal({ "/MTd" }, msc.getcflags(cfg))
end

function suite.cflags_onDynamicRuntimeAndDebug()
staticruntime "Off"
runtime "Debug"
prepare()
test.isequal({ "/MDd" }, msc.getcflags(cfg))
end

function suite.cflags_onStaticRuntimeAndSymbols()
staticruntime "On"
symbols "On"
prepare()
test.isequal({ "/MTd", "/Z7" }, msc.getcflags(cfg))
end

function suite.cflags_onDynamicRuntimeAndSymbols()
staticruntime "Off"
symbols "On"
prepare()
test.isequal({ "/MDd", "/Z7" }, msc.getcflags(cfg))
end

function suite.cflags_onDynamicRuntimeAndReleaseAndSymbols()
staticruntime "Off"
runtime "Release"
symbols "On"
prepare()
test.isequal({ "/MD", "/Z7" }, msc.getcflags(cfg))
end

0 comments on commit 0ca1576

Please sign in to comment.