Skip to content

Commit b4893c9

Browse files
Replace MFC flag with a dedicated API (premake#2334)
1 parent 03b384d commit b4893c9

File tree

8 files changed

+112
-9
lines changed

8 files changed

+112
-9
lines changed

modules/vstudio/_preload.lua

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--
22
-- _preload.lua
3-
-- Define the makefile action(s).
3+
-- Define the Visual Studio action(s).
44
-- Copyright (c) Jess Perkins and the Premake project
55
--
66

@@ -608,6 +608,27 @@
608608
tokens = "true",
609609
}
610610

611+
p.api.register {
612+
name = "mfc",
613+
scope = "config",
614+
kind = "string",
615+
allowed = {
616+
"Default",
617+
"Off",
618+
"On",
619+
"Static",
620+
"Dynamic",
621+
}
622+
}
623+
624+
p.api.deprecateValue("flags", "MFC", 'Use `mfc` instead.',
625+
function(value)
626+
mfc("On")
627+
end,
628+
function(value)
629+
mfc("Off")
630+
end)
631+
611632
--
612633
-- Decide when the full module should be loaded.
613634
--

modules/vstudio/tests/vc2010/test_config_props.lua

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,18 @@
174174
--
175175

176176
function suite.useOfMfc_onDynamicRuntime()
177-
flags "MFC"
177+
mfc "On"
178+
prepare()
179+
test.capture [[
180+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
181+
<ConfigurationType>Application</ConfigurationType>
182+
<UseDebugLibraries>false</UseDebugLibraries>
183+
<UseOfMfc>Dynamic</UseOfMfc>
184+
]]
185+
end
186+
187+
function suite.useOfMfc_onDynamicRuntimeViaFlag()
188+
flags { "MFC" }
178189
prepare()
179190
test.capture [[
180191
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@@ -185,6 +196,18 @@
185196
end
186197

187198
function suite.useOfMfc_onStaticRuntime()
199+
mfc "On"
200+
staticruntime "On"
201+
prepare()
202+
test.capture [[
203+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
204+
<ConfigurationType>Application</ConfigurationType>
205+
<UseDebugLibraries>false</UseDebugLibraries>
206+
<UseOfMfc>Static</UseOfMfc>
207+
]]
208+
end
209+
210+
function suite.useOfMfc_onStaticRuntimeViaFlag()
188211
flags { "MFC" }
189212
staticruntime "On"
190213
prepare()
@@ -195,6 +218,29 @@
195218
<UseOfMfc>Static</UseOfMfc>
196219
]]
197220
end
221+
222+
function suite.useOfMfc_forceStatic()
223+
mfc "Static"
224+
prepare()
225+
test.capture [[
226+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
227+
<ConfigurationType>Application</ConfigurationType>
228+
<UseDebugLibraries>false</UseDebugLibraries>
229+
<UseOfMfc>Static</UseOfMfc>
230+
]]
231+
end
232+
233+
function suite.useOfMfc_forceDynamic()
234+
mfc "Dynamic"
235+
staticruntime "On"
236+
prepare()
237+
test.capture [[
238+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
239+
<ConfigurationType>Application</ConfigurationType>
240+
<UseDebugLibraries>false</UseDebugLibraries>
241+
<UseOfMfc>Dynamic</UseOfMfc>
242+
]]
243+
end
198244

199245
--
200246
-- Check the support for building with ATL.

modules/vstudio/vs200x_vcproj.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,8 +1539,12 @@
15391539

15401540

15411541
function m.useOfMFC(cfg)
1542-
if (cfg.flags.MFC) then
1542+
if (cfg.mfc == "On") then
15431543
p.w('UseOfMFC="%d"', iif(cfg.staticruntime == "On", 1, 2))
1544+
elseif (cfg.mfc == "Static") then
1545+
p.w('UseOfMFC="1"')
1546+
elseif (cfg.mfc == "Dynamic") then
1547+
p.w('UseOfMFC="2"')
15441548
end
15451549
end
15461550

