<?xml version="1.0" encoding="utf-8"?>
<!--
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt VS Tools.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup
    Condition="'$(QtInnerBuild)' == ''">
    <!--// Outer build: invoke inner build -->
    <BuildDependsOn>
      $(QtOuterBuildPrepare);
      QtOuterBuild;
      $(QtOuterBuildFinalize)
    </BuildDependsOn>
    <QtInnerBuild>$(MSBuildProjectFullPath)</QtInnerBuild>
    <RandomFileName>$([System.IO.Path]::GetRandomFileName())</RandomFileName>
  </PropertyGroup>

  <PropertyGroup
    Condition="'$(QtInnerBuild)' != '$(MSBuildProjectFullPath)'">
    <!--// Dependent project inner build: skip build -->
    <BuildDependsOn>$(QtOuterBuildPrepare);$(QtOuterBuildFinalize)</BuildDependsOn>
  </PropertyGroup>

  <!--
  /////////////////////////////////////////////////////////////////////////////////////////////////
  /// TARGET QtOuterBuild
  /////////////////////////////////////////////////////////////////////////////////////////////////
  // Run targets in $(QtOuterBuildDependsOn) and then recursively invoke build
  // -->
  <Target Name="QtOuterBuild" DependsOnTargets="$(QtOuterBuildDependsOn)">
    <!--// Invoke inner build: recursive build in second MSBuild instance -->
    <MSBuild
      Projects="$(MSBuildProjectFullPath)"
      Targets="Build"
      Properties="QtInnerBuild=$(MSBuildProjectFullPath);RandomFileName=$(RandomFileName);BuildProjectReferences=false">
    </MSBuild>
    <OnError ExecuteTargets="QtLeaveCriticalSection_OnError"/>
  </Target>

  <!--
  /////////////////////////////////////////////////////////////////////////////////////////////////
  /// TARGET GetClCommandLineForReference
  /////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // -->
  <Target
    Name="GetClCommandLineForReference"
    DependsOnTargets="$(QtOuterBuildDependsOn)"
    Returns="@(ClCommandLineForReference)">
    <MSBuild
      Projects="$(MSBuildProjectFullPath)"
      Targets="GetClCommandLineForReference"
      Properties="QtInnerBuild=$(MSBuildProjectFullPath);RandomFileName=$(RandomFileName);BuildProjectReferences=false">
      <Output TaskParameter="TargetOutputs" ItemName="ClCommandLineForReference"/>
    </MSBuild>
  </Target>

  <!--
  /////////////////////////////////////////////////////////////////////////////////////////////////
  /// TARGET GetGeneratedFiles
  /////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // -->
  <Target
    Name="GetGeneratedFiles"
    DependsOnTargets="$(QtOuterBuildDependsOn)"
    Returns="@(_GeneratedFiles)">
    <MSBuild
      Projects="$(MSBuildProjectFullPath)"
      Targets="GetGeneratedFiles"
      Properties="QtInnerBuild=$(MSBuildProjectFullPath);RandomFileName=$(RandomFileName);BuildProjectReferences=false">
      <Output TaskParameter="TargetOutputs" ItemName="_GeneratedFiles"/>
    </MSBuild>
  </Target>

  <!--
  /////////////////////////////////////////////////////////////////////////////////////////////////
  /// TARGET GetProjectReferencesInfo
  /////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // -->
  <Target
    Name="GetProjectReferencesInfo"
    DependsOnTargets="$(QtOuterBuildDependsOn)"
    Returns="@(_ProjectReferencesInfo)">
    <MSBuild
      Projects="$(MSBuildProjectFullPath)"
      Targets="GetProjectReferencesInfo"
      Properties="QtInnerBuild=$(MSBuildProjectFullPath);RandomFileName=$(RandomFileName);BuildProjectReferences=false">
      <Output TaskParameter="TargetOutputs" ItemName="_ProjectReferencesInfo"/>
    </MSBuild>
  </Target>

  <!--
  /////////////////////////////////////////////////////////////////////////////////////////////////
  /// TARGET GetClCommandLines
  /////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // -->
  <Target
    Name="GetClCommandLines"
    DependsOnTargets="$(QtOuterBuildDependsOn)"
    Returns="@(ClCommandLines)">
    <MSBuild
      Projects="$(MSBuildProjectFullPath)"
      Targets="GetClCommandLines"
      Properties="QtInnerBuild=$(MSBuildProjectFullPath);RandomFileName=$(RandomFileName);BuildProjectReferences=false">
      <Output TaskParameter="TargetOutputs" ItemName="ClCommandLines"/>
    </MSBuild>
  </Target>
</Project>
