Override GetResolvedWinMD to make sure all native build targets are aware of the C++/WinRT produced WinMD. (#432)

This commit is contained in:
Johan Laanstra 2019-11-27 11:23:35 -08:00 коммит произвёл Kenny Kerr
Родитель 190a347999
Коммит 84095fb5b1
15 изменённых файлов: 87 добавлений и 24 удалений

Просмотреть файл

@ -26,7 +26,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<!-- For CX projects, CppWinRT will never output a winmd-->
<!-- NOTE: We don't set a default here as the default requires evaluation of project references
and this is done by the ComputeCppWinRTResolvedWinMD target. -->
and this is done by the CppWinRTComputeGenerateWindowsMetadata target. -->
<CppWinRTGenerateWindowsMetadata Condition="'$(CppWinRTGenerateWindowsMetadata)' == '' AND '$(XamlLanguage)' == 'C++' ">false</CppWinRTGenerateWindowsMetadata>
<!-- For CX projects, turn off the component projection generation-->
<CppWinRTEnableComponentProjection Condition="'$(CppWinRTEnableComponentProjection)' == '' AND '$(XamlLanguage)' == 'C++' ">false</CppWinRTEnableComponentProjection>
@ -40,11 +40,9 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<!--TEMP: Override NuGet SDK's erroneous setting in uap.props -->
<WindowsSDK_MetadataFoundationPath Condition="('$(WindowsSDK_MetadataFoundationPath)'!='') And !Exists($(WindowsSDK_MetadataFoundationPath))">$(WindowsSDK_MetadataPathVersioned)</WindowsSDK_MetadataFoundationPath>
<GetTargetPathDependsOn>
$(GetTargetPathDependsOn);ComputeCppWinRTResolvedWinMD;CppWinRTResolvedWinMD;
</GetTargetPathDependsOn>
<PrepareForBuildDependsOn>
$(PrepareForBuildDependsOn);CppWinRTVerifyKitVersion;
$(PrepareForBuildDependsOn);
CppWinRTVerifyKitVersion;
</PrepareForBuildDependsOn>
<!-- Note: Before* targets run before Compute* targets. -->
<BeforeMidlCompileTargets>
@ -57,9 +55,8 @@ Copyright (C) Microsoft Corporation. All rights reserved.
$(AfterMidlTargets);
GetCppWinRTMdMergeInputs;
CppWinRTMergeProjectWinMDInputs;
ComputeCppWinRTResolvedWinMD;
CppWinRTResolvedWinMD;
CppWinRTResolvedWinMDToOutputDirectory;
GetResolvedWinMD;
CppWinRTCopyWinMDToOutputDirectory;
</AfterMidlTargets>
<ResolveAssemblyReferencesDependsOn>
$(ResolveAssemblyReferencesDependsOn);GetCppWinRTProjectWinMDReferences;CppWinRTRemoveStaticLibraries;
@ -122,21 +119,66 @@ Copyright (C) Microsoft Corporation. All rights reserved.
</Target>
<!-- Target used only to evaluate CppWinRTGenerateWindowsMetadata if it doesn't already have a value -->
<Target Name="ComputeCppWinRTResolvedWinMD"
Condition="'$(CppWinRTGenerateWindowsMetadata)' == ''"
DependsOnTargets="GetCppWinRTMdMergeInputs">
<Target Name="CppWinRTComputeGenerateWindowsMetadata"
DependsOnTargets="CppWinRTComputeXamlGeneratedMidlInputs;GetCppWinRTProjectWinMDReferences;$(CppWinRTComputeGenerateWindowsMetadataDependsOn)">
<PropertyGroup>
<CppWinRTGenerateWindowsMetadata Condition="'@(CppWinRTMdMergeInputs)'!= ''">true</CppWinRTGenerateWindowsMetadata>
<CppWinRTGenerateWindowsMetadata Condition="'@(CppWinRTMdMergeInputs)'== ''">false</CppWinRTGenerateWindowsMetadata>
<!-- For static libraries, only idl causes a winmd to be generated.
For exe/dll, static libraries that produce a WinMD will be merged,
so they also cause a WinMD to be generated-->
<CppWinRTGenerateWindowsMetadata Condition="'$(ConfigurationType)' != 'StaticLibrary' AND '@(CppWinRTStaticProjectWinMDReferences)@(Midl)'!= ''">true</CppWinRTGenerateWindowsMetadata>
<CppWinRTGenerateWindowsMetadata Condition="'$(ConfigurationType)' == 'StaticLibrary' AND '@(Midl)'!= ''">true</CppWinRTGenerateWindowsMetadata>
<!-- At this point we checked all cases where we do generate a WinMD.
The remaining option is no WinMD. -->
<CppWinRTGenerateWindowsMetadata Condition="'$(CppWinRTGenerateWindowsMetadata)'== ''">false</CppWinRTGenerateWindowsMetadata>
</PropertyGroup>
</Target>
<Target Name="CppWinRTResolvedWinMD"
Condition="'$(CppWinRTGenerateWindowsMetadata)' == 'true'"
<Target Name="ComputeGetResolvedWinMD"
Condition="'$(CppWinRTGenerateWindowsMetadata)' == ''">
<!-- If CppWinRTGenerateWindowsMetadata is not defined, compute it.-->
<!-- We use Calltarget, so we don't run anything including DependsOnTargets
targets if $(CppWinRTGenerateWindowsMetadata) already has a value.-->
<CallTarget Targets="CppWinRTComputeGenerateWindowsMetadata" />
</Target>
<!-- This target overrides the GetResolvedWinMD target used to resolve the WinMD for native projects
so it is aware of the C++/WinRT generated WinMD.
Since not every project that consumes C++/WinRT uses it to generate a WinMD,
we need to keep the CX logic as well. -->
<Target Name="GetResolvedWinMD"
DependsOnTargets="ComputeGetResolvedWinMD"
Returns="@(WinMDFullPath)">
<!-- Copied from the CX GetResolvedWinMD target in Microsoft.CppBuild.targets -->
<ItemGroup>
<WinMDFullPath Remove="@(WinMDFullPath)"/>
<WinMDFullPath Include="$(CppWinRTProjectWinMD)">
<!-- To evaluate the GenerateWindowsMetadata value we need @(Link) to contains at least one element-->
<Link Include="tmp" Condition="'@(Link)'==''">
<DeleteSoon>true</DeleteSoon>
</Link>
<!-- Condition is modified to only do this if CppWinRTGenerateWindowsMetadata is not true. -->
<WinMDFullPath Condition="'%(Link.GenerateWindowsMetadata)' == 'true' AND '$(CppWinRTGenerateWindowsMetadata)' != 'true'"
Include="@(Link->Metadata('WindowsMetadataFile')->FullPath()->Distinct()->ClearMetadata())">
<TargetPath>$([System.IO.Path]::GetFileName('%(Link.WindowsMetadataFile)'))</TargetPath>
<Primary>true</Primary>
</WinMDFullPath>
<WinMDFullPath>
<Implementation>$(WinMDImplementationPath)$(TargetName)$(TargetExt)</Implementation>
<FileType>winmd</FileType>
<WinMDFile>true</WinMDFile>
<ProjectType>$(ConfigurationType)</ProjectType>
</WinMDFullPath>
<Link Remove="@(Link)" Condition="'%(Link.DeleteSoon)' == 'true'" />
</ItemGroup>
<!-- Add C++/WinRT primary WinMD to the WinMDFullPath if CppWinRTGenerateWindowsMetadata is true -->
<ItemGroup>
<WinMDFullPath Include="$(CppWinRTProjectWinMD)" Condition="'$(CppWinRTGenerateWindowsMetadata)' == 'true'">
<TargetPath>$([System.IO.Path]::GetFileName('$(CppWinRTProjectWinMD)'))</TargetPath>
<Primary>true</Primary>
<Implementation Condition="'$(TargetExt)' == '.dll'">$(WinMDImplementationPath)$(RootNamespace)$(TargetExt)</Implementation>
@ -146,7 +188,8 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<ProjectType>$(ConfigurationType)</ProjectType>
</WinMDFullPath>
</ItemGroup>
<Message Text="CppWinRTResolvedWinMD: @(WinMDFullPath->'%(FullPath)')" Importance="$(CppWinRTVerbosity)"/>
<Message Text="GetResolvedWinMD: @(WinMDFullPath->'%(FullPath)')" Importance="$(CppWinRTVerbosity)"/>
</Target>
<!-- Static library reference files are merged into the project that
@ -425,9 +468,9 @@ $(XamlMetaDataProviderPch)
<!-- Only copy winmd to output folder if CppWinRTGenerateWindowsMetadata is true -->
<!-- Note that Condition is evaluated before DependsOnTargets are run -->
<Target Name="CppWinRTResolvedWinMDToOutputDirectory"
<Target Name="CppWinRTCopyWinMDToOutputDirectory"
Condition="'$(CppWinRTGenerateWindowsMetadata)' == 'true'"
DependsOnTargets="CppWinRTMergeProjectWinMDInputs;$(CppWinRTResolvedWinMDToOutputDirectoryDependsOn)"
DependsOnTargets="CppWinRTMergeProjectWinMDInputs;$(CppWinRTCopyWinMDToOutputDirectoryDependsOn)"
Inputs="@(_MdMergedOutput)"
Outputs="$(CppWinRTProjectWinMD)">
<Copy UseHardlinksIfPossible="$(CppWinRTUseHardlinksIfPossible)"

Просмотреть файл

@ -22,6 +22,4 @@
<CppWinRTPath>$(SolutionDir)..\..\_build\$(CppWinRTPlatform)\$(Configuration)\</CppWinRTPath>
</PropertyGroup>
<Import Project="$(SolutionDir)..\..\nuget\Microsoft.Windows.CppWinRT.props" />
</Project>

Просмотреть файл

@ -6,6 +6,4 @@
<Import Condition="Exists($([MSBuild]::GetPathOfFileAbove('Directory.Build.targets','$(MSBuildThisFileDirectory)../')))" Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets','$(MSBuildThisFileDirectory)../'))" />
<Import Project="$(SolutionDir)..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>

Просмотреть файл

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.props" />
<PropertyGroup Label="Globals">
<CppWinRTOptimized>true</CppWinRTOptimized>
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
@ -168,4 +169,5 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>

Просмотреть файл

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.props" />
<PropertyGroup Label="Globals">
<CppWinRTOptimized>true</CppWinRTOptimized>
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
@ -129,4 +130,5 @@
</Text>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>

Просмотреть файл

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.props" />
<PropertyGroup Label="Globals">
<CppWinRTOptimized>true</CppWinRTOptimized>
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
@ -136,4 +137,5 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>

Просмотреть файл

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.props" />
<PropertyGroup Label="Globals">
<CppWinRTOptimized>true</CppWinRTOptimized>
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
@ -136,4 +137,5 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>

Просмотреть файл

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.props" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
@ -262,4 +263,5 @@
<ClCompile Include="TestRuntimeComponentCXClass.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>

Просмотреть файл

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.props" />
<PropertyGroup Label="Globals">
<CppWinRTOptimized>true</CppWinRTOptimized>
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
@ -130,4 +131,5 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>

Просмотреть файл

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.props" />
<PropertyGroup Label="Globals">
<CppWinRTOptimized>true</CppWinRTOptimized>
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
@ -227,4 +228,5 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>

Просмотреть файл

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.props" />
<PropertyGroup Label="Globals">
<CppWinRTOptimized>true</CppWinRTOptimized>
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
@ -227,4 +228,5 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>

Просмотреть файл

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.props" />
<PropertyGroup Label="Globals">
<CppWinRTOptimized>true</CppWinRTOptimized>
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
@ -222,4 +223,5 @@
</Midl>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>

Просмотреть файл

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.props" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
@ -204,4 +205,5 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>

Просмотреть файл

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.props" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
@ -204,4 +205,5 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>

Просмотреть файл

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.props" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
@ -215,4 +216,5 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>