﻿<!--
***********************************************************************************************
Microsoft.BuildSteps.targets

WARNING:  DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
          created a backup copy.  Incorrect changes to this file will make it
          impossible to load or build your projects from the command-line or the IDE.

This file defines the steps in the standard build process for C++ projects.  It
contains all the steps that are specific to building Visual C++ projects.

Copyright (C) Microsoft Corporation. All rights reserved.
***********************************************************************************************
-->

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <GenerateTargetFrameworkAttribute Condition="'$(CLRSupport)' == '' or '$(CLRSupport)' == 'false'">false</GenerateTargetFrameworkAttribute>
    <AssemblyName Condition="'$(CLRSupport)' == 'netcore' and '$(TargetName)' != ''">$(TargetName)</AssemblyName>

    <!-- By default we do not want to build project to project references if they are disabled in the solution configuration -->
    <OnlyReferenceAndBuildProjectsEnabledInSolutionConfiguration Condition="'$(OnlyReferenceAndBuildProjectsEnabledInSolutionConfiguration)' == ''">true</OnlyReferenceAndBuildProjectsEnabledInSolutionConfiguration>
    <_BuildActionType Condition="'$(_BuildActionType)' == ''">Build</_BuildActionType>
  </PropertyGroup>

  <!-- disable intermediate pdb copy to output dir by msbuild common targets, it should never be done for C++ build -->
  <PropertyGroup>
    <!-- avoid msbuild warning about not defined property -->
    <DebugType Condition="'$(DebugType)' == ''"></DebugType>
    <_DebugTypeOld>$(DebugType)</_DebugTypeOld>
    <DebugType>none</DebugType>
  </PropertyGroup>

  <Import Project="$(MSBuildToolsPath)\Microsoft.Common.Targets" />

  <PropertyGroup>
    <!-- Restore the property in case it is used by some extensons -->
    <DebugType>$(_DebugTypeOld)</DebugType>
  </PropertyGroup>

  <!--
    ============================================================
                                        GenerateTargetFrameworkMonikerAttribute

    Emit any specified code fragments into a temporary source file for the compiler.
    Overridden for C++ special care is needed when using precompiled headers.
    ============================================================
    -->

    <Target Name="GenerateTargetFrameworkMonikerAttribute"
            DependsOnTargets="PrepareForBuild;GetReferenceAssemblyPaths"
            Inputs="$(MSBuildThisFileFullPath)"
            Outputs="$(TargetFrameworkMonikerAssemblyAttributesPath)"
            Condition="'$(GenerateTargetFrameworkAttribute)' == 'true'">

        <PropertyGroup>
          <!-- This attribute is only available in mscorlib v4 and later -->
          <AdditionalSourcesText Condition="'$(GenerateTargetFrameworkAttribute)' == 'true' and '$(TargetingClr2Framework)' != 'true'">
            $(AdditionalSourcesText)
