// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.IO; namespace UnrealBuildTool { /// /// Base class for platform-specific project generators /// abstract class UEPlatformProjectGenerator { static Dictionary ProjectGeneratorDictionary = new Dictionary(); /// /// Register the given platforms UEPlatformProjectGenerator instance /// /// The UnrealTargetPlatform to register with /// The UEPlatformProjectGenerator instance to use for the InPlatform public static void RegisterPlatformProjectGenerator(UnrealTargetPlatform InPlatform, UEPlatformProjectGenerator InProjectGenerator) { // Make sure the build platform is legal var 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 static UEPlatformProjectGenerator 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 static bool GenerateGameProjectStubs(ProjectFileGenerator InGenerator, string InTargetName, string InTargetFilepath, TargetRules InTargetRules, List InPlatforms, List InConfigurations) { foreach (KeyValuePair Entry in ProjectGeneratorDictionary) { UEPlatformProjectGenerator 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 static 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 static bool PlatformRequiresVSUserFileGeneration(List InPlatforms, List InConfigurations) { bool bRequiresVSUserFileGeneration = false; foreach (KeyValuePair Entry in ProjectGeneratorDictionary) { if (InPlatforms.Contains(Entry.Key)) { UEPlatformProjectGenerator ProjGen = Entry.Value; bRequiresVSUserFileGeneration |= ProjGen.RequiresVSUserFileGeneration(); } } return bRequiresVSUserFileGeneration; } /// /// Register the platform with the UEPlatformProjectGenerator class /// public abstract void RegisterPlatformProjectGenerator(); public virtual void GenerateGameProjectStub(ProjectFileGenerator InGenerator, string InTargetName, string InTargetFilepath, TargetRules InTargetRules, List InPlatforms, List InConfigurations) { // Do nothing } public virtual void GenerateGameProperties(UnrealTargetConfiguration Configuration, StringBuilder VCProjectFileContent, TargetType TargetType, DirectoryReference RootDirectory, FileReference TargetFilePath) { // Do nothing } public virtual bool RequiresVSUserFileGeneration() { return false; } /// /// VisualStudio project generation functions /// /// /// Whether this build platform has native support for VisualStudio /// /// The UnrealTargetPlatform being built /// The UnrealTargetConfiguration being built /// The visual studio project file format being generated /// bool true if native VisualStudio support (or custom VSI) is available public virtual bool HasVisualStudioSupport(UnrealTargetPlatform InPlatform, UnrealTargetConfiguration InConfiguration, VCProjectFileFormat ProjectFileFormat) { // By default, we assume this is true return true; } /// /// Return the VisualStudio platform name for this build platform /// /// The UnrealTargetPlatform being built /// The UnrealTargetConfiguration being built /// string The name of the platform that VisualStudio recognizes public virtual string GetVisualStudioPlatformName(UnrealTargetPlatform InPlatform, UnrealTargetConfiguration InConfiguration) { // By default, return the platform string return InPlatform.ToString(); } /// /// Return project configuration settings that must be included before the default props file /// /// The UnrealTargetPlatform being built /// The UnrealTargetConfiguration being built /// string The custom configuration section for the project file; Empty string if it doesn't require one public virtual string GetVisualStudioPreDefaultString(UnrealTargetPlatform InPlatform, UnrealTargetConfiguration InConfiguration) { return ""; } /// /// Return the platform toolset string to write into the project configuration /// /// The UnrealTargetPlatform being built /// The UnrealTargetConfiguration being built /// The visual studio project file format being generated /// string The custom configuration section for the project file; Empty string if it doesn't require one public virtual string GetVisualStudioPlatformToolsetString(UnrealTargetPlatform InPlatform, UnrealTargetConfiguration InConfiguration, VCProjectFileFormat InProjectFileFormat) { return ""; } /// /// Return any custom property group lines /// /// The UnrealTargetPlatform being built /// The visual studio project file format being generated /// string The custom property import lines for the project file; Empty string if it doesn't require one public virtual string GetAdditionalVisualStudioPropertyGroups(UnrealTargetPlatform InPlatform, VCProjectFileFormat InProjectFileFormat) { return ""; } /// /// Return any custom property group lines /// /// The UnrealTargetPlatform being built /// The visual studio project file format being generated /// string The platform configuration type. Defaults to "Makefile" unless overridden public virtual string GetVisualStudioPlatformConfigurationType(UnrealTargetPlatform InPlatform, VCProjectFileFormat InProjectFileFormat) { return "Makefile"; } /// /// Return any custom paths for VisualStudio this platform requires /// This include ReferencePath, LibraryPath, LibraryWPath, IncludePath and ExecutablePath. /// /// The UnrealTargetPlatform being built /// The configuration being built /// The type of target (game or program) /// Path to the .target.cs file /// /// /// The visual studio project file format being generated /// The custom path lines for the project file; Empty string if it doesn't require one public virtual string GetVisualStudioPathsEntries(UnrealTargetPlatform InPlatform, UnrealTargetConfiguration InConfiguration, TargetType TargetType, FileReference TargetRulesPath, FileReference ProjectFilePath, FileReference NMakeOutputPath, VCProjectFileFormat InProjectFileFormat) { // NOTE: We are intentionally overriding defaults for these paths with empty strings. We never want Visual Studio's // defaults for these fields to be propagated, since they are version-sensitive paths that may not reflect // the environment that UBT is building in. We'll set these environment variables ourselves! // NOTE: We don't touch 'ExecutablePath' because that would result in Visual Studio clobbering the system "Path" // environment variable string PathsLines = " \n" + " \n" + " \n" + " \n" + " \n" + " \n"; return PathsLines; } /// /// Return any custom property settings. These will be included in the ImportGroup section /// /// The UnrealTargetPlatform being built /// string The custom property import lines for the project file; Empty string if it doesn't require one public virtual string GetVisualStudioImportGroupProperties(UnrealTargetPlatform InPlatform) { return ""; } /// /// Return any custom property settings. These will be included right after Global properties to make values available to all other imports. /// /// The UnrealTargetPlatform being built /// string The custom property import lines for the project file; Empty string if it doesn't require one public virtual string GetVisualStudioGlobalProperties(UnrealTargetPlatform InPlatform) { return ""; } /// /// Return any custom target overrides. These will be included last in the project file so they have the opportunity to override any existing settings. /// /// The UnrealTargetPlatform being built /// The visual studio project file format being generated /// string The custom property import lines for the project file; Empty string if it doesn't require one public virtual string GetVisualStudioTargetOverrides(UnrealTargetPlatform InPlatform, VCProjectFileFormat InProjectFileFormat) { return ""; } /// /// Return any custom layout directory sections /// /// The UnrealTargetPlatform being built /// The configuration being built /// /// The type of target (game or program) /// The visual studio project file format being generated /// /// /// /// string The custom property import lines for the project file; Empty string if it doesn't require one public virtual string GetVisualStudioLayoutDirSection(UnrealTargetPlatform InPlatform, UnrealTargetConfiguration InConfiguration, string InConditionString, TargetType TargetType, FileReference TargetRulesPath, FileReference ProjectFilePath, FileReference NMakeOutputPath, VCProjectFileFormat InProjectFileFormat) { return ""; } /// /// Get the output manifest section, if required /// /// The UnrealTargetPlatform being built /// The type of the target being built /// Path to the .target.cs file /// Path to the project file /// The visual studio project file format being generated /// The output manifest section for the project file; Empty string if it doesn't require one public virtual string GetVisualStudioOutputManifestSection(UnrealTargetPlatform InPlatform, TargetType TargetType, FileReference TargetRulesPath, FileReference ProjectFilePath, VCProjectFileFormat InProjectFileFormat) { return ""; } /// /// Get whether this platform deploys /// /// bool true if the 'Deploy' option should be enabled public virtual bool GetVisualStudioDeploymentEnabled(UnrealTargetPlatform InPlatform, UnrealTargetConfiguration InConfiguration) { return false; } /// /// Get the text to insert into the user file for the given platform/configuration/target /// /// The platform being added /// The configuration being added /// The condition string /// The target rules /// The target rules path /// The project file path /// The string to append to the user file public virtual string GetVisualStudioUserFileStrings(UnrealTargetPlatform InPlatform, UnrealTargetConfiguration InConfiguration, string InConditionString, TargetRules InTargetRules, FileReference TargetRulesPath, FileReference ProjectFilePath) { return ""; } /// /// For Additional Project Property files that need to be written out. This is currently used only on Android. /// public virtual void WriteAdditionalPropFile() { } /// /// For additional Project files (ex. *PROJECTNAME*-AndroidRun.androidproj.user) that needs to be written out. This is currently used only on Android. /// /// Project file this will be related to public virtual void WriteAdditionalProjUserFile(ProjectFile ProjectFile) { } /// /// For additional Project files (ex. *PROJECTNAME*-AndroidRun.androidproj) that needs to be written out. This is currently used only on Android. /// /// Project file this will be related to /// Project file written out, Solution folder it should be put in public virtual Tuple WriteAdditionalProjFile(ProjectFile ProjectFile) { return null; } } }