Skip to content

Commit

Permalink
add vsprops
Browse files Browse the repository at this point in the history
  • Loading branch information
hanagasira committed Aug 10, 2023
1 parent 723992c commit e957529
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 2 deletions.
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 = "vsprops",
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
84 changes: 84 additions & 0 deletions modules/vstudio/tests/cs2005/test_additional_props.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
--
-- 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()
vsprops {
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()
vsprops {
Zzz = "zzz",
}
vsprops {
Aaa = "aaa",
}
vsprops {
Nullable = "enable",
}
prepare()
test.capture [[
<Zzz>zzz</Zzz>
<Aaa>aaa</Aaa>
<Nullable>enable</Nullable>
]]
end


function suite.xmlEscape()
vsprops {
ValueRequiringEscape = "if (age > 3 && age < 8)",
}
prepare()
test.capture [[
<ValueRequiringEscape>if (age &gt; 3 &amp;&amp; age &lt; 8)</ValueRequiringEscape>
]]
end


39 changes: 39 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,45 @@ end
end


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

vsprops {
-- https://devblogs.microsoft.com/directx/gettingstarted-dx12agility/#2-set-agility-sdk-parameters
Microsoft_Direct3D_D3D12_D3D12SDKPath = "custom_path",
ValueRequiringEscape = "if (age > 3 && age < 8)",
}
filter "Debug"
vsprops {
CustomParam = "DebugParam",
}
filter "Release"
vsprops {
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>
<ValueRequiringEscape>if (age &gt; 3 &amp;&amp; age &lt; 8)</ValueRequiringEscape>
<CustomParam>DebugParam</CustomParam>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Globals">
<Microsoft_Direct3D_D3D12_D3D12SDKPath>custom_path</Microsoft_Direct3D_D3D12_D3D12SDKPath>
<ValueRequiringEscape>if (age &gt; 3 &amp;&amp; age &lt; 8)</ValueRequiringEscape>
<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
13 changes: 13 additions & 0 deletions modules/vstudio/vs2005_dotnetbase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
p.vstudio.dotnetbase = {}

local vstudio = p.vstudio
local vs2005 = p.vstudio.vs2005
local dotnetbase = p.vstudio.dotnetbase
local project = p.project
local config = p.config
Expand Down Expand Up @@ -241,6 +242,17 @@
end
end

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

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

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


function dotnetbase.targetFrameworkProfile(cfg)
if _ACTION == "vs2010" then
_p(2,'<TargetFrameworkProfile>')
Expand Down
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
13 changes: 12 additions & 1 deletion modules/vstudio/vs2010_vcxproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
p.vstudio.vc2010 = {}

local vstudio = p.vstudio
local vs2010 = p.vstudio.vs2010
local project = p.project
local config = p.config
local fileconfig = p.fileconfig
Expand Down Expand Up @@ -143,6 +144,7 @@
return {
m.windowsTargetPlatformVersion,
m.xpDeprecationWarning,
m.additionalProps,
}
end

Expand Down Expand Up @@ -1349,8 +1351,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 +2905,15 @@
end


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


function m.fastUpToDateCheck(prj)
if prj.fastuptodate ~= nil then
m.element("DisableFastUpToDateCheck", nil, iif(prj.fastuptodate, "false", "true"))
Expand Down
51 changes: 51 additions & 0 deletions website/docs/vsprops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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
If you want to output groups of values in any order, set multiple times.

```lua
vsprops {
Name1 = "value1",
Name2 = "value2",
}
vsprops {
Name3 = "value3",
}
```

### Parameters ###

Name and value are strings

### Availability ###

Premake 5.0-beta3 or later.

### Applies To ###

The `config` scope.

### Examples ###

```lua
language "C#"
vsprops {
-- 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"
}
vsprops {
-- https://devblogs.microsoft.com/directx/gettingstarted-dx12agility/#2-set-agility-sdk-parameters
Microsoft_Direct3D_D3D12_D3D12SDKPath = "custom_path",
}
```

0 comments on commit e957529

Please sign in to comment.