#using &lt;mscorlib.dll&gt;
[assembly: System::Runtime::Versioning::TargetFrameworkAttribute(L&quot;$(TargetFrameworkMoniker)&quot;, FrameworkDisplayName=L&quot;$(TargetFrameworkMonikerDisplayName)&quot;)]%3b
          </AdditionalSourcesText>
        </PropertyGroup>

        <!-- This is a file shared between projects so we have to take care to handle simultaneous writes (by ContinueOnError)
             and a race between clean from one project and build from another (by not adding to FilesWritten so it doesn't clean) -->
        <WriteLinesToFile
            File="$(TargetFrameworkMonikerAssemblyAttributesPath)"
            Lines="$(AdditionalSourcesText)"
            Condition="'$(AdditionalSourcesText)' != ''"
            ContinueOnError="true"
            Overwrite="true"/>

        <ItemGroup>
           <ClCompile Include="$(TargetFrameworkMonikerAssemblyAttributesPath)" Condition="'@(ClCompile)' != '' and '$(AdditionalSourcesText)' != ''">
              <!-- Since we didn't emit any necessary #include "stdafx.h" or similar -->
              <PrecompiledHeader>NotUsing</PrecompiledHeader>
              <!-- Cleanup ForcedIncludeFiles as PrecompiledHeader might be using /FI and we don't want to pick up any random temp files -->
              <ForcedIncludeFiles></ForcedIncludeFiles>
              <!-- The appropriate CompileAsManaged setting will automatically be set depending on the current CLRSupport value -->
             <IncludeInUnityFile>false</IncludeInUnityFile>
           </ClCompile>
        </ItemGroup>

    </Target>

  <PropertyGroup>
    <ComputeCompileInputsTargets>
      $(ComputeCompileInputsTargets);
      GenerateTargetFrameworkMonikerAttribute;
    </ComputeCompileInputsTargets>
  </PropertyGroup>

  <!-- CPP build is done in 3 steps:
          1. Generate sources (BuildGenerateSources)
          2. Compile          (BuildCompile)
          3. Link             (BuildLink)
       Each step can be executed separately. Populate BuildSteps with one or more steps
       before importing this project to build only particular steps. -->
  <PropertyGroup>
    <EnableBuildPassesInParallel Condition="'$(EnableBuildPassesInParallel)' == '' and ('$(BuildPassReferences)' == 'true' or '$(AllowParallelCompileInReferencedProjects)' == 'true')">true</EnableBuildPassesInParallel>
    <!-- Due to circular dependency, "Build" target can't depend on "BuildGenerateSources;BuildCompile;BuildLink". -->
    <BuildSteps Condition="'$(BuildSteps)' == '' and '$(EnableBuildPassesInParallel)' == 'true'">
      ResolveReferences;
      PrepareForBuild;
      InitializeBuildStatus;
      _BuildGenerateSourcesAction;
      _BuildCompileAction;
      _BuildLinkAction;
    </BuildSteps>

    <BuildSteps Condition="'$(BuildSteps)' == ''">
      ResolveReferences;
      PrepareForBuild;
      InitializeBuildStatus;
      BuildGenerateSources;
      BuildCompile;
      BuildLink;
    </BuildSteps>

    <BuildDependsOn>
      _PrepareForBuild;
      $(BuildSteps);
      AfterBuild;
      IncrementalClean;
      TlogCleanup;
      FinalizeBuildStatus;
    </BuildDependsOn>

    <RebuildDependsOn>
      _PrepareForRebuild;
      $(RebuildDependsOn);
    </RebuildDependsOn>

    <CleanDependsOn>
      _PrepareForClean;
      $(CleanDependsOn);
    </CleanDependsOn>
  </PropertyGroup>

  <Target
      Name="Build"
      Condition=" '$(_InvalidConfigurationWarning)' != 'true' "
      DependsOnTargets="$(BuildDependsOn)"
      Returns="@(ManagedTargetPath);@(WinMDFullPath)" >
    <ItemGroup>
      <ManagedTargetPath Include="$(TargetPath)" Condition="'$(ManagedAssembly)' == 'true' and '$(ConfigurationType)' != 'StaticLibrary'" />
    </ItemGroup>
  </Target>

  <Target
      Name="Rebuild"
      Condition=" '$(_InvalidConfigurationWarning)' != 'true' "
      DependsOnTargets="$(RebuildDependsOn)"
      Returns="@(ManagedTargetPath);@(WinMDFullPath)">
    <ItemGroup>
      <ManagedTargetPath Include="$(TargetPath)" Condition="'$(ManagedAssembly)' == 'true' and '$(ConfigurationType)' != 'StaticLibrary'" />
    </ItemGroup>
  </Target>

  <Target Name="_PrepareForBuild" >
    <PropertyGroup>
      <BuildType Condition="'$(BuildType)' == ''">Build</BuildType>
      <_BuildActionType>Build</_BuildActionType>
    </PropertyGroup>

    <ItemGroup>
       <CustomBuild Condition="'%(CustomBuild.ExcludedFromBuild)'!='true' and '%(CustomBuild.IncludeFileToTool)'==''and '%(CustomBuild.LinkObjects)'=='true' and ('%(Extension)'=='.obj' or '%(Extension)'=='.res' or '%(Extension)'=='.rsc' or '%(Extension)'=='.lib')">
        <IncludeFileToTool Condition="'$(ConfigurationType)'=='StaticLibrary'">Lib</IncludeFileToTool>
        <IncludeFileToTool Condition="'$(ConfigurationType)'!='StaticLibrary'">Link</IncludeFileToTool>
      </CustomBuild>
    </ItemGroup>

    <!-- Add CustomBuild inputs to lib, link, or other tools. -->
    <CreateItem
        Include="@(CustomBuild)"
        Condition="'%(CustomBuild.IncludeFileToTool)'!=''">
       <Output
           TaskParameter="Include"
           ItemName="%(CustomBuild.IncludeFileToTool)"/>
    </CreateItem>

    <ItemGroup>
    <!-- Remove CustomBuild ItemGroup that doesn't meet the condition. This prevents showing "Skipping target "CustomBuild" because it has no outputs. -->
      <CustomBuildStep Remove="@(CustomBuildStep)" Condition="'%(CustomBuildStep.Command)' == ''" />
      <CustomBuild Remove="@(CustomBuild)" Condition="'%(CustomBuild.Command)' == '' or '%(CustomBuild.ExcludedFromBuild)'=='true'" />
    </ItemGroup>
  </Target>

  <Target Name="_PrepareForRebuild">
    <PropertyGroup>
      <BuildType Condition="'$(BuildType)' == ''">Rebuild</BuildType>
      <_BuildActionType>Rebuild</_BuildActionType>
      <_ClCompileGenerateXMLDocumentationFiles Condition="%(ClCompile.GenerateXMLDocumentationFiles) == 'true'">true</_ClCompileGenerateXMLDocumentationFiles>
    </PropertyGroup>

    <ItemGroup>
      <CustomBuildStep Remove="@(CustomBuildStep)" Condition="'%(CustomBuildStep.Command)' == ''" />
      <CustomBuild Remove="@(CustomBuild)" Condition="'%(CustomBuild.Command)' == '' or '%(CustomBuild.ExcludedFromBuild)'=='true'" />
    </ItemGroup>
  </Target>

  <Target Name="_PrepareForClean">
    <PropertyGroup>
      <BuildType Condition="'$(BuildType)' == ''">Clean</BuildType>
      <_BuildActionType>Clean</_BuildActionType>
    </PropertyGroup>
    <Delete Files="$(LastBuildState)" Condition="Exists($(LastBuildState))"/>
  </Target>

  <Target Name="AfterBuild">
  </Target>

  <PropertyGroup>
    <!-- TLogLocation requires trailing slash. -->
    <_TLogProjectName>$(ProjectName)</_TLogProjectName>
    <_TLogProjectName Condition="'$(ProjectName)' != '' and '$(ProjectGuid)' != '' and '$(ProjectName.Length)' &gt; '16'">$(ProjectName.Substring(0,8)).$(ProjectGuid.Substring(1,8))</_TLogProjectName>
    <TLogLocation Condition="'$(TLogLocation)' == ''">$(IntDir)$(_TLogProjectName).tlog\</TLogLocation>
    <TLogLocation_ModuleDependencies Condition="'$(TLogLocation_ModuleDependencies)' == ''">$(IntDir)$(_TLogProjectName)_MD.tlog\</TLogLocation_ModuleDependencies>
    <LastBuildUnsuccessful>$(TLogLocation)unsuccessfulbuild</LastBuildUnsuccessful>
    <LastBuildState>$(TLogLocation)$(ProjectName).lastbuildstate</LastBuildState>
  </PropertyGroup>


  <!-- *******************************************************************************************
        BeforeBuildGenerateSources
       ******************************************************************************************* -->
  <!-- Redefine this target in your project in order to run tasks just before BuildGenerateSources -->
  <Target Name="BeforeBuildGenerateSources"/>

  <PropertyGroup>
    <BeforeBuildGenerateSourcesTargets>
      $(BeforeBuildGenerateSourcesTargets);
      BeforeBuildGenerateSources;
    </BeforeBuildGenerateSourcesTargets>

    <AfterBuildGenerateSourcesTargets>
      $(AfterBuildGenerateSourcesTargets);
      AfterBuildGenerateSources;
    </AfterBuildGenerateSourcesTargets>
  </PropertyGroup>

  <!-- *******************************************************************************************
        AfterBuildGenerateSources
       ******************************************************************************************* -->
  <!-- Redefine this target in your project in order to run tasks just after BuildGenerateSources -->
  <Target Name="AfterBuildGenerateSources"/>

  <!-- *******************************************************************************************
        BeforeBuildCompile
       ******************************************************************************************* -->
  <!-- Redefine this target in your project in order to run tasks just before BuildCompile -->
  <Target Name="BeforeBuildCompile"/>

  <!-- *******************************************************************************************
        AfterBuildCompile
       ******************************************************************************************* -->
  <!-- Redefine this target in your project in order to run tasks just after BuildCompile -->
  <Target Name="AfterBuildCompile"/>

  <Target Name="LibLinkOnly"
          DependsOnTargets="$(CommonBuildOnlyTargets)$(BeforeBuildLinkTargets);$(BuildLibTargets);$(BuildLinkTargets);$(AfterBuildLinkTargets)">
  </Target>

  <!-- *******************************************************************************************
          Utility targets to get files from project from another project using the MSBuild task
       ******************************************************************************************* -->
  <Target Name="GetClCompile" Returns="@(ClCompile)"/>
  <Target Name="GetResourceCompile" Returns="@(ResourceCompile)"/>
  <Target Name="GetMidl" Returns="@(Midl)"/>
  <Target Name="GetImpLib" Returns="@(ImpLib)"/>
  <Target Name="GetLib" Returns="@(Lib)"/>
  <Target Name="GetLink" Returns="@(Link)"/>
  <Target Name="GetCustomBuild" Returns="@(CustomBuild)"/>
  <Target Name="GetXsd" Returns="@(Xsd)"/>
  <Target Name="GetXdcMake" Returns="@(XdcMake)"/>
  <Target Name="GetBscMake" Returns="@(BscMake)"/>

</Project>
