.ProjectName = 'JulietShaderCompiler'
.ProjectPath = 'JulietShaderCompiler'

// 1. Define the configurations and a container for the VS Project
.ShaderCompilerConfigs = { .X64DebugConfig, .X64ReleaseConfig }
.DXCSourcePath = '$ProjectPath$/DXShaderCompiler'

// 0. Single Unity generator target
Unity( '$ProjectName$-Unity' )
{
    .UnityInputPath             = '$ProjectPath$/'
    .UnityOutputPath            = 'Intermediate/$ProjectPath$/'
    .UnityOutputPattern         = '$ProjectName$_Unity*.cpp'
    .UnityMaxFiles              = 5
    .UnityPBRoot                = ''
}

ForEach( .BuildConfig in .ShaderCompilerConfigs )
{
    Using( .BuildConfig )
    .OutputBase + '\$Platform$-$BuildConfigName$'

    // 2. Define the Build Targets for this specific configuration
    ObjectList( '$ProjectName$-Obs-$Platform$-$BuildConfigName$' )
    {
        .CompilerInputUnity = '$ProjectName$-Unity'
        .CompilerOutputPath = '$OutputBase$/$ProjectPath$/'
        .CompilerOptions    + ' "-IJuliet/include"'
                            + ' "-IJulietShaderCompiler"'

        #if __WINDOWS__
            .CompilerOptions + ' -DJULIET_WIN32'
        #endif
    }

#if __WINDOWS__
    Copy( '$ProjectName$-CopyDeps-$Platform$-$BuildConfigName$' )
    {
        .Source = { 
                    '$DXCSourcePath$/dxcompiler.dll',
                    '$DXCSourcePath$/dxil.dll' 
                  }
        .Dest   = '$BinPath$/$Platform$-$BuildConfigName$/'
    }
#endif

    Executable( '$ProjectName$-Exe-$Platform$-$BuildConfigName$' )
    {
        .Libraries      = { 
                            'Juliet-Lib-$Platform$-$BuildConfigName$',
                            '$ProjectName$-Obs-$Platform$-$BuildConfigName$'
                          }
        
        .LinkerOutput               = '$BinPath$/$Platform$-$BuildConfigName$/$ProjectName$$ExeExtension$'

        #if __WINDOWS__

            .CRTLibs = .CRTLibs_Dynamic
            If ( .BuildConfigName == 'Debug' )
            {
                ^CRTLibs = .CRTLibs_DynamicDebug
            }
            .LinkerOptions               + .CRTLibs

            .LinkerOptions + .CommonWinLibs + ' dxcompiler.lib'
        #endif

        #if __WINDOWS__
            .PreBuildDependencies = { '$ProjectName$-CopyDeps-$Platform$-$BuildConfigName$' }
        #endif
    }

    Alias( '$ProjectName$-$Platform$-$BuildConfigName$' ) { .Targets = '$ProjectName$-Exe-$Platform$-$BuildConfigName$' }
    ^'Targets_$Platform$_$BuildConfigName$' + { '$ProjectName$-$Platform$-$BuildConfigName$' }

    #if __WINDOWS__
        .ConfigInfo = 
        [
            Using( .'Project_$Platform$_$BuildConfigName$' )

            .LocalDebuggerCommandArguments = '..\..\Assets\source\SolidColor.frag.hlsl -o ..\..\Assets\compiled\SolidColor.frag.dxil'

            .Target = '$ProjectName$-$Platform$-$BuildConfigName$'
        ]
        ^ProjectConfigs + .ConfigInfo
    #endif
}

// 4. Create the Project using the generated list
VCXProject( '$ProjectName$' )
{
    .ProjectOutput   = '$ProjectPath$/$ProjectName$.vcxproj'
    .ProjectBasePath = '$ProjectPath$/'
    .ProjectInputPaths = { .ProjectBasePath } 
    .ProjectConfigs  = .ProjectConfigs
}

// 5. Global Aliases
Alias( 'shader' )     { .Targets = { '$ProjectName$-x64Clang-Release' } }
Alias( 'shader-debug' )     { .Targets = { '$ProjectName$-x64Clang-Debug',  } }