﻿<?xml version="1.0" encoding="utf-8"?>
<Project
	xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="DownloadXQilla">
        <SetConsoleTitle
            Title="$(CONSOLE_TITLE) - DownloadXQilla" />
        <Message
            Condition="!Exists('$(MSBuildProjectDirectory)\_archives\$(XQILLA_SRC_TAR_GZ)')"
            Text="Downloading '$(XQILLA_URL)'." />
        <WebDownload
            Condition="!Exists('$(MSBuildProjectDirectory)\_archives\$(XQILLA_SRC_TAR_GZ)')"
            FileUri="$(XQILLA_URL)"
            FileName="$(MSBuildProjectDirectory)\_archives\$(XQILLA_SRC_TAR_GZ)"
            UseDefaultCredentials="True" />    
    </Target>
    <Target Name="ExtractXQilla">
        <SetConsoleTitle
            Title="$(CONSOLE_TITLE) - ExtractXQilla" />
        <ExtractWith7za
            Condition="!Exists('$(MSBuildProjectDirectory)\$(XQILLA_DIR)')"
            FileToExtract="$(MSBuildProjectDirectory)\_archives\$(XQILLA_SRC_TAR_GZ)" />
    </Target>
    <Target Name="PatchXQilla">
        <SetConsoleTitle
            Title="$(CONSOLE_TITLE) - PatchXQilla" />
        <Exec
            Condition="!Exists('$(MSBuildProjectDirectory)\$(XQILLA_DIR)\XQilla_patched')"
            Command="&quot;$(PATCH_EXE)&quot; -p1 -i &quot;$(MSBuildProjectDirectory)\patches\$(XQILLA_PATCH_FILE)&quot;"
            WorkingDirectory="$(MSBuildProjectDirectory)\$(XQILLA_DIR)" />
        <Touch
            AlwaysCreate='true'
            Files="$(MSBuildProjectDirectory)\$(XQILLA_DIR)\XQilla_patched" />
    </Target>
    <Target Name="BuildXQilla">
        <SetConsoleTitle
            Title="$(CONSOLE_TITLE) - BuildXQilla" />
        <MSBuild
            Projects="$(MSBuildProjectDirectory)\$(XQILLA_DIR)\Win32Projects\VC14+\XQilla.sln"
            Properties="Configuration=Release;Platform=Win32;VcpkgEnabled=false"/>
        <MSBuild
            Projects="$(MSBuildProjectDirectory)\$(XQILLA_DIR)\Win32Projects\VC14+\XQilla.sln"
            Properties="Configuration=Release;Platform=x64;VcpkgEnabled=false"/>
        <MSBuild
            Projects="$(MSBuildProjectDirectory)\$(XQILLA_DIR)\Win32Projects\VC14+\XQilla.sln"
            Properties="Configuration=Debug;Platform=Win32;VcpkgEnabled=false"/>
        <MSBuild
            Projects="$(MSBuildProjectDirectory)\$(XQILLA_DIR)\Win32Projects\VC14+\XQilla.sln"
            Properties="Configuration=Debug;Platform=x64;VcpkgEnabled=false"/>
    </Target>
    <Target Name="CopyXQilla">
        <ItemGroup>
            <XQILLA_BIN_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x64\Debug\*.dll" />
            <XQILLA_BIN_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x64\Debug\*.exe" />
            <XQILLA_BIN_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x64\Debug\*.pdb" />
            <XQILLA_BIN_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x64\Release\*.dll" />
            <XQILLA_BIN_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x64\Release\*.exe" />
            <XQILLA_BIN_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x64\Release\*.pdb" />
            <XQILLA_BIN_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x86\Debug\*.dll" />
            <XQILLA_BIN_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x86\Debug\*.exe" />
            <XQILLA_BIN_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x86\Debug\*.pdb" />
            <XQILLA_BIN_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x86\Release\*.dll" />
            <XQILLA_BIN_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x86\Release\*.exe" />
            <XQILLA_BIN_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x86\Release\*.pdb" />

            <XQILLA_DOCS_FILES
                Include="$(MSBuildProjectDirectory)\$(XQILLA_DIR)\ChangeLog" />
            <XQILLA_DOCS_FILES
                Include="$(MSBuildProjectDirectory)\$(XQILLA_DIR)\LICENSE" />
            <XQILLA_DOCS_FILES
                Include="$(MSBuildProjectDirectory)\$(XQILLA_DIR)\README" />
            <XQILLA_DOCS_FILES
                Include="$(MSBuildProjectDirectory)\$(XQILLA_DIR)\TODO" />
            <XQILLA_DOCS_FILES
                Include="$(MSBuildProjectDirectory)\$(XQILLA_DIR)\docs\**\*.html" />

            <XQILLA_INCLUDE_FILES
                Include="$(MSBuildProjectDirectory)\$(XQILLA_DIR)\include\**\*.h" />
            <XQILLA_INCLUDE_FILES
                Include="$(MSBuildProjectDirectory)\$(XQILLA_DIR)\include\**\*.hpp" />

            <XQILLA_LIB_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x64\Debug\*.lib" />
            <XQILLA_LIB_X64_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x64\Debug\*.pdb" />
            <XQILLA_LIB_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x64\Release\*.lib" />
            <XQILLA_LIB_X64_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x64\Release\*.pdb" />
            <XQILLA_LIB_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x86\Debug\*.lib" />
            <XQILLA_LIB_X86_DEBUG_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x86\Debug\*.pdb" />
            <XQILLA_LIB_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x86\Release\*.lib" />
            <XQILLA_LIB_X86_RELEASE_FILES
                Include="$(MSBuildProjectDirectory)\build\out\x86\Release\*.pdb" />
        </ItemGroup>
        <SetConsoleTitle
            Title="$(CONSOLE_TITLE) - CopyXQilla" />
        <MakeDir
            Condition="!Exists('$(COMMON_SDKS)\docs\XQilla')"
            Directories="$(COMMON_SDKS)\docs\XQilla" />
        <Copy
            SourceFiles="@(XQILLA_BIN_X64_DEBUG_FILES)"
            DestinationFolder="$(COMMON_SDKS)\bin\x64\Debug"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(XQILLA_BIN_X64_RELEASE_FILES)"
            DestinationFolder="$(COMMON_SDKS)\bin\x64\Release"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(XQILLA_BIN_X86_DEBUG_FILES)"
            DestinationFolder="$(COMMON_SDKS)\bin\x86\Debug"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(XQILLA_BIN_X86_RELEASE_FILES)"
            DestinationFolder="$(COMMON_SDKS)\bin\x86\Release"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(XQILLA_DOCS_FILES)"
            DestinationFolder="$(COMMON_SDKS)\docs\XQilla\%(RecursiveDir)"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(XQILLA_INCLUDE_FILES)"
            DestinationFolder="$(COMMON_SDKS)\include\%(RecursiveDir)"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(XQILLA_LIB_X64_DEBUG_FILES)"
            DestinationFolder="$(COMMON_SDKS)\lib\x64\Debug"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(XQILLA_LIB_X64_RELEASE_FILES)"
            DestinationFolder="$(COMMON_SDKS)\lib\x64\Release"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(XQILLA_LIB_X86_DEBUG_FILES)"
            DestinationFolder="$(COMMON_SDKS)\lib\x86\Debug"
            SkipUnchangedFiles="true" />
        <Copy
            SourceFiles="@(XQILLA_LIB_X86_RELEASE_FILES)"
            DestinationFolder="$(COMMON_SDKS)\lib\x86\Release"
            SkipUnchangedFiles="true" />
    </Target>
    <Target Name="CleanXQilla">
        <SetConsoleTitle
            Title="$(CONSOLE_TITLE) - CleanXQilla" />
        <RemoveDir
            Condition="Exists('$(MSBuildProjectDirectory)\build')"
            Directories="$(MSBuildProjectDirectory)\build" />
        <RemoveDir
            Condition="Exists('$(MSBuildProjectDirectory)\$(XQILLA_DIR)')"
            Directories="$(MSBuildProjectDirectory)\$(XQILLA_DIR)" />
    </Target>
    <Target Name="XQilla">
        <SetConsoleTitle
            Title="$(CONSOLE_TITLE) - XQilla" />
        <CallTarget
            Condition="!Exists('$(MSBuildProjectDirectory)\build_state\XQilla_build_successful')"
            Targets="DownloadXQilla;ExtractXQilla;PatchXQilla;BuildXQilla;CopyXQilla" />
        <Touch
            AlwaysCreate='true'
            Files="$(MSBuildProjectDirectory)\build_state\XQilla_build_successful" />
    </Target>
</Project>
