Skip to content

Commit

Permalink
add props
Browse files Browse the repository at this point in the history
  • Loading branch information
hanagasira committed Jul 29, 2023
1 parent 26725da commit 0dfc5f5
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modules/vstudio/_manifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ return {
"vs2015.lua",
"vs2017.lua",
"vs2019.lua",
"vs2022.lua"
"vs2022.lua",
}
7 changes: 7 additions & 0 deletions modules/vstudio/_preload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@
}
}

p.api.register {
name = "props",
scope = "config",
kind = "list:table",
tokens = true,
}

--
-- Decide when the full module should be loaded.
--
Expand Down
1 change: 1 addition & 0 deletions modules/vstudio/tests/_tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ return {
"dotnet2005/test_nuget_framework_folders.lua",

-- Visual Studio 2005+ C# projects
"cs2005/test_additional_props.lua",
"cs2005/test_assembly_refs.lua",
"cs2005/test_build_events.lua",
"cs2005/test_common_props.lua",
Expand Down
71 changes: 71 additions & 0 deletions modules/vstudio/tests/cs2005/test_additional_props.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
--
-- tests/actions/vstudio/cs2005/test_additional_props.lua
-- Test the compiler flags of a Visual Studio 2005+ C# project.
-- Copyright (c) 2012-2023 Jason Perkins and the Premake project
--

local p = premake
local suite = test.declare("vstudio_cs2005_additional_props")
local dn2005 = p.vstudio.dotnetbase
local project = p.project


--
-- Setup and teardown
--

local wks, prj

function suite.setup()
p.action.set("vs2005")
wks, prj = test.createWorkspace()
end

local function prepare()
local cfg = test.getconfig(prj, "Debug")
dn2005.additionalProps(cfg)
end


--
-- Check handling of AdditionialProps.
-- Elements specified at a time are sorted by name before placement.
--

function suite.propsAreSorted()
props {
Zzz = "zzz",
Aaa = "aaa",
Nullable = "enable",
}
prepare()
test.capture [[
<Aaa>aaa</Aaa>
<Nullable>enable</Nullable>
<Zzz>zzz</Zzz>
]]
end


--
-- Check handling of AdditionialProps.
-- Element groups set multiple times are placed in the order in which they are set.
--

function suite.multipleSetPropsAreNotSorted()
props {
Zzz = "zzz",
}
props {
Aaa = "aaa",
}
props {
Nullable = "enable",
}
prepare()
test.capture [[
<Zzz>zzz</Zzz>
<Aaa>aaa</Aaa>
<Nullable>enable</Nullable>
]]
end
36 changes: 36 additions & 0 deletions modules/vstudio/tests/vc2010/test_globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,42 @@ end
end


function suite.additionalProps()
p.action.set("vs2022")

props {
-- https://devblogs.microsoft.com/directx/gettingstarted-dx12agility/#2-set-agility-sdk-parameters
Microsoft_Direct3D_D3D12_D3D12SDKPath = "custom_path",
}
filter "Debug"
props {
CustomParam = "DebugParam",
}
filter "Release"
props {
CustomParam = "ReleaseParam",
}
filter {}
prepare()
test.capture [[
<PropertyGroup Label="Globals">
<ProjectGuid>{42B5DBC6-AE1F-903D-F75D-41E363076E92}</ProjectGuid>
<IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
<Keyword>Win32Proj</Keyword>
<RootNamespace>MyProject</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Globals">
<Microsoft_Direct3D_D3D12_D3D12SDKPath>custom_path</Microsoft_Direct3D_D3D12_D3D12SDKPath>
<CustomParam>DebugParam</CustomParam>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Globals">
<Microsoft_Direct3D_D3D12_D3D12SDKPath>custom_path</Microsoft_Direct3D_D3D12_D3D12SDKPath>
<CustomParam>ReleaseParam</CustomParam>
</PropertyGroup>
]]
end


function suite.disableFastUpToDateCheck()
fastuptodate "Off"
prepare()
Expand Down
3 changes: 2 additions & 1 deletion modules/vstudio/vs2005_csproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
dotnetbase.debugProps,
dotnetbase.outputProps,
dotnetbase.compilerProps,
dotnetbase.NoWarn
dotnetbase.additionalProps,
dotnetbase.NoWarn,
}
end

