// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using Tools.DotNETCommon; namespace UnrealBuildTool { /// /// Stores all the registered platform project generators /// class PlatformProjectGeneratorCollection { Dictionary ProjectGeneratorDictionary = new Dictionary(); /// /// Register the given platforms UEPlatformProjectGenerator instance /// /// The UnrealTargetPlatform to register with /// The UEPlatformProjectGenerator instance to use for the InPlatform public void RegisterPlatformProjectGenerator(UnrealTargetPlatform InPlatform, PlatformProjectGenerator InProjectGenerator) { // Make sure the build platform is legal UEBuildPlatform BuildPlatform = UEBuildPlatform.GetBuildPlatform(InPlatform, true); if (BuildPlatform != null) { if (ProjectGeneratorDictionary.ContainsKey(InPlatform) == true) { Log.TraceInformation("RegisterPlatformProjectGenerator Warning: Registering project generator {0} for {1} when it is already set to {2}", InProjectGenerator.ToString(), InPlatform.ToString(), ProjectGeneratorDictionary[InPlatform].ToString()); ProjectGeneratorDictionary[InPlatform] = InProjectGenerator; } else { ProjectGeneratorDictionary.Add(InPlatform, InProjectGenerator); } } else { Log.TraceVerbose("Skipping project file generator registration for {0} due to no valid BuildPlatform.", InPlatform.ToString()); } } /// /// Retrieve the UEPlatformProjectGenerator instance for the given TargetPlatform /// /// The UnrealTargetPlatform being built /// If true, do not throw an exception and return null /// UEPlatformProjectGenerator The instance of the project generator public PlatformProjectGenerator GetPlatformProjectGenerator(UnrealTargetPlatform InPlatform, bool bInAllowFailure = false) { if (ProjectGeneratorDictionary.ContainsKey(InPlatform) == true) { return ProjectGeneratorDictionary[InPlatform]; } if (bInAllowFailure == true) { return null; } throw new BuildException("GetPlatformProjectGenerator: No PlatformProjectGenerator found for {0}", InPlatform.ToString()); } /// /// Allow various platform project generators to generate stub projects if required /// /// /// /// /// /// /// /// public bool GenerateGameProjectStubs(ProjectFileGenerator InGenerator, string InTargetName, string InTargetFilepath, TargetRules InTargetRules, List InPlatforms, List InConfigurations) { foreach (KeyValuePair Entry in ProjectGeneratorDictionary) { PlatformProjectGenerator ProjGen = Entry.Value; ProjGen.GenerateGameProjectStub(InGenerator, InTargetName, InTargetFilepath, InTargetRules, InPlatforms, InConfigurations); } return true; } /// /// Allow various platform project generators to generate any special project properties if required /// /// /// /// /// /// /// /// public bool GenerateGamePlatformSpecificProperties(UnrealTargetPlatform InPlatform, UnrealTargetConfiguration Configuration, TargetType TargetType, StringBuilder VCProjectFileContent, DirectoryReference RootDirectory, FileReference TargetFilePath) { if (ProjectGeneratorDictionary.ContainsKey(InPlatform) == true) { ProjectGeneratorDictionary[InPlatform].GenerateGameProperties(Configuration, VCProjectFileContent, TargetType, RootDirectory, TargetFilePath); ; } return true; } public bool PlatformRequiresVSUserFileGeneration(List InPlatforms, List InConfigurations) { bool bRequiresVSUserFileGeneration = false; foreach (KeyValuePair Entry in ProjectGeneratorDictionary) { if (InPlatforms.Contains(Entry.Key)) { PlatformProjectGenerator ProjGen = Entry.Value; bRequiresVSUserFileGeneration |= ProjGen.RequiresVSUserFileGeneration(); } } return bRequiresVSUserFileGeneration; } } }