<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup Label="Globals">
    <ProjectGuid>{CA5CAD1A-1754-4A9D-93D7-857A9D17CB1B}</ProjectGuid>
    <Keyword>Win32Proj</Keyword>
    <RootNamespace>WindowsTerminal</RootNamespace>
    <ProjectName>WindowsTerminal</ProjectName>
    <TargetName>WindowsTerminal</TargetName>
    <ConfigurationType>Application</ConfigurationType>
    <OpenConsoleUniversalApp>false</OpenConsoleUniversalApp>
    <ApplicationType>Windows Store</ApplicationType>
    <WindowsStoreApp>true</WindowsStoreApp>
    <WindowsAppContainer>false</WindowsAppContainer>
    <TargetPlatformIdentifier>Windows</TargetPlatformIdentifier>
    <VersionInfoFileDescription>Windows Terminal Host</VersionInfoFileDescription>
    <PgoTarget>true</PgoTarget>
  </PropertyGroup>

  <PropertyGroup Label="NuGet Dependencies">
    <TerminalCppWinrt>true</TerminalCppWinrt>
    <TerminalThemeHelpers>true</TerminalThemeHelpers>
    <TerminalMUX>true</TerminalMUX>
    <TerminalWinGetInterop>true</TerminalWinGetInterop>
  </PropertyGroup>

  <Import Project="..\..\..\common.openconsole.props" Condition="'$(OpenConsoleDir)'==''" />
  <Import Project="$(OpenConsoleDir)src\common.nugetversions.props" />
  <Import Project="$(OpenConsoleDir)src\cppwinrt.build.pre.props" />

  <ItemDefinitionGroup>
    <ClCompile>
      <SDLCheck>true</SDLCheck>
    </ClCompile>
  </ItemDefinitionGroup>

  <ItemDefinitionGroup>
    <ClCompile>
      <AdditionalIncludeDirectories>$(OpenConsoleDir)\src\inc;$(OpenConsoleDir)\dep;$(OpenConsoleDir)\dep\Console;$(OpenConsoleDir)\dep\Win32K;$(OpenConsoleDir)\dep\gsl\include;%(AdditionalIncludeDirectories);</AdditionalIncludeDirectories>
    </ClCompile>
    <Link>
      <AdditionalDependencies>gdi32.lib;dwmapi.lib;Shcore.lib;UxTheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <PropertyGroup>
    <GenerateManifest>true</GenerateManifest>
    <EmbedManifest>true</EmbedManifest>
  </PropertyGroup>
  <!-- Source Files -->
  <ItemGroup>
    <ClInclude Include="pch.h" />
    <ClInclude Include="resource.h" />
    <ClInclude Include="AppHost.h" />
    <ClInclude Include="BaseWindow.h" />
    <ClInclude Include="IslandWindow.h" />
    <ClInclude Include="NonClientIslandWindow.h" />
    <ClInclude Include="VirtualDesktopUtils.h" />
    <ClInclude Include="WindowEmperor.h" />
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="pch.cpp">
      <PrecompiledHeader>Create</PrecompiledHeader>
    </ClCompile>
    <ClCompile Include="main.cpp" />
    <ClCompile Include="AppHost.cpp" />
    <ClCompile Include="IslandWindow.cpp" />
    <ClCompile Include="NonClientIslandWindow.cpp" />
    <ClCompile Include="VirtualDesktopUtils.cpp" />
    <ClCompile Include="WindowEmperor.cpp" />
    <ClCompile Include="icon.cpp" />
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="WindowsTerminal.rc" />
  </ItemGroup>
  <ItemGroup>
    <Manifest Include="WindowsTerminal.manifest" />
  </ItemGroup>
  <!-- Dependencies -->
  <ItemGroup>
    <!-- Even though we do have proper recursive dependencies, we want to keep some of these here
         so that the AppX Manifest contains their activatable classes. -->
    <ProjectReference Include="$(OpenConsoleDir)src\cascadia\TerminalControl\dll\TerminalControl.vcxproj" />
    <ProjectReference Include="$(OpenConsoleDir)src\cascadia\TerminalConnection\TerminalConnection.vcxproj" />
    <ProjectReference Include="$(OpenConsoleDir)src\cascadia\TerminalSettingsModel\dll\Microsoft.Terminal.Settings.Model.vcxproj" />
    <ProjectReference Include="$(OpenConsoleDir)src\cascadia\UIHelpers\UIHelpers.vcxproj" />
    <ProjectReference Include="$(OpenConsoleDir)src\cascadia\TerminalApp\dll\TerminalApp.vcxproj" />
    <ProjectReference Include="$(OpenConsoleDir)src\cascadia\TerminalSettingsEditor\Microsoft.Terminal.Settings.Editor.vcxproj" />
    <ProjectReference Include="$(OpenConsoleDir)src\cascadia\UIMarkdown\UIMarkdown.vcxproj" />
    <ProjectReference Include="$(OpenConsoleDir)src\types\lib\types.vcxproj" />
    <ProjectReference Include="$(OpenConsoleDir)src\cascadia\WinRTUtils\WinRTUtils.vcxproj">
      <Project>{CA5CAD1A-039A-4929-BA2A-8BEB2E4106FE}</Project>
      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
    </ProjectReference>
  </ItemGroup>

  <!-- Manually add a reference to Core here. We need this so MDMERGE will know
  where the Core types are defined. However, we need to do it exactly like this,
  because the Core project is a lib not a dll, so it can't be ProjectReference'd
  like everything else. It does get built into TerminalControl.dll, so we don't
  need to worry about that. -->
  <ItemGroup>
    <Reference Include="Microsoft.Terminal.Core">
      <HintPath>$(OpenConsoleCommonOutDir)TerminalCore\Microsoft.Terminal.Core.winmd</HintPath>
      <IsWinMDFile>true</IsWinMDFile>
      <Private>false</Private>
      <CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
    </Reference>
  </ItemGroup>
  <!--
    This ItemGroup and the Globals PropertyGroup below it are required in order
    to enable F5 debugging for the unpackaged application
    -->
  <ItemGroup>
    <PropertyPageSchema Include="$(VCTargetsPath)$(LangID)\debugger_general.xml" />
    <PropertyPageSchema Include="$(VCTargetsPath)$(LangID)\debugger_local_windows.xml" />
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
  </PropertyGroup>

  <!--
  BODGY

  The wapproj `GetResolvedWinMD` target tries to get a winmd from every cppwinrt
  executable we put in the package. But we DON'T produce a winmd. This makes the
  FastUpToDate check fail every time, and leads to the whole wapproj build
  running even if you're just f5'ing the package. EVEN AFTER A SUCCESSFUL BUILD.

  Setting GenerateWindowsMetadata=false is enough to tell the build system that
  we don't produce one, and get it off our backs.
  -->
  <ItemDefinitionGroup>
    <Link>
      <GenerateWindowsMetadata>false</GenerateWindowsMetadata>
    </Link>
  </ItemDefinitionGroup>

  <Import Project="$(OpenConsoleDir)src\cppwinrt.build.post.props" />

  <!-- Override GetPackagingOutputs to roll up all our dependencies.
       This ensures that when the WAP packaging project asks what files go into
       the package, we tell it.
       This is a heavily stripped version of the one in Microsoft.*.AppxPackage.targets.
  -->
  <PropertyGroup>
    <_ContinueOnError Condition="'$(BuildingProject)' == 'true'">true</_ContinueOnError>
    <_ContinueOnError Condition="'$(BuildingProject)' != 'true'">false</_ContinueOnError>
  </PropertyGroup>
  <Target Name="GetPackagingOutputs" Returns="@(PackagingOutputs)">
    <MSBuild
      Projects="@(ProjectReferenceWithConfiguration)"
      Targets="GetPackagingOutputs"
      BuildInParallel="$(BuildInParallel)"
      Properties="%(ProjectReferenceWithConfiguration.SetConfiguration); %(ProjectReferenceWithConfiguration.SetPlatform)"
      Condition="'@(ProjectReferenceWithConfiguration)' != ''
                 and '%(ProjectReferenceWithConfiguration.BuildReference)' == 'true'
                 and '%(ProjectReferenceWithConfiguration.ReferenceOutputAssembly)' == 'true'"
      ContinueOnError="$(_ContinueOnError)">
      <Output TaskParameter="TargetOutputs" ItemName="_PackagingOutputsFromOtherProjects"/>
    </MSBuild>

    <ItemGroup>
      <PackagingOutputs Include="@(_PackagingOutputsFromOtherProjects)" />
    </ItemGroup>

  </Target>

  <PropertyGroup>
    <PrepareForRunDependsOn Condition="'$(BuildingInsideVisualStudio)'=='true'">_WTPrepareUnpackagedLayoutForRun;$(PrepareForRunDependsOn)</PrepareForRunDependsOn>
  </PropertyGroup>

  <ItemGroup>
    <WTFullXamlAssets Include="$(OutDir)\_xaml\resources.pri" />
    <WTFullXamlAssets Include="$(OutDir)\_xaml\Microsoft.UI.Xaml.dll" />
  </ItemGroup>
  <Target Name="_GetFullFatXamlAssets" Inputs="@(AppxPackageRegistration)" Outputs="@(WTFullXamlAssets)">
    <ItemGroup>
      <CurrentXamlPackage Include="@(AppxPackageRegistration)"
        Condition="'%(AppxPackageRegistration.Architecture)'=='$(Platform)' AND
        $([System.String]::new('%(AppxPackageRegistration.Filename)').StartsWith('Microsoft.UI.Xaml'))" />
    </ItemGroup>
    <MakeDir Directories="$(OutDir)\_xaml" />
    <Exec Command="tar.exe -x -C &quot;$(OutDir)\_xaml&quot; -f &quot;@(CurrentXamlPackage)&quot;" />
  </Target>
  <Target Name="_WTCalculateUnpackagedRunFiles" DependsOnTargets="CopyFilesToOutputDirectory;_GetFullFatXamlAssets">
    <CallTarget Targets="GetPackagingOutputs">
      <Output TaskParameter="TargetOutputs" ItemName="WTPackagingOutputsFromDependencyProjects" />
    </CallTarget>
    <ItemGroup>
      <DependencyPriFiles Include="@(WTPackagingOutputsFromDependencyProjects->Distinct())" Condition="'%(WTPackagingOutputsFromDependencyProjects.Extension)'=='.pri' and '%(WTPackagingOutputsFromDependencyProjects.Filename)'!='Microsoft.UI.Xaml'"/>
      <DependencyPriFiles Include="@(WTFullXamlAssets)" Condition="'%(WTFullXamlAssets.Extension)'=='.pri'" />
      <DependencyExecutables Include="@(WTFullXamlAssets)" Condition="'%(WTFullXamlAssets.Extension)'=='.dll'" />
      <DependencyExecutables Include="$(OutDir)\..\OpenConsole.exe" />
    </ItemGroup>
  </Target>
  <Target Name="_WTPrepareUnpackagedLayoutForRun" Inputs="@(DependencyPriFiles);@(DependencyExecutables)" Outputs="$(OutDir)\stamp" DependsOnTargets="_WTCalculateUnpackagedRunFiles">
    <Copy SourceFiles="@(DependencyExecutables)" DestinationFolder="$(OutDir)" UseHardlinksIfPossible="true" SkipUnchangedFiles="true" />
    <Exec Command="pwsh.exe -noprofile -c &quot;$(OpenConsoleDir)\build\scripts\Merge-PriFiles.ps1&quot; -Path &quot;@(DependencyPriFiles, '&quot;, &quot;')&quot; -OutputPath &quot;$(OutDir)resources.pri&quot;" />
    <Touch Files="$(OutDir)\stamp" AlwaysCreate="true" />
  </Target>

  <Import Project="$(OpenConsoleDir)\build\rules\GenerateSxsManifestsFromWinmds.targets" />
  <Import Project="$(OpenConsoleDir)src\common.nugetversions.targets" />

</Project>
