// ------------------------------------------------
// Copyright Joe Marshall 2024- All Rights Reserved
// ------------------------------------------------
//
// Build AndroidVulkanVideo module
// ------------------------------------------------

using UnrealBuildTool;
using System.IO;
using System;

public class AndroidVulkanVideo : ModuleRules
{
	public AndroidVulkanVideo(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
		CppStandard = CppStandardVersion.Cpp17;


		PublicIncludePaths.AddRange(
			new string[] {
				// ... add public include paths required here ...
			}
			);


		PrivateIncludePaths.AddRange(
			new string[] {
				// ... add other private include paths required here ...
			}
			);


		PublicDependencyModuleNames.AddRange(
			new string[]
			{
				"Core",
				"Projects"
				// ... add other public dependencies that you statically link with here ...
			}
			);


		PrivateDependencyModuleNames.AddRange(
			new string[]
			{
				"CoreUObject", "Engine","RHI","VulkanRHI","AudioExtensions","MediaUtils"
				// ... add private dependencies that you statically link with here ...	
			}
			);


		DynamicallyLoadedModuleNames.AddRange(
			new string[]
			{
				"Media"
			}
			);

		PrivateIncludePathModuleNames.AddRange(
			new string[] {
					"Media","MediaUtils"
			});

		if (Target.Platform == UnrealTargetPlatform.Android)
		{
			PrivateDependencyModuleNames.AddRange(new string[] { "Launch" });
			// AdditionalPropertiesForReceipt.Add("AndroidPlugin", Path.Combine(ModuleDirectory, "Copy_Lib_Android.xml"));
			AddEngineThirdPartyPrivateStaticDependencies(Target, "Vulkan");
			PublicSystemLibraries.Add("libmediandk");
			string overridelib_src_path = Path.GetFullPath("../overridelib/BuildOverrideLib.xml", ModuleDirectory);
			string overridelib_built_path = Path.GetFullPath("./overridelib_built/InstallOverrideLib.xml",ModuleDirectory);
			if(File.Exists(overridelib_src_path)){
				// build vulkan override layer from scratch if we have code
				AdditionalPropertiesForReceipt.Add("AndroidPlugin", overridelib_src_path);
			}else if(File.Exists(overridelib_built_path)){
				// otherwise copy pre-built vulkan override layer .so into project
				AdditionalPropertiesForReceipt.Add("AndroidPlugin", overridelib_built_path);
			}else{
				// ERROR
				throw new InvalidOperationException("Need "+overridelib_built_path+" to build");
			}
		}

		bPrecompile	= true;	

	}
}
