wv2winrt.targets 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. ***********************************************************************************************
  4. Copyright (C) Microsoft Corporation. All rights reserved.
  5. Use of this source code is governed by a BSD-style license that can be
  6. found in the LICENSE file.
  7. ***********************************************************************************************
  8. -->
  9. <!-- This file contains the targets properties and such related to the wv2winrt tool. -->
  10. <Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  11. <PropertyGroup>
  12. <!-- Only do this for MSBuild versions below 16.0
  13. as it is since done automatically, see https://github.com/microsoft/msbuild/pull/3605
  14. -->
  15. <MSBuildAllProjects Condition="'$(MSBuildToolsVersion)' &lt;= '15'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
  16. </PropertyGroup>
  17. <PropertyGroup>
  18. <GeneratedFilesDir Condition="'$(GeneratedFilesDir)' == ''">$(IntDir)Generated Files\</GeneratedFilesDir>
  19. <WV2WinRTVerbosity Condition="'$(WV2WinRTVerbosity)' == ''">normal</WV2WinRTVerbosity>
  20. <WV2WinRTPath Condition="'$(WV2WinRTPath)' == ''">$([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)', '..\tools\wv2winrt'))</WV2WinRTPath>
  21. <WV2WinRTExe Condition="'$(WV2WinRTExe)' == ''">$(WV2WinRTPath)wv2winrt.exe</WV2WinRTExe>
  22. <WV2WinRTWinMDInputsResponseFile Condition="'$(WV2WinRTWinMDInputsResponseFile)' == ''">$(IntDir)wv2winrt_inputs.rsp</WV2WinRTWinMDInputsResponseFile>
  23. <WV2WinRTParametersResponseFile Condition="'$(WV2WinRTParametersResponseFile)' == ''">$(IntDir)wv2winrt_params.rsp</WV2WinRTParametersResponseFile>
  24. <WV2WinRTSkipMakeProjections Condition="'$(WV2WinRTSkipMakeProjections)' == ''">false</WV2WinRTSkipMakeProjections>
  25. <!-- If WebView2UseWinRT is enabled, we assume the generated classes are being used in this project and put them under wv2winrt default namespace. -->
  26. <WebView2DispatchAdapterNamespace Condition="'$(WebView2DispatchAdapterNamespace)' == '' and '$(WebView2UseWinRT)' == 'true'">WinRTAdapter</WebView2DispatchAdapterNamespace>
  27. <!-- Otherwise, we assume the project will be consumed from a separate project. We put generated code under RootNamespace in this case as that's the namespace that will be automatically available when the project is referenced. -->
  28. <WebView2DispatchAdapterNamespace Condition="'$(WebView2DispatchAdapterNamespace)' == ''">$(RootNamespace)</WebView2DispatchAdapterNamespace>
  29. <WebView2DispatchAdapterOutputDir Condition="'$(WebView2DispatchAdapterOutputDir)' == ''">$(GeneratedFilesDir)</WebView2DispatchAdapterOutputDir>
  30. <WebView2DispatchAdapterOutputDir>$([MSBuild]::EnsureTrailingSlash('$(WebView2DispatchAdapterOutputDir)'))</WebView2DispatchAdapterOutputDir>
  31. <WV2WinRTDisallowEmptyAdapter Condition="'$(WV2WinRTDisallowEmptyAdapter)' == ''">true</WV2WinRTDisallowEmptyAdapter>
  32. <WebView2WinRTWrapSystemTypes Condition="'$(WebView2WinRTWrapSystemTypes)' == ''">true</WebView2WinRTWrapSystemTypes>
  33. <WV2WinRTPlatformReferencesLevel Condition="'$(WV2WinRTPlatformReferencesLevel)' == ''">match</WV2WinRTPlatformReferencesLevel>
  34. <!-- Note: Before* targets run before Compute* targets. -->
  35. <BeforeMidlCompileTargets Condition="'$(WebView2UseDispatchAdapter)' == 'true'">
  36. $(BeforeMidlCompileTargets);WV2WinRTAddDispatchAdapterIdl;
  37. </BeforeMidlCompileTargets>
  38. <BeforeClCompileTargets Condition="'$(WebView2UseDispatchAdapter)' == 'true'">
  39. $(BeforeClCompileTargets);WV2WinRTAddGeneratedFiles;
  40. </BeforeClCompileTargets>
  41. </PropertyGroup>
  42. <Target Name="GetWV2WinRTPlatformWinMDReferences"
  43. DependsOnTargets="ResolveAssemblyReferences;CppWinRTImplicitlyExpandTargetPlatform;GetCppWinRTPlatformWinMDReferences;$(GetWV2WinRTPlatformWinMDReferencesDependsOn)"
  44. Returns="@(WV2WinRTPlatformWinMDReferences)">
  45. <ItemGroup>
  46. <_WV2WinRTPlatformWinMDReferences Remove="@(_WV2WinRTPlatformWinMDReferences)"/>
  47. <!-- Project platform references -->
  48. <_WV2WinRTPlatformWinMDReferences Include="@(ReferencePath)" Condition="('$(WV2WinRTPlatformReferencesLevel)' == 'explicit' or '$(WV2WinRTPlatformReferencesLevel)' == 'foundation') and '%(ReferencePath.IsSystemReference)' == 'true' and '%(ReferencePath.WinMDFile)' == 'true' and '%(ReferencePath.ReferenceSourceTarget)' == 'ResolveAssemblyReference'"/>
  49. <!-- Foundation contracts -->
  50. <_WV2WinRTPlatformWinMDReferences Include="$(WindowsSDK_MetadataPathVersioned)\**\Windows.Foundation.FoundationContract.winmd" Condition="'$(WV2WinRTPlatformReferencesLevel)' == 'foundation'"/>
  51. <_WV2WinRTPlatformWinMDReferences Include="$(WindowsSDK_MetadataPathVersioned)\**\Windows.Foundation.UniversalApiContract.winmd" Condition="'$(WV2WinRTPlatformReferencesLevel)' == 'foundation'"/>
  52. <_WV2WinRTPlatformWinMDReferences Include="$(WindowsSDK_MetadataPathVersioned)\**\Windows.Networking.Connectivity.WwanContract.winmd" Condition="'$(WV2WinRTPlatformReferencesLevel)' == 'foundation'"/>
  53. <!-- C++/WinRT -->
  54. <_WV2WinRTPlatformWinMDReferences Include="@(CppWinRTPlatformWinMDReferences)" Condition="'$(WV2WinRTPlatformReferencesLevel)' == 'match'"/>
  55. <WV2WinRTPlatformWinMDReferences Remove="@(WV2WinRTPlatformWinMDReferences)"/>
  56. <WV2WinRTPlatformWinMDReferences Include="@(_WV2WinRTPlatformWinMDReferences->'%(FullPath)'->Distinct())"/>
  57. </ItemGroup>
  58. <Message Text="WV2WinRTPlatformWinMDReferences: &#xA;@(WV2WinRTPlatformWinMDReferences->'%(FullPath)', '&#xA;')" Importance="$(WV2WinRTVerbosity)"/>
  59. </Target>
  60. <Target Name="GetWV2WinRTDirectWinMDReferences"
  61. DependsOnTargets="ResolveAssemblyReferences;GetCppWinRTDirectWinMDReferences;$(GetWV2WinRTDirectWinMDReferencesDependsOn)"
  62. Returns="@(WV2WinRTDirectWinMDReferences)">
  63. <ItemGroup>
  64. <_WV2WinRTDirectWinMDReferences Remove="@(_WV2WinRTDirectWinMDReferences)"/>
  65. <_WV2WinRTDirectWinMDReferences Include="@(CppWinRTDirectWinMDReferences)" Condition="'%(Filename)' != 'Microsoft.Web.WebView2.Core'"/>
  66. <_WV2WinRTDirectWinMDReferences Include="@(CppWinRTDirectWinMDReferences)" Condition="'%(Filename)' == 'Microsoft.Web.WebView2.Core' And '$(WV2WinRTWrapWebViewTypes)' == 'true'"/>
  67. <WV2WinRTDirectWinMDReferences Remove="@(WV2WinRTDirectWinMDReferences)"/>
  68. <WV2WinRTDirectWinMDReferences Include="@(_WV2WinRTDirectWinMDReferences)"/>
  69. </ItemGroup>
  70. <Message Text="WV2WinRTDirectWinMDReferences: &#xA;@(WV2WinRTDirectWinMDReferences->'%(FullPath)', '&#xA;')" Importance="$(WV2WinRTVerbosity)"/>
  71. </Target>
  72. <Target Name="GetWV2WinRTProjectWinMDReferences"
  73. DependsOnTargets="GetCppWinRTProjectWinMDReferences;$(GetWV2WinRTProjectWinMDReferencesDependsOn)"
  74. Returns="@(WV2WinRTProjectWinMDReferences)">
  75. <ItemGroup>
  76. <_WV2WinRTStaticProjectWinMDReferences Remove="@(_WV2WinRTStaticProjectWinMDReferences)"/>
  77. <_WV2WinRTStaticProjectWinMDReferences Include="@(CppWinRTStaticProjectWinMDReferences)"/>
  78. <WV2WinRTStaticProjectWinMDReferences Remove="@(WV2WinRTStaticProjectWinMDReferences)"/>
  79. <WV2WinRTStaticProjectWinMDReferences Include="@(_WV2WinRTStaticProjectWinMDReferences)"/>
  80. </ItemGroup>
  81. <ItemGroup>
  82. <_WV2WinRTDynamicProjectWinMDReferences Remove="@(_WV2WinRTDynamicProjectWinMDReferences)"/>
  83. <_WV2WinRTDynamicProjectWinMDReferences Include="@(CppWinRTDynamicProjectWinMDReferences)"/>
  84. <WV2WinRTDynamicProjectWinMDReferences Remove="@(WV2WinRTDynamicProjectWinMDReferences)"/>
  85. <WV2WinRTDynamicProjectWinMDReferences Include="@(_WV2WinRTDynamicProjectWinMDReferences)"/>
  86. </ItemGroup>
  87. <ItemGroup>
  88. <WV2WinRTProjectWinMDReferences Remove="@(WV2WinRTProjectWinMDReferences)"/>
  89. <WV2WinRTProjectWinMDReferences Include="@(WV2WinRTStaticProjectWinMDReferences)"/>
  90. <WV2WinRTProjectWinMDReferences Include="@(WV2WinRTDynamicProjectWinMDReferences)"/>
  91. </ItemGroup>
  92. <Message Text="WV2WinRTStaticProjectWinMDReferences: &#xA;@(WV2WinRTStaticProjectWinMDReferences->'%(FullPath)', '&#xA;')" Condition="'$(WV2WinRTLogIntermediateWinMDReferences)' == 'true'" Importance="$(WV2WinRTVerbosity)"/>
  93. <Message Text="WV2WinRTDynamicProjectWinMDReferences: &#xA;@(WV2WinRTDynamicProjectWinMDReferences->'%(FullPath)', '&#xA;')" Condition="'$(WV2WinRTLogIntermediateWinMDReferences)' == 'true'" Importance="$(WV2WinRTVerbosity)"/>
  94. <Message Text="WV2WinRTProjectWinMDReferences: &#xA;@(WV2WinRTProjectWinMDReferences->'%(FullPath)', '&#xA;')" Importance="$(WV2WinRTVerbosity)"/>
  95. </Target>
  96. <Target Name="GetWV2WinRTAdditionalWinMDReferences"
  97. DependsOnTargets="$(GetWV2WinRTAdditionalWinMDReferencesDependsOn)"
  98. Returns="@(WV2WinRTAdditionalWinMDReferences)">
  99. <ItemGroup>
  100. <WebView2WinRTAdditionalWinMDReferences Include="$(WebView2WinRTAdditionalWinMDReferences)"/>
  101. </ItemGroup>
  102. <ItemGroup>
  103. <_WV2WinRTAdditionalWinMDReferences Remove="@(_WV2WinRTAdditionalWinMDReferences)"/>
  104. <_WV2WinRTAdditionalWinMDReferences Include="@(WebView2WinRTAdditionalWinMDReferences)"/>
  105. <WV2WinRTAdditionalWinMDReferences Remove="@(WV2WinRTAdditionalWinMDReferences)"/>
  106. <WV2WinRTAdditionalWinMDReferences Include="@(_WV2WinRTAdditionalWinMDReferences)"/>
  107. </ItemGroup>
  108. <Message Text="WV2WinRTAdditionalWinMDReferences: &#xA;@(WV2WinRTAdditionalWinMDReferences->'%(FullPath)', '&#xA;')" Importance="$(WV2WinRTVerbosity)"/>
  109. </Target>
  110. <Target Name="GetWV2WinRTInputs"
  111. DependsOnTargets="GetWV2WinRTPlatformWinMDReferences;GetWV2WinRTDirectWinMDReferences;GetWV2WinRTProjectWinMDReferences;GetWV2WinRTAdditionalWinMDReferences;CppWinRTMakeComponentProjection"
  112. Outputs="$(WV2WinRTWinMDInputsResponseFile)">
  113. <ItemGroup>
  114. <_WV2WinRTInputs Remove="@(_WV2WinRTInputs)"/>
  115. <_WV2WinRTInputs Include="@(WV2WinRTDirectWinMDReferences)"/>
  116. <_WV2WinRTInputs Include="@(WV2WinRTPlatformWinMDReferences)" Condition="'$(WebView2WinRTWrapSystemTypes)' == 'true'"/>
  117. <_WV2WinRTInputs Include="@(WV2WinRTProjectWinMDReferences)"/>
  118. <_WV2WinRTInputs Include="@(WV2WinRTAdditionalWinMDReferences)"/>
  119. <_WV2WinRTInputs Include="@(_CppwinrtCompInputs)"/>
  120. <WV2WinRTInputs Remove="@(WV2WinRTInputs)"/>
  121. <WV2WinRTInputs Include="@(_WV2WinRTInputs->'%(FullPath)'->Distinct())">
  122. <WinMDPath>%(FullPath)</WinMDPath>
  123. </WV2WinRTInputs>
  124. </ItemGroup>
  125. <Error Condition="'@(_WV2WinRTInputs)' == '' And '$(WV2WinRTDisallowEmptyAdapter)' == 'true'" Text="No winmd inputs for WebView2 WinRT Projection"/>
  126. <!-- Always write the wv2winrt_inputs.rsp file when the target runs, because the file is used as the output of this target. -->
  127. <WriteLinesToFile
  128. File="$(WV2WinRTWinMDInputsResponseFile)" Lines="@(WV2WinRTInputs)"
  129. ContinueOnError="true" Overwrite="true" />
  130. <Message Text="WV2WinRTInputs: &#xA;@(WV2WinRTInputs->'%(WinMDPath)', '&#xA;')" Importance="$(WV2WinRTVerbosity)"/>
  131. </Target>
  132. <Target Name="WV2WinRTComputeIdlParameters">
  133. <PropertyGroup>
  134. <WV2WinRTIdlParameters>--idl</WV2WinRTIdlParameters>
  135. <WV2WinRTIdlParameters Condition="'$(WebView2DispatchAdapterOutputDir)' != ''">$(WV2WinRTIdlParameters) --output-path &quot;$(WebView2DispatchAdapterOutputDir.TrimEnd('\'))&quot;</WV2WinRTIdlParameters>
  136. <WV2WinRTIdlParameters Condition="'$(WebView2DispatchAdapterNamespace)' != ''">$(WV2WinRTIdlParameters) --output-namespace $(WebView2DispatchAdapterNamespace)</WV2WinRTIdlParameters>
  137. </PropertyGroup>
  138. </Target>
  139. <Target Name="WV2WinRTGenerateDispatchAdapterIdl"
  140. DependsOnTargets="WV2WinRTComputeIdlParameters"
  141. Inputs="$(WV2WinRTExe)"
  142. Outputs="$(WebView2DispatchAdapterOutputDir)wv2winrt\DispatchAdapter.idl">
  143. <PropertyGroup>
  144. <WV2WinRTIdlCommand>&quot;$(WV2WinRTExe)&quot; $(WV2WinRTIdlParameters)</WV2WinRTIdlCommand>
  145. </PropertyGroup>
  146. <Message Text="$(WV2WinRTIdlCommand)" Importance="$(WV2WinRTVerbosity)"/>
  147. <Exec Command="$(WV2WinRTIdlCommand)"/>
  148. </Target>
  149. <Target Name="WV2WinRTAddDispatchAdapterIdl"
  150. DependsOnTargets="WV2WinRTGenerateDispatchAdapterIdl">
  151. <ItemGroup>
  152. <Midl Include="$(WebView2DispatchAdapterOutputDir)wv2winrt\DispatchAdapter.idl" />
  153. </ItemGroup>
  154. </Target>
  155. <Target Name="WV2WinRTComputeParameters"
  156. DependsOnTargets="GetWV2WinRTInputs"
  157. Inputs="$(WV2WinRTWinMDInputsResponseFile)"
  158. Outputs="$(IntDir)wv2winrt.rsp">
  159. <ItemGroup>
  160. <WV2WinRTIncludeFilters Remove="@(WV2WinRTIncludeFilters)"/>
  161. <WV2WinRTIncludeFilters Include="$(WebView2DispatchAdapterIncludeFilters)"/>
  162. <WV2WinRTIncludeFilters Include="@(WebView2DispatchAdapterIncludeFilters)"/>
  163. <WV2WinRTExcludeFilters Remove="@(WV2WinRTExcludeFilters)"/>
  164. <WV2WinRTExcludeFilters Include="$(WebView2DispatchAdapterExcludeFilters)"/>
  165. <WV2WinRTExcludeFilters Include="@(WebView2DispatchAdapterExcludeFilters)"/>
  166. </ItemGroup>
  167. <ItemGroup>
  168. <_PCH Include="@(ClCompile->Metadata('PrecompiledHeaderFile')->Distinct())"/>
  169. </ItemGroup>
  170. <Error Condition="'@(_PCH->Count())' &gt; '1'" Text="wv2winrt only supports a single PCH."/>
  171. <PropertyGroup>
  172. <_PCH>@(_PCH->Distinct())</_PCH>
  173. </PropertyGroup>
  174. <PropertyGroup>
  175. <WV2WinRTParameters Condition="'$(WebView2DispatchAdapterOutputDir)' != ''">--output-path &quot;$(WebView2DispatchAdapterOutputDir.TrimEnd('\'))&quot;</WV2WinRTParameters>
  176. <WV2WinRTParameters Condition="'$(WebView2DispatchAdapterNamespace)' != ''">$(WV2WinRTParameters) --output-namespace $(WebView2DispatchAdapterNamespace)</WV2WinRTParameters>
  177. <WV2WinRTParameters Condition="'$(WebView2DispatchAdapterNamespace)' != '$(RootNamespace)'">$(WV2WinRTParameters) --use-full-namespace</WV2WinRTParameters>
  178. <WV2WinRTParameters Condition="'$(WebView2DispatchAdapterUseJavaScriptCase)' == 'true'">$(WV2WinRTParameters) --use-javascript-case</WV2WinRTParameters>
  179. <WV2WinRTParameters Condition="'$(WV2WinRTExplicitIncludesOnly)' == 'true'">$(WV2WinRTParameters) --explicit-includes-only</WV2WinRTParameters>
  180. <WV2WinRTParameters Condition="'@(WV2WinRTIncludeFilters)' != ''">$(WV2WinRTParameters) --include @(WV2WinRTIncludeFilters, ' ')</WV2WinRTParameters>
  181. <WV2WinRTParameters Condition="'@(WV2WinRTExcludeFilters)' != ''">$(WV2WinRTParameters) --exclude @(WV2WinRTExcludeFilters, ' ')</WV2WinRTParameters>
  182. <WV2WinRTParameters Condition="'@(WV2WinRTInputs)' != ''">$(WV2WinRTParameters) --winmd-paths @(WV2WinRTInputs->'&quot;%(WinMDPath)&quot;', ' ')</WV2WinRTParameters>
  183. <WV2WinRTParameters Condition="'$(_PCH)' != ''">$(WV2WinRTParameters) --pch &quot;$(_PCH)&quot;</WV2WinRTParameters>
  184. <WV2WinRTParameters Condition="'$(WV2WinRTAdditionalParameters)' != ''">$(WV2WinRTParameters) $(WV2WinRTAdditionalParameters)</WV2WinRTParameters>
  185. </PropertyGroup>
  186. <!-- Always write the wv2winrt.rsp file when the target runs, because the file is used as the output of this target. -->
  187. <WriteLinesToFile
  188. File="$(IntDir)wv2winrt.rsp" Lines="$(WV2WinRTParameters)"
  189. ContinueOnError="true" Overwrite="true" />
  190. </Target>
  191. <Target Name="WV2WinRTMakeProjections"
  192. Condition="'$(WV2WinRTSkipMakeProjections)' != 'true'"
  193. DependsOnTargets="WV2WinRTComputeParameters"
  194. Inputs="$(IntDir)wv2winrt.rsp"
  195. Outputs="$(WebView2DispatchAdapterOutputDir)wv2winrt\**">
  196. <PropertyGroup>
  197. <WV2WinRTCommand>&quot;$(WV2WinRTExe)&quot; $(WV2WinRTParameters)</WV2WinRTCommand>
  198. </PropertyGroup>
  199. <Message Text="$(WV2WinRTCommand)" Importance="$(WV2WinRTVerbosity)"/>
  200. <Exec Command="$(WV2WinRTCommand)"/>
  201. </Target>
  202. <Target Name="WV2WinRTAddGeneratedFiles"
  203. DependsOnTargets="WV2WinRTMakeProjections">
  204. <ItemGroup>
  205. <_WV2WinRTFilesToBuild Remove="@(_WV2WinRTFilesToBuild)"/>
  206. <_WV2WinRTFilesToBuild Include="$(WebView2DispatchAdapterOutputDir)wv2winrt\*.cpp"/>
  207. <_WV2WinRTFilesToClean Include="$(WebView2DispatchAdapterOutputDir)wv2winrt\*.*"/>
  208. </ItemGroup>
  209. <ItemGroup>
  210. <ClCompile Include="@(_WV2WinRTFilesToBuild)">
  211. <ObjectFileName>$(IntDir)wv2winrt\</ObjectFileName>
  212. </ClCompile>
  213. <FileWrites Include="@(_WV2WinRTFilesToClean)" Condition="'$(WV2WinRTSkipMakeProjections)' != 'true'"/>
  214. </ItemGroup>
  215. <Message Text="GeneratedCppFiles: &#xA;@(_WV2WinRTFilesToBuild, '&#xA;')" Importance="$(WV2WinRTVerbosity)" />
  216. </Target>
  217. <ItemDefinitionGroup>
  218. <ClCompile>
  219. <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(WebView2DispatchAdapterOutputDir)</AdditionalIncludeDirectories>
  220. </ClCompile>
  221. </ItemDefinitionGroup>
  222. </Project>