Merge pull request #1747 from LORgames/ssurtees/consumewinrtextension

Added API for CompileAsWinRT
This commit is contained in:
starkos 2021-11-26 10:36:47 -05:00
commit a81717019e
6 changed files with 136 additions and 2 deletions

View File

@ -1672,3 +1672,58 @@
</ClCompile>
]]
end
--
-- If consumewinrtextension flag is set, add <CompileAsWinRT> element
--
function suite.onconsumewinrtextensionOff()
p.action.set("vs2019")
consumewinrtextension "Off"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<CompileAsWinRT>false</CompileAsWinRT>
]]
end
function suite.onconsumewinrtextensionOn()
p.action.set("vs2019")
consumewinrtextension "On"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<CompileAsWinRT>true</CompileAsWinRT>
]]
end
function suite.onconsumewinrtextensionNotSpecified()
p.action.set("vs2019")
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
</ClCompile>
]]
end
function suite.onconsumewinrtextensionOn_BeforeVS2019()
p.action.set("vs2017")
consumewinrtextension "On"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
</ClCompile>
]]
end

View File

@ -903,3 +903,37 @@
</ItemGroup>
]]
end
--
-- test consumewinrtextension set for a single file
--
function suite.consumewinrtextensionPerFile()
p.action.set("vs2019")
files { "hello.cpp", "hello2.cpp" }
filter { "files:hello.cpp" }
consumewinrtextension 'On'
prepare()
test.capture [[
<ItemGroup>
<ClCompile Include="hello.cpp">
<CompileAsWinRT>true</CompileAsWinRT>
</ClCompile>
<ClCompile Include="hello2.cpp" />
</ItemGroup>
]]
end
function suite.consumewinrtextensionPerFile_BeforeVS2019()
p.action.set("vs2017")
files { "hello.cpp", "hello2.cpp" }
filter { "files:hello.cpp" }
consumewinrtextension 'On'
prepare()
test.capture [[
<ItemGroup>
<ClCompile Include="hello.cpp" />
<ClCompile Include="hello2.cpp" />
</ItemGroup>
]]
end

View File

@ -393,7 +393,8 @@
m.conformanceMode,
m.structMemberAlignment,
m.useFullPaths,
m.removeUnreferencedCodeData
m.removeUnreferencedCodeData,
m.compileAsWinRT,
}
if cfg.kind == p.STATICLIB then
@ -816,6 +817,7 @@
m.compileAs,
m.runtimeTypeInfo,
m.warningLevelFile,
m.compileAsWinRT,
}
else
return {
@ -1544,6 +1546,14 @@
end
end
function m.compileAsWinRT(cfg, condition)
if _ACTION >= "vs2019" then
if cfg and cfg.consumewinrtextension ~= nil then
m.element("CompileAsWinRT", condition, iif(cfg.consumewinrtextension, "true", "false"))
end
end
end
function m.additionalCompileOptions(cfg, condition)
local opts = cfg.buildoptions
if _ACTION == "vs2015" or vstudio.isMakefile(cfg) then

View File

@ -203,6 +203,12 @@
kind = "list:string",
}
api.register {
name = "consumewinrtextension",
scope = "config",
kind = "boolean",
}
api.register {
name = "copylocal",
scope = "config",

View File

@ -0,0 +1,28 @@
Enables the WinRT extension, C++/CX, for the specified projects/files.
```lua
consumewinrtextension "value"
```
### Parameters ###
`value` is one of:
* `Default` - Compiles the file using the default for the toolset. (Default is `Off`)
* `On` - Compiles the file with the WinRT extension enabled.
* `Off` - Compiles the file without the WinRT extension enabled.
### Applies To ###
The `workspace`, `project` or `file` scope.
### Availability ###
Premake 5.0.0 Beta 2 or later and only implemented for Visual Studio 2019+.
### Examples ###
```lua
filter { "files:**_winrt.cpp" }
consumewinrtextension "On"
```

View File

@ -94,6 +94,7 @@ module.exports = {
'configuration',
'configurations',
'conformancemode',
'consumewinrtextension',
'copylocal',
'cppdialect',
'csversion',