From 0dfc5f5eab3dd80cbc685ef9cad6ddcca2108605 Mon Sep 17 00:00:00 2001 From: Rsu Date: Sat, 6 May 2023 23:26:04 +0900 Subject: [PATCH] add props --- modules/vstudio/_manifest.lua | 2 +- modules/vstudio/_preload.lua | 7 ++ modules/vstudio/tests/_tests.lua | 1 + .../tests/cs2005/test_additional_props.lua | 71 +++++++++++++++++++ modules/vstudio/tests/vc2010/test_globals.lua | 36 ++++++++++ modules/vstudio/vs2005_csproj.lua | 3 +- modules/vstudio/vs2005_dotnetbase.lua | 16 ++++- modules/vstudio/vs2005_fsproj.lua | 1 + modules/vstudio/vs2010_vcxproj.lua | 12 +++- website/docs/props.md | 47 ++++++++++++ 10 files changed, 191 insertions(+), 5 deletions(-) create mode 100644 modules/vstudio/tests/cs2005/test_additional_props.lua create mode 100644 website/docs/props.md diff --git a/modules/vstudio/_manifest.lua b/modules/vstudio/_manifest.lua index 123b36c081..948925b63a 100644 --- a/modules/vstudio/_manifest.lua +++ b/modules/vstudio/_manifest.lua @@ -25,5 +25,5 @@ return { "vs2015.lua", "vs2017.lua", "vs2019.lua", - "vs2022.lua" + "vs2022.lua", } diff --git a/modules/vstudio/_preload.lua b/modules/vstudio/_preload.lua index eae6fae82b..16f6967a8a 100644 --- a/modules/vstudio/_preload.lua +++ b/modules/vstudio/_preload.lua @@ -195,6 +195,13 @@ } } + p.api.register { + name = "props", + scope = "config", + kind = "list:table", + tokens = true, + } + -- -- Decide when the full module should be loaded. -- diff --git a/modules/vstudio/tests/_tests.lua b/modules/vstudio/tests/_tests.lua index 07cd658a26..3bf71afba0 100644 --- a/modules/vstudio/tests/_tests.lua +++ b/modules/vstudio/tests/_tests.lua @@ -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", diff --git a/modules/vstudio/tests/cs2005/test_additional_props.lua b/modules/vstudio/tests/cs2005/test_additional_props.lua new file mode 100644 index 0000000000..30d9251580 --- /dev/null +++ b/modules/vstudio/tests/cs2005/test_additional_props.lua @@ -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 + enable + 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 + aaa + enable + ]] + end diff --git a/modules/vstudio/tests/vc2010/test_globals.lua b/modules/vstudio/tests/vc2010/test_globals.lua index a6542567fe..969bd96318 100644 --- a/modules/vstudio/tests/vc2010/test_globals.lua +++ b/modules/vstudio/tests/vc2010/test_globals.lua @@ -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 [[ + + {42B5DBC6-AE1F-903D-F75D-41E363076E92} + true + Win32Proj + MyProject + + + custom_path + DebugParam + + + custom_path + ReleaseParam + + ]] + end + + function suite.disableFastUpToDateCheck() fastuptodate "Off" prepare() diff --git a/modules/vstudio/vs2005_csproj.lua b/modules/vstudio/vs2005_csproj.lua index 83a6816319..73c252efda 100644 --- a/modules/vstudio/vs2005_csproj.lua +++ b/modules/vstudio/vs2005_csproj.lua @@ -81,7 +81,8 @@ dotnetbase.debugProps, dotnetbase.outputProps, dotnetbase.compilerProps, - dotnetbase.NoWarn + dotnetbase.additionalProps, + dotnetbase.NoWarn, } end diff --git a/modules/vstudio/vs2005_dotnetbase.lua b/modules/vstudio/vs2005_dotnetbase.lua index e6371c8fca..b623086993 100644 --- a/modules/vstudio/vs2005_dotnetbase.lua +++ b/modules/vstudio/vs2005_dotnetbase.lua @@ -58,7 +58,7 @@ if dotnetbase.isNewFormatProject(prj) then if prj.flags.WPF then _p('') - else + else _p('') end else @@ -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', key, value, key) + end + end + end -- -- Write the compiler flags for a particular configuration. @@ -740,6 +751,7 @@ end end + function dotnetbase.targetFrameworkProfile(cfg) if _ACTION == "vs2010" then _p(2,'') @@ -789,4 +801,4 @@ if cfg.clr == "Unsafe" then _p(2,'true') end - end \ No newline at end of file + end diff --git a/modules/vstudio/vs2005_fsproj.lua b/modules/vstudio/vs2005_fsproj.lua index 6c7e8a8d76..779103ccd7 100644 --- a/modules/vstudio/vs2005_fsproj.lua +++ b/modules/vstudio/vs2005_fsproj.lua @@ -52,6 +52,7 @@ dotnetbase.debugProps, dotnetbase.outputProps, dotnetbase.compilerProps, + dotnetbase.additionalProps, dotnetbase.NoWarn, fs2005.tailCalls } diff --git a/modules/vstudio/vs2010_vcxproj.lua b/modules/vstudio/vs2010_vcxproj.lua index 9eec95a402..0e95e17e35 100644 --- a/modules/vstudio/vs2010_vcxproj.lua +++ b/modules/vstudio/vs2010_vcxproj.lua @@ -143,6 +143,7 @@ return { m.windowsTargetPlatformVersion, m.xpDeprecationWarning, + m.additionalProps, } end @@ -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 @@ -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")) diff --git a/website/docs/props.md b/website/docs/props.md new file mode 100644 index 0000000000..e0cde8289e --- /dev/null +++ b/website/docs/props.md @@ -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", + } +```