Skip to content

Commit a903a2c

Browse files
authored
Ignore MIDL files which are excluded from the build (#1019)
* Ignore MIDL files which are excluded from the build Without this, cppwinrt would attempt to use the output of MIDL files which where excluded from the build, resuting in mdmerge either erroring due to missing files, or using partially outdated buid output. * Fix up other uses of @(Midl)
1 parent 1c07e1b commit a903a2c

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

nuget/Microsoft.Windows.CppWinRT.targets

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,24 @@ Copyright (C) Microsoft Corporation. All rights reserved.
190190
</ItemGroup>
191191
</Target>
192192

193+
<Target Name="CppWinRTGetBuildingMidl"
194+
DependsOnTargets="CppWinRTComputeXamlGeneratedMidlInputs"
195+
Returns="@(_BuildingMidl)">
196+
<ItemGroup>
197+
<_BuildingMidl Include="@(Midl)" Condition="'%(Midl.ExcludedFromBuild)' != 'true'" />
198+
</ItemGroup>
199+
</Target>
200+
193201
<!-- Target used only to evaluate CppWinRTGenerateWindowsMetadata if it doesn't already have a value -->
194202
<Target Name="CppWinRTComputeGenerateWindowsMetadata"
195-
DependsOnTargets="CppWinRTComputeXamlGeneratedMidlInputs;GetCppWinRTProjectWinMDReferences;$(CppWinRTComputeGenerateWindowsMetadataDependsOn)">
203+
DependsOnTargets="CppWinRTGetBuildingMidl;GetCppWinRTProjectWinMDReferences;$(CppWinRTComputeGenerateWindowsMetadataDependsOn)">
196204

197205
<PropertyGroup>
198206
<!-- For static libraries, only idl causes a winmd to be generated.
199207
For exe/dll, static libraries that produce a WinMD will be merged,
200208
so they also cause a WinMD to be generated-->
201-
<CppWinRTGenerateWindowsMetadata Condition="'$(ConfigurationType)' != 'StaticLibrary' AND '@(CppWinRTStaticProjectWinMDReferences)@(Midl)'!= ''">true</CppWinRTGenerateWindowsMetadata>
202-
<CppWinRTGenerateWindowsMetadata Condition="'$(ConfigurationType)' == 'StaticLibrary' AND '@(Midl)'!= ''">true</CppWinRTGenerateWindowsMetadata>
209+
<CppWinRTGenerateWindowsMetadata Condition="'$(ConfigurationType)' != 'StaticLibrary' AND '@(CppWinRTStaticProjectWinMDReferences)@(_BuildingMidl)'!= ''">true</CppWinRTGenerateWindowsMetadata>
210+
<CppWinRTGenerateWindowsMetadata Condition="'$(ConfigurationType)' == 'StaticLibrary' AND '@(_BuildingMidl)'!= ''">true</CppWinRTGenerateWindowsMetadata>
203211

204212
<!-- At this point we checked all cases where we do generate a WinMD.
205213
The remaining option is no WinMD. -->
@@ -345,12 +353,12 @@ Copyright (C) Microsoft Corporation. All rights reserved.
345353

346354
<!-- Calculates the input files and metadata directories to be passed to MdMerge -->
347355
<Target Name="GetCppWinRTMdMergeInputs"
348-
DependsOnTargets="CppWinRTComputeXamlGeneratedMidlInputs;CppWinRTResolveReferences;"
349-
Returns="@(CppWinRTMdMergeMetadataDirectories);@(CppWinRTMdMergeInputs)">
356+
DependsOnTargets="CppWinRTGetBuildingMidl;CppWinRTResolveReferences"
357+
Returns="@(CppWinRTMdMergeMetadataDirectories);@(CppWinRTMdMergeInputs)">
350358
<ItemGroup>
351359
<_MdMergeInputs Remove="@(_MdMergeInputs)"/>
352-
<_MdMergeInputs Include="@(Midl)">
353-
<WinMDPath>%(Midl.OutputDirectory)%(Midl.MetadataFileName)</WinMDPath>
360+
<_MdMergeInputs Include="@(_BuildingMidl)">
361+
<WinMDPath>%(_BuildingMidl.OutputDirectory)%(_BuildingMidl.MetadataFileName)</WinMDPath>
354362
<MdMergeOutputFile>$(CppWinRTProjectWinMD)</MdMergeOutputFile>
355363
</_MdMergeInputs>
356364
<!-- Static libraries don't mdmerge other static libraries.
@@ -387,7 +395,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
387395
<ItemGroup>
388396
<Midl Remove="$(XamlMetaDataProviderIdl)" />
389397
<Midl Include="$(XamlMetaDataProviderIdl)">
390-
<DisableReferences Condition="$(_DisableReferences)">>true</DisableReferences>
398+
<DisableReferences Condition="$(_DisableReferences)">true</DisableReferences>
391399
</Midl>
392400
</ItemGroup>
393401
</Target>

0 commit comments

Comments
 (0)