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

  <!-- Ensures that if this file changes it forces a rebuild -->
  <PropertyGroup>
    <MSBuildAllProjects>
      $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
    </MSBuildAllProjects>
  </PropertyGroup>

  <!-- default configuration -->
  <PropertyGroup>
    <Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
    <Platform Condition="'$(Platform)'==''">Win32</Platform>
  </PropertyGroup>
  
  <!-- for root paths -->
  <PropertyGroup>
    <BuildRoot>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.root))</BuildRoot>
    <TargetsPath>$(BuildRoot)\Build</TargetsPath>
    <OsVersion>$(registry:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion@CurrentVersion)</OsVersion>
    <!--If Dev11 and Dev12 are both installed, the default is to build Dev12. This can be overridden by setting the DevToolsVersion variable in powershell-->
	<DevToolsVersion Condition="'$(DevToolsVersion)' == '' And '$(VS140COMNTOOLS)' != ''">140</DevToolsVersion>
	<DevToolsVersion Condition="'$(DevToolsVersion)' == '' And '$(VS120COMNTOOLS)' != ''">120</DevToolsVersion>
    <DevToolsVersion Condition="'$(DevToolsVersion)' == '' And '$(VS110COMNTOOLS)' != ''">110</DevToolsVersion>
    <!-- ARM tools are installed in $(FrameworkSdkDir)\DesignTime\CommonConfiguration\Neutral\Windows.desktop.arm.props -->
    <FrameworkSdkDir Condition="'$(FrameworkSdkDir)'==''">$(WindowsSdkDir)</FrameworkSdkDir>
	<WindowsSDKDesktopARMSupport Condition="'$(DevToolsVersion)'=='120' AND Exists('$(FrameworkSdkDir)\DesignTime\CommonConfiguration\Neutral\Windows.desktop.arm.props')" >true</WindowsSDKDesktopARMSupport>
    <WindowsSDKDesktopARMSupport Condition="'$(DevToolsVersion)'=='110' AND Exists('$(FrameworkSdkDir)\DesignTime\CommonConfiguration\Neutral\Windows.desktop.arm.props')" >true</WindowsSDKDesktopARMSupport>
    <WindowsSDKDesktopARMSupport Condition="'$(DevToolsVersion)'=='110' AND !Exists('$(FrameworkSdkDir)\DesignTime\CommonConfiguration\Neutral\Windows.desktop.arm.props')">false</WindowsSDKDesktopARMSupport>
  </PropertyGroup>


  <!-- paths can be overridden by configuration -->
  <PropertyGroup>
    <OutputPath>$(BuildRoot)\Binaries\$(Platform)\$(Configuration)\</OutputPath>
    <OutDir>$(OutputPath)</OutDir>
    <IntDir>$(BuildRoot)\Intermediate\$(MSBuildProjectName)\$(Platform)\$(Configuration)\</IntDir>
    <TestRoot>$(BuildRoot)\Release\Tests</TestRoot>
    <CasablancaSrcDir>$(BuildRoot)\Release\src</CasablancaSrcDir>
    <CasablancaResourceDir>$(BuildRoot)\Release\Resource</CasablancaResourceDir>
    <CasablancaIncludeDir>$(BuildRoot)\Release\include</CasablancaIncludeDir>
    <WebsocketppIncludeDir>$(BuildRoot)\Release\libs\websocketpp</WebsocketppIncludeDir>
    <PackagesRoot Condition="'$(PackagesRoot)'=='' AND Exists('$(BuildRoot)\packages')">$(BuildRoot)\packages</PackagesRoot>
    <PackagesRoot Condition="'$(PackagesRoot)'=='' AND Exists('$(BuildRoot)\..\Tools\packages')">$(BuildRoot)\..\Tools\packages</PackagesRoot>
  </PropertyGroup>

  <!-- paths will not be overridden -->
  <PropertyGroup>
    <OutDir Condition="'$(OutDir)' != '' and !HasTrailingSlash('$(OutDir)')">$(OutDir)\</OutDir>
  </PropertyGroup>

  <PropertyGroup Condition="'$(DevToolsVersion)' == '110'">
    <DevEnvDir>$(VS110COMNTOOLS)..\IDE</DevEnvDir>
  </PropertyGroup>

  <PropertyGroup Condition="'$(DevToolsVersion)' == '120'">
    <DevEnvDir>$(VS120COMNTOOLS)..\IDE</DevEnvDir>
  </PropertyGroup>

  <PropertyGroup>
    <BinaryDependencies>$(TargetsPath)\BinaryDependencies</BinaryDependencies>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>

    <!--For C#:-->
    <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
    <!-- RunCodeAnalysis, false by default, is set true as necessary from the msbuild command line. -->
    <!-- This is normally done for the gated checkin build. -->
    <RunCodeAnalysis Condition="'$(RunCodeAnalysis)'==''">false</RunCodeAnalysis>
    <EnableCPPAnalysis Condition="'$(EnableCPPAnalysis)'==''">$(RunCodeAnalysis)</EnableCPPAnalysis>
    <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
    <!-- This is overridden in Release.Product.settings and Release.Tests.settings. -->
    <StyleCopEnabled Condition="'$(StyleCopEnabled)'==''">true</StyleCopEnabled>
    
    <!-- Set LinkIncremental, WholeProgramOptimization, unless they were already set in CodeCoverage.proj. -->
    <LinkIncremental Condition="'$(LinkIncremental)'=='' And '$(Configuration)'=='Debug'">true</LinkIncremental>
    <LinkIncremental Condition="'$(LinkIncremental)'=='' And '$(Configuration)'!='Debug'">false</LinkIncremental>
    <WholeProgramOptimization Condition="'$(WholeProgramOptimization)'=='' And '$(Configuration)'=='Debug'">false</WholeProgramOptimization>
    <WholeProgramOptimization Condition="'$(WholeProgramOptimization)'=='' And '$(Configuration)'!='Debug'">true</WholeProgramOptimization>
  </PropertyGroup>

  <ItemDefinitionGroup>
    <ClCompile>
      <WarningLevel>Level4</WarningLevel>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <TreatWarningAsError Condition="'$(TreatWarningsAsErrors)' != ''">true</TreatWarningAsError>
      <EnablePREfast>$(EnableCPPAnalysis)</EnablePREfast>
      <CompileAsManaged Condition="'$(CompileAsManagedDefault)' != ''">true</CompileAsManaged>
      <AdditionalOptions Condition="'$(DevToolsVersion)'=='140' And '$(ApplicationType)'!='Android'"> /d2notypeopt %(AdditionalOptions)</AdditionalOptions>
    </ClCompile>
    <ResourceCompile>
	  <AdditionalOptions>/DTARGET_NAME="$(TARGETNAME)" %(AdditionalOptions)</AdditionalOptions>
    </ResourceCompile>
  </ItemDefinitionGroup>

  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>

  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PreprocessorDefinitions>_WIN64;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>

  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
    <ClCompile>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>

  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <PreprocessorDefinitions>_WIN64;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>

  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
    <ClCompile>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>

  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|Win32' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <InstallerPlatform>x86</InstallerPlatform>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <DefineConstants>DEBUG;TRACE;X64</DefineConstants>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Win32' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <DefineConstants>TRACE</DefineConstants>
    <InstallerPlatform>x86</InstallerPlatform>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <DefineConstants>TRACE;X64</DefineConstants>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|ARM' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <DefineConstants>DEBUG;TRACE;ARM</DefineConstants>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|ARM' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <DefineConstants>TRACE;ARM</DefineConstants>
  </PropertyGroup>
  
  <!--end paths configuration -->
  <Target Name="CopyToOutputDirectoryAlwaysError"
         Condition="'@(Content)'!='' or '@(None)'!=''">
    <Error Condition="'%(Content.CopyToOutputDirectory)'=='Always'" Text="CopyToOutputDirectory is not allowed to be 'Always'.  Use 'PreserveNewest' instead." File="$(MSBuildProjectFile)" />
    <Error Condition="'%(None.CopyToOutputDirectory)'=='Always'" Text="CopyToOutputDirectory is not allowed to be 'Always'.  Use 'PreserveNewest' instead." File="$(MSBuildProjectFile)" />
  </Target>
  <!-- BEGIN: Workaround for MSBuild.exe bug that will be fixed in v4.5 -->
  <!-- Bug Symptom:  -->
  <!--    Multi-proc build returns "CSC : fatal error CS0009: Metadata file '(FilePath)' could not be opened == 'File is corrupt.' -->
  <!-- Bug Cause: -->
  <!--    "We are sharing the resultsbytargets dictionary between build results. -->
  <!--    We return build result A  but do some merging of results in build result B -->
  <!--    B is a copy of A sharing the same resultsbyTargets.  -->
  <!--    The merging of results into B causes extra target outputs to be put into A  -->
  <!--    and when we return A we see these extra results. -->
  <!-- Bug Workaround: -->
  <!--    Since items are bleeding across, they still have metadata we can use to differentiate them. -->  
  <!--    This error seems to be specific to items that have CopyToOutputDirectory -->
  <!--    defined (Content, None, etc.) that bleed into _ResolvedProjectReferencePaths.  -->
  <!--    So, we will remove items from _ResolvedProjectReferencePaths that have CopyToOutputDirectory defined.  -->
  <!--    There may be other places where the underlying bug manifests, but we have not encountered them.  -->

  <!-- Placeholder target since we're importing this into some non-c# projects as well. -->
  <Target Name="ResolveAssemblyReferences" />

  <!-- Define a default value so we can test items for the metadata without erroring -->
  <ItemDefinitionGroup>
    <_ResolvedProjectReferencePaths>
      <CopyToOutputDirectory>Undefined</CopyToOutputDirectory>
    </_ResolvedProjectReferencePaths>
  </ItemDefinitionGroup>

  <!-- Remove all items from _ResolvedProjectReferencePaths that have non-default value for CopyToOutputDirectory   -->
  <Target Name="Cleanup_ResolvedProjectReferencePaths"
     BeforeTargets="ResolveAssemblyReferences"
    Condition="'@(_ResolvedProjectReferencePaths)' != ''">
    <Message Text="Before Cleanup_ResolvedProjectReferencePaths (CopyToOutputDirectory = %(CopyToOutputDirectory)): @(_ResolvedProjectReferencePaths)"
             Importance="Low" />
    <ItemGroup>
      <_ResolvedProjectReferencePaths Condition="'%(CopyToOutputDirectory)' != 'Undefined'"
                                      Remove="@(_ResolvedProjectReferencePaths)" />
    </ItemGroup>
    <Message Text="After Cleanup_ResolvedProjectReferencePaths (CopyToOutputDirectory = %(CopyToOutputDirectory)): @(_ResolvedProjectReferencePaths)"
             Importance="Low" />
  </Target>
  <!-- END Workaround for MSBuild.exe bug that will be fixed in v4.5 -->

</Project>

