Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 63 additions & 20 deletions nuget/Microsoft.Windows.CppWinRT.targets
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -57,9 +55,8 @@ Copyright (C) Microsoft Corporation. All rights reserved.
$(AfterMidlTargets);
GetCppWinRTMdMergeInputs;
CppWinRTMergeProjectWinMDInputs;
ComputeCppWinRTResolvedWinMD;
CppWinRTResolvedWinMD;
CppWinRTResolvedWinMDToOutputDirectory;
GetResolvedWinMD;
CppWinRTCopyWinMDToOutputDirectory;
</AfterMidlTargets>
<ResolveAssemblyReferencesDependsOn>
$(ResolveAssemblyReferencesDependsOn);GetCppWinRTProjectWinMDReferences;CppWinRTRemoveStaticLibraries;
Expand Down Expand Up @@ -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>
Expand All @@ -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
Expand Down Expand Up @@ -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)"
Expand Down
2 changes: 0 additions & 2 deletions test/nuget/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@
<CppWinRTPath>$(SolutionDir)..\..\_build\$(CppWinRTPlatform)\$(Configuration)\</CppWinRTPath>
</PropertyGroup>

<Import Project="$(SolutionDir)..\..\nuget\Microsoft.Windows.CppWinRT.props" />

</Project>
2 changes: 0 additions & 2 deletions test/nuget/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions test/nuget/TestApp/TestApp.vcxproj
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -168,4 +169,5 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -129,4 +130,5 @@
</Text>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -136,4 +137,5 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -136,4 +137,5 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -262,4 +263,5 @@
<ClCompile Include="TestRuntimeComponentCXClass.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -130,4 +131,5 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>
2 changes: 2 additions & 0 deletions test/nuget/TestStaticLibrary1/TestStaticLibrary1.vcxproj
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -227,4 +228,5 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>
2 changes: 2 additions & 0 deletions test/nuget/TestStaticLibrary2/TestStaticLibrary2.vcxproj
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -227,4 +228,5 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>
2 changes: 2 additions & 0 deletions test/nuget/TestStaticLibrary3/TestStaticLibrary3.vcxproj
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -222,4 +223,5 @@
</Midl>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>
2 changes: 2 additions & 0 deletions test/nuget/TestStaticLibrary4/TestStaticLibrary4.vcxproj
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -204,4 +205,5 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>
2 changes: 2 additions & 0 deletions test/nuget/TestStaticLibrary5/TestStaticLibrary5.vcxproj
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -204,4 +205,5 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>
2 changes: 2 additions & 0 deletions test/nuget/TestStaticLibrary6/TestStaticLibrary6.vcxproj
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -215,4 +216,5 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
<Import Project="$(ProjectDir)..\..\..\nuget\Microsoft.Windows.CppWinRT.targets" />
</Project>