Skip to content

Commit

Permalink
Replace MFC flag with a dedicated API
Browse files Browse the repository at this point in the history
  • Loading branch information
nickclark2016 committed Nov 23, 2024
1 parent 6f0cb4a commit 578c4f3
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 9 deletions.
23 changes: 22 additions & 1 deletion modules/vstudio/_preload.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--
-- _preload.lua
-- Define the makefile action(s).
-- Define the Visual Studio action(s).
-- Copyright (c) Jess Perkins and the Premake project
--

Expand Down Expand Up @@ -608,6 +608,27 @@
tokens = "true",
}

p.api.register {
name = "mfc",
scope = "config",
kind = "string",
allowed = {
"Default",
"Off",
"On",
"Static",
"Dynamic",
}
}

p.api.deprecateValue("flags", "MFC", 'Use `mfc` instead.',
function(value)
mfc("On")
end,
function(value)
mfc("Off")
end)

--
-- Decide when the full module should be loaded.
--
Expand Down
48 changes: 47 additions & 1 deletion modules/vstudio/tests/vc2010/test_config_props.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,18 @@
--

function suite.useOfMfc_onDynamicRuntime()
flags "MFC"
mfc "On"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<UseOfMfc>Dynamic</UseOfMfc>
]]
end

function suite.useOfMfc_onDynamicRuntimeViaFlag()
flags { "MFC" }
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand All @@ -185,6 +196,18 @@
end

function suite.useOfMfc_onStaticRuntime()
mfc "On"
staticruntime "On"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<UseOfMfc>Static</UseOfMfc>
]]
end

function suite.useOfMfc_onStaticRuntimeViaFlag()
flags { "MFC" }
staticruntime "On"
prepare()
Expand All @@ -195,6 +218,29 @@
<UseOfMfc>Static</UseOfMfc>
]]
end

function suite.useOfMfc_forceStatic()
mfc "Static"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<UseOfMfc>Static</UseOfMfc>
]]
end

function suite.useOfMfc_forceDynamic()
mfc "Dynamic"
staticruntime "On"
prepare()
test.capture [[
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<UseOfMfc>Dynamic</UseOfMfc>
]]
end

--
-- Check the support for building with ATL.
Expand Down
6 changes: 5 additions & 1 deletion modules/vstudio/vs200x_vcproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1539,8 +1539,12 @@


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

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


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

Expand Down
8 changes: 4 additions & 4 deletions tests/base/test_configset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@
function suite.remove_onExactValueMatch()
local f = field.get("flags")

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

configset.remove(cset, f, { "MFC" })
configset.remove(cset, f, { "WPF" })

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

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

configset.remove(cset, f, { "Maps", "MFC" })
configset.remove(cset, f, { "Maps", "WPF" })

local result = configset.fetch(cset, f)
test.isequal({ "MultiProcessorCompile", "NoPCH" }, result)
Expand Down
2 changes: 1 addition & 1 deletion website/docs/flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ flags { "flag_list" }
| FatalWarnings | Treat all warnings as errors; equivalent to FatalCompileWarnings, FatalLinkWarnings |
| LinkTimeOptimization | Enable link-time (i.e. whole program) optimizations. |
| Maps | Enable Generate Map File for Visual Studio |
| MFC | Enable support for Microsoft Foundation Classes. |
| MFC | Enable support for Microsoft Foundation Classes. Deprecated in Premake 5.0.0-beta4. |
| MultiProcessorCompile | Enable Visual Studio to use multiple compiler processes when building. |
| No64BitChecks | Disable 64-bit portability warnings. |
| NoBufferSecurityCheck | Turn off stack protection checks. |
Expand Down
25 changes: 25 additions & 0 deletions website/docs/mfc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Sets the version of the MFC libraries to link against.

```lua
mfc "On"
```

### Parameters ###

*value* specifies the desired PIC mode:

| Value | Description |
|-------------|--------------------------------------------------------------------------------------------------------|
| Default | Perform the default linkage against the MFC libraries for your project type. |
| Off | Do not link against MFC libraries. |
| On | Link against the MFC libraries corresponding with the runtime type you are using (static or dynamic). |
| Static | Force static linkage to the MFC libraries. |
| Dynamic | Force dynamic linkage to the MFC libraries. |

### Applies To ###

Project configurations.

### Availability ###

Premake 5.0-beta4 or later on Visual Studio.
1 change: 1 addition & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ module.exports = {
'llvmdir',
'llvmversion',
'makesettings',
'mfc',
'namespace',
'nativewchar',
'newaction',
Expand Down

0 comments on commit 578c4f3

Please sign in to comment.