Expand Down
16 changes: 14 additions & 2 deletions modules/vstudio/vs2005_dotnetbase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
if dotnetbase.isNewFormatProject(prj) then
if prj.flags.WPF then
_p('<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">')
else
else
_p('<Project Sdk="Microsoft.NET.Sdk">')
end
else
Expand Down Expand Up @@ -241,6 +241,17 @@
end
end

--
-- Write out the additional props.
--

function dotnetbase.additionalProps(cfg)
for i = 1, #cfg.props do
for key, value in spairs(cfg.props[i]) do
_p(2, '<%s>%s</%s>', key, value, key)
end
end
end

--
-- Write the compiler flags for a particular configuration.
Expand Down Expand Up @@ -740,6 +751,7 @@
end
end


function dotnetbase.targetFrameworkProfile(cfg)
if _ACTION == "vs2010" then
_p(2,'<TargetFrameworkProfile>')
Expand Down Expand Up @@ -789,4 +801,4 @@
if cfg.clr == "Unsafe" then
_p(2,'<AllowUnsafeBlocks>true</AllowUnsafeBlocks>')
end
end
end
1 change: 1 addition & 0 deletions modules/vstudio/vs2005_fsproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
dotnetbase.debugProps,
dotnetbase.outputProps,
dotnetbase.compilerProps,
dotnetbase.additionalProps,
dotnetbase.NoWarn,
fs2005.tailCalls
}
Expand Down
12 changes: 11 additions & 1 deletion modules/vstudio/vs2010_vcxproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
return {
m.windowsTargetPlatformVersion,
m.xpDeprecationWarning,
m.additionalProps,
}
end

Expand Down Expand Up @@ -1349,8 +1350,8 @@
if value and #value > 0 then
m.element(prop.name, m.configPair(cfg), '%s', value)
end
end
end
end
if #m.conditionalElements > 0 then
m.emitConditionalElements(prj)
end
Expand Down Expand Up @@ -2903,6 +2904,15 @@
end


function m.additionalProps(prj, cfg)
for i = 1, #cfg.props do
for key, value in spairs(cfg.props[i]) do
m.element(key, nil, value)
end
end
end


function m.fastUpToDateCheck(prj)
if prj.fastuptodate ~= nil then
m.element("DisableFastUpToDateCheck", nil, iif(prj.fastuptodate, "false", "true"))
Expand Down
47 changes: 47 additions & 0 deletions website/docs/props.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Add any property to your visual studio project
This allows you to set properties that premake does not support without extending it

Values set at one time are sorted alphabetically

```lua
props {
Name1 = "value1",
Name2 = "value2",
}
```

### Parameters ###

Name and value are strings

### Availability ###

Premake 5.0-beta3 or later.

### Applies To ###

The `config` scope.

### Examples ###

```lua
language "C#"
props {
-- https://devblogs.microsoft.com/visualstudio/vs-toolbox-accelerate-your-builds-of-sdk-style-net-projects/
AccelerateBuildsInVisualStudio = "true",
-- https://learn.microsoft.com/en-us/visualstudio/ide/how-to-change-the-build-output-directory?view=vs-2022
AppendTargetFrameworkToOutputPath = "false",
-- https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/nullable-reference-types
Nullable = "enable",
}
```
```lua
language "C++"
nuget {
"Microsoft.Direct3D.D3D12:1.608.2"
}
props {
-- https://devblogs.microsoft.com/directx/gettingstarted-dx12agility/#2-set-agility-sdk-parameters
Microsoft_Direct3D_D3D12_D3D12SDKPath = "custom_path",
}
```

0 comments on commit 0dfc5f5

Please sign in to comment.