modules/vstudio/vs2010_vcxproj.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3225,8 +3225,14 @@
32253225

32263226

32273227
function m.useOfMfc(cfg)
3228-
if cfg.flags.MFC then
3228+
if (cfg.mfc == "On") then
32293229
m.element("UseOfMfc", nil, iif(cfg.staticruntime == "On", "Static", "Dynamic"))
3230+
elseif (cfg.mfc == "Off") then
3231+
m.element("UseOfMfc", nil, "false")
3232+
elseif (cfg.mfc == "Static") then
3233+
m.element("UseOfMfc", nil, "Static")
3234+
elseif (cfg.mfc == "Dynamic") then
3235+
m.element("UseOfMfc", nil, "Dynamic")
32303236
end
32313237
end
32323238

tests/base/test_configset.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@
177177
function suite.remove_onExactValueMatch()
178178
local f = field.get("flags")
179179

180-
local r, err = configset.store(cset, f, { "MFC", "MultiProcessorCompile", "NoPCH" })
180+
local r, err = configset.store(cset, f, { "WPF", "MultiProcessorCompile", "NoPCH" })
181181
test.isnil(err)
182182

183-
configset.remove(cset, f, { "MFC" })
183+
configset.remove(cset, f, { "WPF" })
184184

185185
local result = configset.fetch(cset, f)
186186
test.isequal({ "MultiProcessorCompile", "NoPCH" }, result)
@@ -190,10 +190,10 @@
190190
function suite.remove_onMultipleValues()
191191
local f = field.get("flags")
192192

193-
local r, err = configset.store(cset, f, { "Maps", "MFC", "MultiProcessorCompile", "NoPCH" })
193+
local r, err = configset.store(cset, f, { "Maps", "WPF", "MultiProcessorCompile", "NoPCH" })
194194
test.isnil(err)
195195

196-
configset.remove(cset, f, { "Maps", "MFC" })
196+
configset.remove(cset, f, { "Maps", "WPF" })
197197

198198
local result = configset.fetch(cset, f)
199199
test.isequal({ "MultiProcessorCompile", "NoPCH" }, result)

website/docs/flags.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ flags { "flag_list" }
1616
| FatalWarnings | Treat all warnings as errors; equivalent to FatalCompileWarnings, FatalLinkWarnings |
1717
| LinkTimeOptimization | Enable link-time (i.e. whole program) optimizations. |
1818
| Maps | Enable Generate Map File for Visual Studio |
19-
| MFC | Enable support for Microsoft Foundation Classes. |
19+
| MFC | Enable support for Microsoft Foundation Classes. Deprecated in Premake 5.0.0-beta4. |
2020
| MultiProcessorCompile | Enable Visual Studio to use multiple compiler processes when building. |
2121
| No64BitChecks | Disable 64-bit portability warnings. |
2222
| NoBufferSecurityCheck | Turn off stack protection checks. |

website/docs/mfc.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Sets the version of the MFC libraries to link against.
2+
3+
```lua
4+
mfc "On"
5+
```
6+
7+
### Parameters ###
8+
9+
*value* specifies the desired PIC mode:
10+
11+
| Value | Description |
12+
|-------------|--------------------------------------------------------------------------------------------------------|
13+
| Default | Perform the default linkage against the MFC libraries for your project type. |
14+
| Off | Do not link against MFC libraries. |
15+
| On | Link against the MFC libraries corresponding with the runtime type you are using (static or dynamic). |
16+
| Static | Force static linkage to the MFC libraries. |
17+
| Dynamic | Force dynamic linkage to the MFC libraries. |
18+
19+
### Applies To ###
20+
21+
Project configurations.
22+
23+
### Availability ###
24+
25+
Premake 5.0-beta4 or later on Visual Studio.

website/sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ module.exports = {
190190
'llvmdir',
191191
'llvmversion',
192192
'makesettings',
193+
'mfc',
193194
'namespace',
194195
'nativewchar',
195196
'newaction',

0 commit comments

Comments
 (0)