<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- Variant support. For compatibility with how it works for the other ports, this gets imported
       early so variants cannot override build options like the ones specified in the rest of this file.
       Use CustomPropsFile (see the .vcxproj file) for that. -->
  <PropertyGroup Condition="'$(PyBuildingMpyCross)' != 'True'">
    <PyVariant Condition="'$(PyVariant)' == ''">standard</PyVariant>
    <PyBuild Condition="'$(PyBuild)' == ''">build-$(PyVariant)</PyBuild>
    <PyProg Condition="'$(PyProg)' == ''">micropython</PyProg>
  </PropertyGroup>
  <ImportGroup Label="PropertySheets">
    <Import Project="paths.props" Condition="'$(PyPathsIncluded)' != 'True'"/>
    <Import Condition="'$(PyBuildingMpyCross)' != 'True'" Project="$(PyVariantDir)mpconfigvariant.props"/>
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup>
    <OutDir>$(PyOutDir)</OutDir>
    <IntDir>$(PyIntDir)</IntDir>
    <PyFileCopyCookie>$(PyBuildDir)copycookie$(Configuration)$(Platform)</PyFileCopyCookie>
    <CharacterSet>MultiByte</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(PyBuildingMpyCross)' != 'True'">
    <PyIncDirs>$(PyIncDirs);$(PyVariantDir)</PyIncDirs>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <ClCompile>
      <AdditionalIncludeDirectories>$(PyIncDirs);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <PreprocessorDefinitions>_USE_MATH_DEFINES;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PreprocessorDefinitions Condition="'$(FrozenManifest)' != ''">MICROPY_MODULE_FROZEN_MPY=1;MICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool;MPZ_DIG_SIZE=16;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <SDLCheck>false</SDLCheck>
      <WarningLevel>Level1</WarningLevel>
      <ExceptionHandling>false</ExceptionHandling>
      <MultiProcessorCompilation>true</MultiProcessorCompilation>
      <MinimalRebuild>false</MinimalRebuild>
      <TreatWarningAsError>true</TreatWarningAsError>
    </ClCompile>
    <Link>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <GenerateMapFile>true</GenerateMapFile>
      <AdditionalDependencies>Bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <PyOutputFiles Include="$(TargetPath)">
      <Destination>$(PyTargetDir)%(FileName)%(Extension)</Destination>
    </PyOutputFiles>
    <PyCookieFiles Include="$(PyBuildDir)copycookie*" Exclude="$(PyFileCopyCookie)"/>
    <QstrDependencies Include="$(PyVariantDir)mpconfigvariant.h"/>
  </ItemGroup>

  <!-- Helper for getting resulting executable path since it depends on other properties. -->
  <Target Name="ShowTargetPath">
    <Message Text="$(TargetPath)" Importance="high"/>
  </Target>

  <!-- Copy PyOutputFiles to their target destination.
       To force this when switching between platforms/configurations which are already up-to-date (and as such,
       for which a build wouldn't even start because all outputs are effectively newer than the inputs)
       an empty file $(PyFileCopyCookie) is created serving as a record to indicate what was last copied,
       and any previous records are deleted. So when switching between builds which are otherwise up-to-date
       the tracker will notice a missing file and a build is started anyway (and it will just copy our files). -->
  <Target Name="CopyFilesToWinDir" AfterTargets="Build"
          Inputs="$(TargetPath)" Outputs="$(PyFileCopyCookie);@(PyOutputFiles->'%(Destination)')">
    <Delete Files="@(PyCookieFiles)"/>
    <Touch Files="$(PyFileCopyCookie)" AlwaysCreate="true"/>
    <Copy SourceFiles="%(PyOutputFiles.Identity)" DestinationFiles="%(PyOutputFiles.Destination)"/>
    <WriteLinesToFile File="$(TLogLocation)$(ProjectName).write.u.tlog" Lines="$(PyFileCopyCookie);@(PyOutputFiles->'%(Destination)')" Overwrite="True"/>
  </Target>
</Project>
