Exemplo n.º 1
0
        /// <summary>
        /// Get the name of the response file for the current linker environment and output file
        /// </summary>
        /// <param name="LinkEnvironment"></param>
        /// <param name="OutputFile"></param>
        /// <returns></returns>
        public static string GetResponseFileName(LinkEnvironment LinkEnvironment, FileItem OutputFile)
        {
            // Construct a relative path for the intermediate response file
            string ResponseFileName = Path.Combine(LinkEnvironment.Config.IntermediateDirectory, Path.GetFileName(OutputFile.AbsolutePath) + ".response");

            if (UnrealBuildTool.HasUProjectFile())
            {
                // If this is the uproject being built, redirect the intermediate
                if (Utils.IsFileUnderDirectory(OutputFile.AbsolutePath, UnrealBuildTool.GetUProjectPath()))
                {
                    ResponseFileName = Path.Combine(
                        UnrealBuildTool.GetUProjectPath(),
                        BuildConfiguration.PlatformIntermediateFolder,
                        Path.GetFileNameWithoutExtension(UnrealBuildTool.GetUProjectFile()),
                        LinkEnvironment.Config.Target.Configuration.ToString(),
                        Path.GetFileName(OutputFile.AbsolutePath) + ".response");
                }
            }
            // Convert the relative path to an absolute path
            ResponseFileName = Path.GetFullPath(ResponseFileName);

            return(ResponseFileName);
        }
Exemplo n.º 2
0
        public override bool WriteProjectFile(List <UnrealTargetPlatform> InPlatforms, List <UnrealTargetConfiguration> InConfigurations)
        {
            bool bSuccess = false;

            string ProjectPath             = ProjectFilePath;
            string ProjectExtension        = Path.GetExtension(ProjectFilePath);
            string ProjectPlatformName     = BuildHostPlatform.Current.Platform.ToString();
            string ProjectRelativeFilePath = this.RelativeProjectFilePath;

            // Get the output directory
            string EngineRootDirectory = Path.GetFullPath(ProjectFileGenerator.EngineRelativePath);

            //
            // Build the working directory of the Game executable.
            //

            string GameWorkingDirectory = "";

            if (UnrealBuildTool.HasUProjectFile())
            {
                GameWorkingDirectory = Path.Combine(Path.GetDirectoryName(UnrealBuildTool.GetUProjectFile()), "Binaries", ProjectPlatformName);
            }
            //
            // Build the working directory of the UE4Editor executable.
            //
            string UE4EditorWorkingDirectory = Path.Combine(EngineRootDirectory, "Binaries", ProjectPlatformName);

            //
            // Create the folder where the project files goes if it does not exist
            //
            String FilePath = Path.GetDirectoryName(ProjectFilePath);

            if ((FilePath.Length > 0) && !Directory.Exists(FilePath))
            {
                Directory.CreateDirectory(FilePath);
            }

            string GameProjectFile = UnrealBuildTool.GetUProjectFile();

            //
            // Write all targets which will be separate projects.
            //
            foreach (ProjectTarget target in ProjectTargets)
            {
                string[] tmp = target.ToString().Split('.');
                string   ProjectTargetFileName = Path.GetDirectoryName(ProjectFilePath) + "/" + tmp [0] + ProjectExtension;
                String   ProjectName           = tmp [0];
                var      ProjectTargetType     = target.TargetRules.Type;

                //
                // Create the CodeLites root element.
                //
                XElement   CodeLiteProject = new XElement("CodeLite_Project");
                XAttribute CodeLiteProjectAttributeName = new XAttribute("Name", ProjectName);
                CodeLiteProject.Add(CodeLiteProjectAttributeName);

                //
                // Select only files we want to add.
                // TODO Maybe skipping those files directly in the following foreach loop is faster?
                //
                List <SourceFile> FilterSourceFile = SourceFiles.FindAll(s => (
                                                                             Path.GetExtension(s.FilePath).Equals(".h") ||
                                                                             Path.GetExtension(s.FilePath).Equals(".cpp") ||
                                                                             Path.GetExtension(s.FilePath).Equals(".cs") ||
                                                                             Path.GetExtension(s.FilePath).Equals(".uproject") ||
                                                                             Path.GetExtension(s.FilePath).Equals(".ini") ||
                                                                             Path.GetExtension(s.FilePath).Equals(".usf")
                                                                             ));

                //
                // Find/Create the correct virtual folder and place the file into it.
                //
                foreach (var CurrentFile in FilterSourceFile)
                {
                    //
                    // Try to get the correct relative folder representation for the project.
                    //
                    String CurrentFilePath = "";
                    // TODO It seems that the full pathname doesn't work for some files like .ini, .usf
                    if ((ProjectTargetType == TargetRules.TargetType.Client) ||
                        (ProjectTargetType == TargetRules.TargetType.Editor) ||
                        (ProjectTargetType == TargetRules.TargetType.Server))
                    {
                        if (ProjectName.Contains("UE4"))
                        {
                            int Idx = Path.GetFullPath(ProjectFileGenerator.EngineRelativePath).Length;
                            CurrentFilePath = Path.GetDirectoryName(Path.GetFullPath(CurrentFile.FilePath)).Substring(Idx);
                        }
                        else
                        {
                            int    IdxProjectName = ProjectName.IndexOf("Editor");
                            string ProjectNameRaw = ProjectName;
                            if (IdxProjectName > 0)
                            {
                                ProjectNameRaw = ProjectName.Substring(0, IdxProjectName);
                            }
                            int Idx = Path.GetDirectoryName(Path.GetFullPath(CurrentFile.FilePath)).IndexOf(ProjectNameRaw) + ProjectNameRaw.Length;
                            CurrentFilePath = Path.GetDirectoryName(Path.GetFullPath(CurrentFile.FilePath)).Substring(Idx);
                        }
                    }
                    else if (ProjectTargetType == TargetRules.TargetType.Program)
                    {
                        //
                        // We do not need all the editors subfolders to show the content. Find the correct programs subfolder.
                        //
                        int Idx = Path.GetDirectoryName(Path.GetFullPath(CurrentFile.FilePath)).IndexOf(ProjectName) + ProjectName.Length;
                        CurrentFilePath = Path.GetFullPath(Path.GetDirectoryName(CurrentFile.FilePath)).Substring(Idx);
                    }
                    else if (ProjectTargetType == TargetRules.TargetType.Game)
                    {
//						int lengthOfProjectRootPath = Path.GetFullPath(ProjectFileGenerator.MasterProjectRelativePath).Length;
//						CurrentFilePath = Path.GetDirectoryName(Path.GetFullPath(CurrentFile.FilePath)).Substring(lengthOfProjectRootPath);
                        //	int lengthOfProjectRootPath = EngineRootDirectory.Length;
                        int Idx = Path.GetDirectoryName(Path.GetFullPath(CurrentFile.FilePath)).IndexOf(ProjectName) + ProjectName.Length;
                        CurrentFilePath = Path.GetDirectoryName(Path.GetFullPath(CurrentFile.FilePath)).Substring(Idx);
                    }

                    string [] SplitFolders = CurrentFilePath.Split('/');
                    //
                    // Set the CodeLite root folder again.
                    //
                    XElement root = CodeLiteProject;

                    //
                    // Iterate through all XElement virtual folders until we find the right place to put the file.
                    // TODO this looks more like a hack to me.
                    //
                    foreach (var FolderName in SplitFolders)
                    {
                        if (FolderName.Equals(""))
                        {
                            continue;
                        }

                        //
                        // Let's look if there is a virtual folder withint the current XElement.
                        //
                        IEnumerable <XElement> tests = root.Elements("VirtualDirectory");
                        if (IsEmpty(tests))
                        {
                            //
                            // No, then we have to create.
                            //
                            XElement   vf  = new XElement("VirtualDirectory");
                            XAttribute vfn = new XAttribute("Name", FolderName);
                            vf.Add(vfn);
                            root.Add(vf);
                            root = vf;
                        }
                        else
                        {
                            //
                            // Yes, then let's find the correct sub XElement.
                            //
                            bool notfound = true;

                            //
                            // We have some virtual directories let's find the correct one.
                            //
                            foreach (var element in tests)
                            {
                                //
                                // Look the the following folder
                                XAttribute attribute = element.Attribute("Name");
                                if (attribute.Value == FolderName)
                                {
                                    // Ok, we found the folder as subfolder, let's use it.
                                    root     = element;
                                    notfound = false;
                                    break;
                                }
                            }
                            //
                            // If we are here we didn't find any XElement with that subfolder, then we have to create.
                            //
                            if (notfound)
                            {
                                XElement   vf  = new XElement("VirtualDirectory");
                                XAttribute vfn = new XAttribute("Name", FolderName);
                                vf.Add(vfn);
                                root.Add(vf);
                                root = vf;
                            }
                        }
                    }

                    //
                    // If we are at this point we found the correct XElement folder
                    //
                    XElement   file          = new XElement("File");
                    XAttribute fileAttribute = new XAttribute("Name", Path.GetFullPath(CurrentFile.FilePath));
                    file.Add(fileAttribute);
                    root.Add(file);
                }

                XElement CodeLiteSettings = new XElement("Settings");
                CodeLiteProject.Add(CodeLiteSettings);

                XElement CodeLiteGlobalSettings = new XElement("GlobalSettings");
                CodeLiteSettings.Add(CodeLiteSettings);


                foreach (var CurConf in InConfigurations)
                {
                    XElement   CodeLiteConfiguration     = new XElement("Configuration");
                    XAttribute CodeLiteConfigurationName = new XAttribute("Name", CurConf.ToString());
                    CodeLiteConfiguration.Add(CodeLiteConfigurationName);

                    //
                    // Create Configuration General part.
                    //
                    XElement CodeLiteConfigurationGeneral = new XElement("General");

                    //
                    // Create the executable filename.
                    //
                    string ExecutableToRun       = "";
                    string PlatformConfiguration = "-" + ProjectPlatformName + "-" + CurConf.ToString();
                    switch (BuildHostPlatform.Current.Platform)
                    {
                    case UnrealTargetPlatform.Linux:
                    {
                        ExecutableToRun = "./" + ProjectName;
                        if ((ProjectTargetType == TargetRules.TargetType.Game) || (ProjectTargetType == TargetRules.TargetType.Program))
                        {
                            if (CurConf != UnrealTargetConfiguration.Development)
                            {
                                ExecutableToRun += PlatformConfiguration;
                            }
                        }
                        else if (ProjectTargetType == TargetRules.TargetType.Editor)
                        {
                            ExecutableToRun = "./UE4Editor";
                        }
                    }
                    break;

                    case UnrealTargetPlatform.Mac:
                    {
                        ExecutableToRun = "./" + ProjectName;
                        if ((ProjectTargetType == TargetRules.TargetType.Game) || (ProjectTargetType == TargetRules.TargetType.Program))
                        {
                            if (CurConf != UnrealTargetConfiguration.Development)
                            {
                                ExecutableToRun += PlatformConfiguration;
                            }
                            ExecutableToRun += ".app/Contents/MacOS/" + ProjectName;
                            if (CurConf != UnrealTargetConfiguration.Development)
                            {
                                ExecutableToRun += PlatformConfiguration;
                            }
                        }
                        else if (ProjectTargetType == TargetRules.TargetType.Editor)
                        {
                            ExecutableToRun = "./UE4Editor";
                            if (CurConf != UnrealTargetConfiguration.Development)
                            {
                                ExecutableToRun += PlatformConfiguration;
                            }
                            ExecutableToRun += ".app/Contents/MacOS/UE4Editor";
                            if (CurConf != UnrealTargetConfiguration.Development)
                            {
                                ExecutableToRun += PlatformConfiguration;
                            }
                        }
                    }
                    break;

                    case UnrealTargetPlatform.Win64:
                    case UnrealTargetPlatform.Win32:
                    {
                        ExecutableToRun = ProjectName;
                        if ((ProjectTargetType == TargetRules.TargetType.Game) || (ProjectTargetType == TargetRules.TargetType.Program))
                        {
                            if (CurConf != UnrealTargetConfiguration.Development)
                            {
                                ExecutableToRun += PlatformConfiguration;
                            }
                        }
                        else if (ProjectTargetType == TargetRules.TargetType.Editor)
                        {
                            ExecutableToRun = "UE4Editor";
                        }

                        ExecutableToRun += ".exe";
                    }
                    break;

                    default:
                        throw new BuildException("Unsupported platform.");
                    }


                    // Is this project a Game type?
                    XAttribute GeneralExecutableToRun = new XAttribute("Command", ExecutableToRun);
                    if (ProjectTargetType == TargetRules.TargetType.Game)
                    {
                        if (CurConf.ToString().Contains("Debug"))
                        {
                            string     commandArguments = " -debug";
                            XAttribute GeneralExecutableToRunArguments = new XAttribute("CommandArguments", commandArguments);
                            CodeLiteConfigurationGeneral.Add(GeneralExecutableToRunArguments);
                        }
                        if (ProjectName.Equals("UE4Game"))
                        {
                            XAttribute GeneralExecutableWorkingDirectory = new XAttribute("WorkingDirectory", UE4EditorWorkingDirectory);
                            CodeLiteConfigurationGeneral.Add(GeneralExecutableWorkingDirectory);
                        }
                        else
                        {
                            XAttribute GeneralExecutableWorkingDirectory = new XAttribute("WorkingDirectory", GameWorkingDirectory);
                            CodeLiteConfigurationGeneral.Add(GeneralExecutableWorkingDirectory);
                        }
                    }
                    else if (ProjectTargetType == TargetRules.TargetType.Editor)
                    {
                        if (ProjectName != "UE4Editor")
                        {
                            string     commandArguments = "\"" + GameProjectFile + "\"" + " -game";
                            XAttribute CommandArguments = new XAttribute("CommandArguments", commandArguments);
                            CodeLiteConfigurationGeneral.Add(CommandArguments);
                        }
                        XAttribute WorkingDirectory = new XAttribute("WorkingDirectory", UE4EditorWorkingDirectory);
                        CodeLiteConfigurationGeneral.Add(WorkingDirectory);
                    }
                    else if (ProjectTargetType == TargetRules.TargetType.Program)
                    {
                        XAttribute WorkingDirectory = new XAttribute("WorkingDirectory", UE4EditorWorkingDirectory);
                        CodeLiteConfigurationGeneral.Add(WorkingDirectory);
                    }
                    else if (ProjectTargetType == TargetRules.TargetType.Client)
                    {
                        XAttribute WorkingDirectory = new XAttribute("WorkingDirectory", UE4EditorWorkingDirectory);
                        CodeLiteConfigurationGeneral.Add(WorkingDirectory);
                    }
                    else if (ProjectTargetType == TargetRules.TargetType.Server)
                    {
                        XAttribute WorkingDirectory = new XAttribute("WorkingDirectory", UE4EditorWorkingDirectory);
                        CodeLiteConfigurationGeneral.Add(WorkingDirectory);
                    }
                    CodeLiteConfigurationGeneral.Add(GeneralExecutableToRun);

                    CodeLiteConfiguration.Add(CodeLiteConfigurationGeneral);

                    //
                    // End of Create Configuration General part.
                    //

                    //
                    // Create Configuration Custom Build part.
                    //
                    XElement CodeLiteConfigurationCustomBuild = new XElement("CustomBuild");
                    CodeLiteConfiguration.Add(CodeLiteConfigurationGeneral);
                    XAttribute CodeLiteConfigurationCustomBuildEnabled = new XAttribute("Enabled", "yes");
                    CodeLiteConfigurationCustomBuild.Add(CodeLiteConfigurationCustomBuildEnabled);

                    //
                    // Add the working directory for the custom build commands.
                    //
                    XElement CustomBuildWorkingDirectory  = new XElement("WorkingDirectory");
                    XText    CustuomBuildWorkingDirectory = new XText(Path.GetDirectoryName(UnrealBuildTool.GetUBTPath()));
                    CustomBuildWorkingDirectory.Add(CustuomBuildWorkingDirectory);
                    CodeLiteConfigurationCustomBuild.Add(CustomBuildWorkingDirectory);

                    //
                    // End of Add the working directory for the custom build commands.
                    //



                    //
                    // Make Build Target.
                    //
                    XElement CustomBuildCommand = new XElement("BuildCommand");
                    CodeLiteConfigurationCustomBuild.Add(CustomBuildCommand);

                    string BuildTarget = Path.GetFileName(UnrealBuildTool.GetUBTPath()) + " " + ProjectName + " " + ProjectPlatformName + " " + CurConf.ToString();
                    if ((BuildHostPlatform.Current.Platform != UnrealTargetPlatform.Win64) &&
                        (BuildHostPlatform.Current.Platform != UnrealTargetPlatform.Win32))
                    {
                        BuildTarget = "mono " + BuildTarget;
                    }

                    if (GameProjectFile.Length > 0)
                    {
                        BuildTarget += " -project=" + "\"" + GameProjectFile + "\"";
                    }

                    XText commandLine = new XText(BuildTarget);
                    CustomBuildCommand.Add(commandLine);

                    //
                    // End of Make Build Target
                    //

                    //
                    // Clean Build Target.
                    //
                    XElement CustomCleanCommand = new XElement("CleanCommand");
                    CodeLiteConfigurationCustomBuild.Add(CustomCleanCommand);

                    string CleanTarget      = BuildTarget + " -clean";
                    XText  CleanCommandLine = new XText(CleanTarget);

                    CustomCleanCommand.Add(CleanCommandLine);


                    //
                    // End of Clean Build Target.
                    //

                    //
                    // Rebuild Build Target.
                    //
                    XElement CustomRebuildCommand = new XElement("RebuildCommand");
                    CodeLiteConfigurationCustomBuild.Add(CustomRebuildCommand);

                    string RebuildTarget      = CleanTarget + "\n" + BuildTarget;
                    XText  RebuildCommandLine = new XText(RebuildTarget);

                    CustomRebuildCommand.Add(RebuildCommandLine);

                    //
                    // End of Clean Build Target.
                    //


                    //
                    // Some other fun Custom Targets.
                    //
                    if (ProjectTargetType == TargetRules.TargetType.Game)
                    {
                        string CookGameCommandLine = "mono AutomationTool.exe BuildCookRun ";

                        // Projects filename
                        CookGameCommandLine += "-project=\"" + UnrealBuildTool.GetUProjectFile() + "\" ";

                        // Disables Perforce functionality
                        CookGameCommandLine += "-noP4 ";

                        // Do not kill any spawned processes on exit
                        CookGameCommandLine += "-nokill ";
                        CookGameCommandLine += "-clientconfig=" + CurConf.ToString() + " ";
                        CookGameCommandLine += "-serverconfig=" + CurConf.ToString() + " ";
                        CookGameCommandLine += "-platform=" + ProjectPlatformName + " ";
                        CookGameCommandLine += "-targetplatform=" + ProjectPlatformName + " ";                                 // TODO Maybe I can add all the supported one.
                        CookGameCommandLine += "-nocompile ";
                        CookGameCommandLine += "-compressed -stage -deploy";

                        //
                        // Cook Game.
                        //
                        XElement   CookGame        = new XElement("Target");
                        XAttribute CookGameName    = new XAttribute("Name", "Cook Game");
                        XText      CookGameCommand = new XText(CookGameCommandLine + " -cook");
                        CookGame.Add(CookGameName);
                        CookGame.Add(CookGameCommand);
                        CodeLiteConfigurationCustomBuild.Add(CookGame);

                        XElement   CookGameOnTheFly         = new XElement("Target");
                        XAttribute CookGameNameOnTheFlyName = new XAttribute("Name", "Cook Game on the fly");
                        XText      CookGameOnTheFlyCommand  = new XText(CookGameCommandLine + " -cookonthefly");
                        CookGameOnTheFly.Add(CookGameNameOnTheFlyName);
                        CookGameOnTheFly.Add(CookGameOnTheFlyCommand);
                        CodeLiteConfigurationCustomBuild.Add(CookGameOnTheFly);

                        XElement   SkipCook        = new XElement("Target");
                        XAttribute SkipCookName    = new XAttribute("Name", "Skip Cook Game");
                        XText      SkipCookCommand = new XText(CookGameCommandLine + " -skipcook");
                        SkipCook.Add(SkipCookName);
                        SkipCook.Add(SkipCookCommand);
                        CodeLiteConfigurationCustomBuild.Add(SkipCook);
                    }
                    //
                    // End of Some other fun Custom Targets.
                    //
                    CodeLiteConfiguration.Add(CodeLiteConfigurationCustomBuild);

                    //
                    // End of Create Configuration Custom Build part.
                    //

                    CodeLiteSettings.Add(CodeLiteConfiguration);
                }

                CodeLiteSettings.Add(CodeLiteGlobalSettings);

                //
                // Save the XML file.
                //
                CodeLiteProject.Save(ProjectTargetFileName);

                bSuccess = true;
            }
            return(bSuccess);
        }
Exemplo n.º 3
0
        private bool WriteQMakePro()
        {
            // Some more stuff borrowed from Mac side of things.
            List <string> IncludeDirectories       = new List <string>();
            List <string> SystemIncludeDirectories = new List <string>();
            List <string> DefinesAndValues         = new List <string> ();

            // DefineList.Add ("");

            var QMakeIncludesFileName       = MasterProjectName + "Includes.pri";
            var QMakeIncludesPriFileContent = new StringBuilder();

            var QMakeDefinesFileName       = MasterProjectName + "Defines.pri";
            var QMakeDefinesPriFileContent = new StringBuilder();

            string GameProjectPath     = "";
            string GameProjectFile     = "";
            string GameProjectRootPath = "";

            string BuildCommand = "";

            string QMakeGameProjectFile = "";

            foreach (var CurProject in GeneratedProjectFiles)
            {
                QMakefileProjectFile QMakeProject = CurProject as QMakefileProjectFile;
                if (QMakeProject == null)
                {
                    System.Console.WriteLine("QMakeProject == null");
                    continue;
                }

                foreach (var CurPath in QMakeProject.IntelliSenseIncludeSearchPaths)
                {
                    AddIncludeDirectory(ref IncludeDirectories, CurPath, Path.GetDirectoryName(QMakeProject.ProjectFilePath));
                    // System.Console.WriteLine ("Not empty now? CurPath == ", CurPath);
                }
                foreach (var CurPath in QMakeProject.IntelliSenseSystemIncludeSearchPaths)
                {
                    AddIncludeDirectory(ref SystemIncludeDirectories, CurPath, Path.GetDirectoryName(QMakeProject.ProjectFilePath));
                }
            }

            // Iterate through all the defines for the projects that are generated by
            // UnrealBuildTool.exe
            // !RAKE: move to seperate function
            QMakeDefinesPriFileContent.Append("DEFINES += \\\n");
            foreach (var CurProject in GeneratedProjectFiles)
            {
                QMakefileProjectFile QMakeProject = CurProject as QMakefileProjectFile;
                if (QMakeProject == null)
                {
                    System.Console.WriteLine("QMakeProject == null");
                    continue;
                }

                foreach (var CurDefine in QMakeProject.IntelliSensePreprocessorDefinitions)
                {
                    String define = "";
                    String value  = "";

                    SplitDefinitionAndValue(CurDefine, out define, out value);

                    if (!DefinesAndValues.Contains(define))
                    {
                        // System.Console.WriteLine (CurDefine);
                        if (string.IsNullOrEmpty(value))
                        {
                            DefinesAndValues.Add("\t");
                            DefinesAndValues.Add(String.Format("{0}=", define));
                            DefinesAndValues.Add(" \\\n");
                        }
                        else
                        {
                            DefinesAndValues.Add("\t");
                            DefinesAndValues.Add(define);
                            DefinesAndValues.Add("=");
                            DefinesAndValues.Add(value);
                            DefinesAndValues.Add(" \\\n");
                        }
                    }
                }
            }

            foreach (var Def in DefinesAndValues)
            {
                QMakeDefinesPriFileContent.Append(Def);
            }

            // Iterate through all the include paths that
            // UnrealBuildTool.exe generates
            // !RAKE: Move to seperate function
            QMakeIncludesPriFileContent.Append("INCLUDEPATH += \\\n");
            foreach (var CurPath in IncludeDirectories)
            {
                QMakeIncludesPriFileContent.Append("\t");
                QMakeIncludesPriFileContent.Append(CurPath);
                QMakeIncludesPriFileContent.Append(" \\\n");
            }

            foreach (var CurPath in SystemIncludeDirectories)
            {
                QMakeIncludesPriFileContent.Append("\t");
                QMakeIncludesPriFileContent.Append(CurPath);
                QMakeIncludesPriFileContent.Append(" \\\n");
            }
            QMakeIncludesPriFileContent.Append("\n");

            if (!String.IsNullOrEmpty(GameProjectName))
            {
                GameProjectPath      = UnrealBuildTool.GetUProjectPath();
                GameProjectFile      = UnrealBuildTool.GetUProjectFile();
                QMakeGameProjectFile = "gameProjectFile=" + GameProjectFile + "\n";
                BuildCommand         = "build=mono $$unrealRootPath/Engine/Binaries/DotNET/UnrealBuildTool.exe\n\n";
            }
            else
            {
                BuildCommand = "build=bash $$unrealRootPath/Engine/Build/BatchFiles/Linux/Build.sh\n";
            }

            var UnrealRootPath = Path.GetFullPath(ProjectFileGenerator.RootRelativePath);

            var FileName = MasterProjectName + ".pro";

            var QMakeSourcePriFileName = MasterProjectName + "Source.pri";
            var QMakeHeaderPriFileName = MasterProjectName + "Header.pri";
            var QMakeConfigPriFileName = MasterProjectName + "Config.pri";

            var QMakeFileContent = new StringBuilder();

            var QMakeSourcePriFileContent = new StringBuilder();
            var QMakeHeaderPriFileContent = new StringBuilder();
            var QMakeConfigPriFileContent = new StringBuilder();

            var QMakeSectionEnd = " \n\n";

            var QMakeSourceFilesList = "SOURCES += \\ \n";
            var QMakeHeaderFilesList = "HEADERS += \\ \n";
            var QMakeConfigFilesList = "OTHER_FILES += \\ \n";
            var QMakeTargetList      = "QMAKE_EXTRA_TARGETS += \\ \n";

            if (!String.IsNullOrEmpty(GameProjectName))
            {
                GameProjectRootPath = GameProjectName + "RootPath=" + GameProjectPath + "\n\n";
            }

            QMakeFileContent.Append(
                "# UnrealEngine.pro generated by QMakefileGenerator.cs\n" +
                "# *DO NOT EDIT*\n\n" +
                "TEMPLATE = aux\n" +
                "CONFIG -= console\n" +
                "CONFIG -= app_bundle\n" +
                "CONFIG -= qt\n\n" +
                "TARGET = UE4 \n\n" +
                "unrealRootPath=" + UnrealRootPath + "\n" +
                GameProjectRootPath +
                QMakeGameProjectFile +
                BuildCommand +
                "args=$(ARGS)\n\n" +
                "include(" + QMakeSourcePriFileName + ")\n" +
                "include(" + QMakeHeaderPriFileName + ")\n" +
                "include(" + QMakeConfigPriFileName + ")\n" +
                "include(" + QMakeIncludesFileName + ")\n" +
                "include(" + QMakeDefinesFileName + ")\n\n"
                );

            // Create SourceFiles, HeaderFiles, and ConfigFiles sections.
            var AllModuleFiles = DiscoverModules();

            foreach (string CurModuleFile in AllModuleFiles)
            {
                var FoundFiles = SourceFileSearch.FindModuleSourceFiles(CurModuleFile, ExcludeNoRedistFiles: bExcludeNoRedistFiles);
                foreach (string CurSourceFile in FoundFiles)
                {
                    string SourceFileRelativeToRoot = Utils.MakePathRelativeTo(CurSourceFile, Path.Combine(EngineRelativePath));
                    // Exclude some directories that we don't compile (note that we still want Windows/Mac etc for code navigation)
                    if (!SourceFileRelativeToRoot.Contains("Source/ThirdParty/"))
                    {
                        if (SourceFileRelativeToRoot.EndsWith(".cpp"))
                        {
                            if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                            {
                                QMakeSourceFilesList += ("\t\"" + "$$unrealRootPath/Engine/" + SourceFileRelativeToRoot + "\" \\\n");
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(GameProjectName))
                                {
                                    QMakeSourceFilesList += ("\t\"" + SourceFileRelativeToRoot.Substring(3) + "\" \\\n");
                                }
                                else if (!String.IsNullOrEmpty(GameProjectName))
                                {
                                    QMakeSourceFilesList += ("\t\"$$" + GameProjectName + "RootPath/" + Utils.MakePathRelativeTo(CurSourceFile, GameProjectPath) + "\" \\\n");
                                }
                                else
                                {
                                    System.Console.WriteLine("Error!, you should not be here.");
                                }
                            }
                        }
                        if (SourceFileRelativeToRoot.EndsWith(".h"))
                        {
                            if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                            {
                                // SourceFileRelativeToRoot = "Engine/" + SourceFileRelativeToRoot;
                                QMakeHeaderFilesList += ("\t\"" + "$$unrealRootPath/Engine/" + SourceFileRelativeToRoot + "\" \\\n");
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(GameProjectName))
                                {
                                    // SourceFileRelativeToRoot = SourceFileRelativeToRoot.Substring (3);
                                    QMakeHeaderFilesList += ("\t\"" + SourceFileRelativeToRoot.Substring(3) + "\" \\\n");
                                }
                                else if (!String.IsNullOrEmpty(GameProjectName))
                                {
                                    QMakeHeaderFilesList += ("\t\"$$" + GameProjectName + "RootPath/" + Utils.MakePathRelativeTo(CurSourceFile, GameProjectPath) + "\" \\\n");
                                }
                                else
                                {
                                    System.Console.WriteLine("Error!, you should not be here.");
                                }
                            }
                        }
                        if (SourceFileRelativeToRoot.EndsWith(".cs"))
                        {
                            if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                            {
                                // SourceFileRelativeToRoot = "Engine/" + SourceFileRelativeToRoot;
                                QMakeConfigFilesList += ("\t\"" + "$$unrealRootPath/Engine/" + SourceFileRelativeToRoot + "\" \\\n");
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(GameProjectName))
                                {
                                    // SourceFileRelativeToRoot = SourceFileRelativeToRoot.Substring (3);
                                    QMakeConfigFilesList += ("\t\"" + SourceFileRelativeToRoot.Substring(3) + "\" \\\n");
                                }
                                else if (!String.IsNullOrEmpty(GameProjectName))
                                {
                                    QMakeConfigFilesList += ("\t\"$$" + GameProjectName + "RootPath/" + Utils.MakePathRelativeTo(CurSourceFile, GameProjectPath) + "\" \\\n");
                                }
                                else
                                {
                                    System.Console.WriteLine("Error!, you should not be here.");
                                }
                            }
                        }
                    }
                }
            }

            // Add section end to section strings;
            QMakeSourceFilesList += QMakeSectionEnd;
            QMakeHeaderFilesList += QMakeSectionEnd;
            QMakeConfigFilesList += QMakeSectionEnd;

            // Append sections to the QMakeLists.txt file
            QMakeSourcePriFileContent.Append(QMakeSourceFilesList);
            QMakeHeaderPriFileContent.Append(QMakeHeaderFilesList);
            QMakeConfigPriFileContent.Append(QMakeConfigFilesList);

            string QMakeProjectCmdArg = "";

            foreach (string TargetFilePath in DiscoverTargets())
            {
                var TargetName = Utils.GetFilenameWithoutAnyExtensions(TargetFilePath);                         // Remove both ".cs" and ".

                foreach (UnrealTargetConfiguration CurConfiguration in Enum.GetValues(typeof(UnrealTargetConfiguration)))
                {
                    if (CurConfiguration != UnrealTargetConfiguration.Unknown && CurConfiguration != UnrealTargetConfiguration.Development)
                    {
                        if (UnrealBuildTool.IsValidConfiguration(CurConfiguration))
                        {
                            if (TargetName == GameProjectName || TargetName == (GameProjectName + "Editor"))
                            {
                                QMakeProjectCmdArg = " -project=\"\\\"$$gameProjectFile\\\"\"";
                            }
                            var ConfName = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration);
                            QMakeFileContent.Append(String.Format("{0}-Linux-{1}.commands = $$build {2} {0} Linux {1} $$args\n", TargetName, ConfName, QMakeProjectCmdArg));
                            QMakeTargetList += "\t" + TargetName + "-Linux-" + ConfName + " \\\n";                             // , TargetName, ConfName);
                        }
                    }
                }

                if (TargetName == GameProjectName || TargetName == (GameProjectName + "Editor"))
                {
                    QMakeProjectCmdArg = " -project=\"\\\"$$gameProjectFile\\\"\"";
                }

                QMakeFileContent.Append(String.Format("{0}.commands = $$build {1} {0} Linux Development $$args\n\n", TargetName, QMakeProjectCmdArg));
                QMakeTargetList += "\t" + TargetName + " \\\n";
            }

            QMakeFileContent.Append(QMakeTargetList.TrimEnd('\\'));

            var FullFileName = Path.Combine(MasterProjectRelativePath, FileName);

            var FullQMakeDefinesFileName   = Path.Combine(MasterProjectRelativePath, QMakeDefinesFileName);
            var FullQMakeIncludesFileName  = Path.Combine(MasterProjectRelativePath, QMakeIncludesFileName);
            var FullQMakeSourcePriFileName = Path.Combine(MasterProjectRelativePath, QMakeSourcePriFileName);
            var FullQMakeHeaderPriFileName = Path.Combine(MasterProjectRelativePath, QMakeHeaderPriFileName);
            var FullQMakeConfigPriFileName = Path.Combine(MasterProjectRelativePath, QMakeConfigPriFileName);

            WriteFileIfChanged(FullQMakeDefinesFileName, QMakeDefinesPriFileContent.ToString());
            WriteFileIfChanged(FullQMakeIncludesFileName, QMakeIncludesPriFileContent.ToString());
            WriteFileIfChanged(FullQMakeSourcePriFileName, QMakeSourcePriFileContent.ToString());

            WriteFileIfChanged(FullQMakeHeaderPriFileName, QMakeHeaderPriFileContent.ToString());
            WriteFileIfChanged(FullQMakeConfigPriFileName, QMakeConfigPriFileContent.ToString());

            return(WriteFileIfChanged(FullFileName, QMakeFileContent.ToString()));
        }
Exemplo n.º 4
0
        private bool WriteMakefile()
        {
            string GameProjectFile     = "";
            string BuildCommand        = "";
            string ProjectBuildCommand = "";

            string MakeGameProjectFile = "";

            var UnrealRootPath = Path.GetFullPath(ProjectFileGenerator.RootRelativePath);

            if (!String.IsNullOrEmpty(GameProjectName))
            {
                GameProjectFile     = UnrealBuildTool.GetUProjectFile();
                MakeGameProjectFile = "GAMEPROJECTFILE =" + GameProjectFile + "\n";
                ProjectBuildCommand = "PROJECTBUILD = mono $(UNREALROOTPATH)/Engine/Binaries/DotNET/UnrealBuildTool.exe\n";
            }

            BuildCommand = "BUILD = bash $(UNREALROOTPATH)/Engine/Build/BatchFiles/Linux/Build.sh\n";

            var FileName        = "Makefile"; // MasterProjectName + ".mk";
            var MakefileContent = new StringBuilder();

            MakefileContent.Append(
                "# Makefile generated by MakefileGenerator.cs\n" +
                "# *DO NOT EDIT*\n\n" +
                "UNREALROOTPATH = \"" + UnrealRootPath + "\"\n" +
                MakeGameProjectFile + "\n" +
                "TARGETS ="
                );
            String MakeProjectCmdArg = "";
            String MakeBuildCommand  = "";

            foreach (string Target in DiscoverTargets())
            {
                var Basename = Path.GetFileNameWithoutExtension(Target);
                Basename = Path.GetFileNameWithoutExtension(Basename);
                foreach (UnrealTargetConfiguration CurConfiguration in Enum.GetValues(typeof(UnrealTargetConfiguration)))
                {
                    if (CurConfiguration != UnrealTargetConfiguration.Unknown && CurConfiguration != UnrealTargetConfiguration.Development)
                    {
                        if (UnrealBuildTool.IsValidConfiguration(CurConfiguration))
                        {
                            var Confname = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration);
                            MakefileContent.Append(String.Format(" \\\n\t{0}-Linux-{1} ", Basename, Confname));
                        }
                    }
                }
                MakefileContent.Append(" \\\n\t" + Basename);
            }
            MakefileContent.Append("\\\n\tconfigure");

            MakefileContent.Append("\n\n" + BuildCommand + ProjectBuildCommand + "\n" +
                                   "all: StandardSet\n\n" +
                                   "RequiredTools: CrashReportClient ShaderCompileWorker UnrealPak UnrealLightmass\n\n" +
                                   "StandardSet: RequiredTools UnrealFrontend UE4Editor\n\n" +
                                   "DebugSet: RequiredTools UnrealFrontend-Linux-Debug UE4Editor-Linux-Debug\n\n"
                                   );

            foreach (string Target in DiscoverTargets())
            {
                var Basename = Path.GetFileNameWithoutExtension(Target);
                Basename = Path.GetFileNameWithoutExtension(Basename);
                foreach (UnrealTargetConfiguration CurConfiguration in Enum.GetValues(typeof(UnrealTargetConfiguration)))
                {
                    if (Basename == GameProjectName || Basename == (GameProjectName + "Editor"))
                    {
                        MakeProjectCmdArg = " -project=\"\\\"$(GAMEPROJECTFILE)\\\"\"";
                        MakeBuildCommand  = "$(PROJECTBUILD)";
                    }
                    else
                    {
                        MakeBuildCommand = "$(BUILD)";
                    }

                    if (CurConfiguration != UnrealTargetConfiguration.Unknown && CurConfiguration != UnrealTargetConfiguration.Development)
                    {
                        if (UnrealBuildTool.IsValidConfiguration(CurConfiguration))
                        {
                            var Confname = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration);
                            MakefileContent.Append(String.Format("\n{1}-Linux-{2}:\n\t {0} {1} Linux {2} {3} $(ARGS)\n", MakeBuildCommand, Basename, Confname, MakeProjectCmdArg));
                        }
                    }
                }

                MakefileContent.Append(String.Format("\n{1}:\n\t {0} {1} Linux Development {2} $(ARGS)\n", MakeBuildCommand, Basename, MakeProjectCmdArg));
            }

            MakefileContent.Append("\nconfigure:\n");
            if (!String.IsNullOrEmpty(GameProjectName))
            {
                // Make sure UBT is updated.
                MakefileContent.Append("\txbuild /property:Configuration=Development /property:TargetFrameworkVersion=v4.0 /verbosity:quiet /nologo ");
                MakefileContent.Append("$(UNREALROOTPATH)/Engine/Source/Programs/UnrealBuildTool/UnrealBuildTool_Mono.csproj\n");
                MakefileContent.Append("\t$(PROJECTBUILD) -makefile -qmakefile -cmakefile -project=\"\\\"$(GAMEPROJECTFILE)\\\"\" -game -engine \n");
            }
            else
            {
                MakefileContent.Append("\tbash $(UNREALROOTPATH)/GenerateProjectFiles.sh \n");
            }

            MakefileContent.Append("\n.PHONY: $(TARGETS)\n");
            var FullFileName = Path.Combine(MasterProjectRelativePath, FileName);

            return(WriteFileIfChanged(FullFileName, MakefileContent.ToString()));
        }
Exemplo n.º 5
0
        /**
         * Builds and runs the header tool and touches the header directories.
         * Performs any early outs if headers need no changes, given the UObject modules, tool path, game name, and configuration
         */
        public static bool ExecuteHeaderToolIfNecessary(UEBuildTarget Target, CPPEnvironment GlobalCompileEnvironment, List <UHTModuleInfo> UObjectModules, string ModuleInfoFileName, ref ECompilationResult UHTResult)
        {
            if (ProgressWriter.bWriteMarkup)
            {
                Log.WriteLine(TraceEventType.Information, "@progress push 5%");
            }
            using (ProgressWriter Progress = new ProgressWriter("Generating code...", false))
            {
                // We never want to try to execute the header tool when we're already trying to build it!
                var bIsBuildingUHT = Target.GetTargetName().Equals("UnrealHeaderTool", StringComparison.InvariantCultureIgnoreCase);

                var BuildPlatform = UEBuildPlatform.GetBuildPlatform(Target.Platform);
                var CppPlatform   = BuildPlatform.GetCPPTargetPlatform(Target.Platform);
                var ToolChain     = UEToolChain.GetPlatformToolChain(CppPlatform);
                var RootLocalPath = Path.GetFullPath(ProjectFileGenerator.RootRelativePath);

                // check if UHT is out of date
                DateTime HeaderToolTimestamp = DateTime.MaxValue;
                bool     bHaveHeaderTool     = !bIsBuildingUHT && GetHeaderToolTimestamp(out HeaderToolTimestamp);

                // ensure the headers are up to date
                bool bUHTNeedsToRun = (UEBuildConfiguration.bForceHeaderGeneration == true || !bHaveHeaderTool || AreGeneratedCodeFilesOutOfDate(UObjectModules, HeaderToolTimestamp));
                if (bUHTNeedsToRun || UnrealBuildTool.IsGatheringBuild)
                {
                    // Since code files are definitely out of date, we'll now finish computing information about the UObject modules for UHT.  We
                    // want to save this work until we know that UHT actually needs to be run to speed up best-case iteration times.
                    if (UnrealBuildTool.IsGatheringBuild)                               // In assembler-only mode, PCH info is loaded from our UBTMakefile!
                    {
                        foreach (var UHTModuleInfo in UObjectModules)
                        {
                            // Only cache the PCH name if we don't already have one.  When running in 'gather only' mode, this will have already been cached
                            if (string.IsNullOrEmpty(UHTModuleInfo.PCH))
                            {
                                UHTModuleInfo.PCH = "";

                                // We need to figure out which PCH header this module is including, so that UHT can inject an include statement for it into any .cpp files it is synthesizing
                                var DependencyModuleCPP      = (UEBuildModuleCPP)Target.GetModuleByName(UHTModuleInfo.ModuleName);
                                var ModuleCompileEnvironment = DependencyModuleCPP.CreateModuleCompileEnvironment(GlobalCompileEnvironment);
                                DependencyModuleCPP.CachePCHUsageForModuleSourceFiles(ModuleCompileEnvironment);
                                if (DependencyModuleCPP.ProcessedDependencies.UniquePCHHeaderFile != null)
                                {
                                    UHTModuleInfo.PCH = DependencyModuleCPP.ProcessedDependencies.UniquePCHHeaderFile.AbsolutePath;
                                }
                            }
                        }
                    }
                }

                // @todo ubtmake: Optimization: Ideally we could avoid having to generate this data in the case where UHT doesn't even need to run!  Can't we use the existing copy?  (see below use of Manifest)
                UHTManifest Manifest = new UHTManifest(Target, RootLocalPath, ToolChain.ConvertPath(RootLocalPath + '\\'), UObjectModules);

                if (!bIsBuildingUHT && bUHTNeedsToRun)
                {
                    // Always build UnrealHeaderTool if header regeneration is required, unless we're running within a Rocket ecosystem or hot-reloading
                    if (UnrealBuildTool.RunningRocket() == false &&
                        UEBuildConfiguration.bDoNotBuildUHT == false &&
                        UEBuildConfiguration.bHotReloadFromIDE == false &&
                        !(bHaveHeaderTool && !UnrealBuildTool.IsGatheringBuild && UnrealBuildTool.IsAssemblingBuild))                                   // If running in "assembler only" mode, we assume UHT is already up to date for much faster iteration!
                    {
                        // If it is out of date or not there it will be built.
                        // If it is there and up to date, it will add 0.8 seconds to the build time.
                        Log.TraceInformation("Building UnrealHeaderTool...");

                        var UBTArguments = new StringBuilder();

                        UBTArguments.Append("UnrealHeaderTool");

                        // Which desktop platform do we need to compile UHT for?
                        UBTArguments.Append(" " + BuildHostPlatform.Current.Platform.ToString());
                        // NOTE: We force Development configuration for UHT so that it runs quickly, even when compiling debug
                        UBTArguments.Append(" " + UnrealTargetConfiguration.Development.ToString());

                        // NOTE: We disable mutex when launching UBT from within UBT to compile UHT
                        UBTArguments.Append(" -NoMutex");

                        if (UnrealBuildTool.CommandLineContains("-noxge"))
                        {
                            UBTArguments.Append(" -noxge");
                        }

                        // Propagate command-line option to switch back to old 2013 toolchain
                        if (UnrealBuildTool.CommandLineContains("-2013"))
                        {
                            UBTArguments.Append(" -2013");
                        }

                        if (RunExternalExecutable(UnrealBuildTool.GetUBTPath(), UBTArguments.ToString()) != 0)
                        {
                            return(false);
                        }
                    }

                    Progress.Write(1, 3);

                    var ActualTargetName = String.IsNullOrEmpty(Target.GetTargetName()) ? "UE4" : Target.GetTargetName();
                    Log.TraceInformation("Parsing headers for {0}", ActualTargetName);

                    string HeaderToolPath = GetHeaderToolPath();
                    if (!File.Exists(HeaderToolPath))
                    {
                        throw new BuildException("Unable to generate headers because UnrealHeaderTool binary was not found ({0}).", Path.GetFullPath(HeaderToolPath));
                    }

                    // Disable extensions when serializing to remove the $type fields
                    Directory.CreateDirectory(Path.GetDirectoryName(ModuleInfoFileName));
                    System.IO.File.WriteAllText(ModuleInfoFileName, fastJSON.JSON.Instance.ToJSON(Manifest, new fastJSON.JSONParameters {
                        UseExtensions = false
                    }));

                    string CmdLine = (UnrealBuildTool.HasUProjectFile()) ? "\"" + UnrealBuildTool.GetUProjectFile() + "\"" : Target.GetTargetName();
                    CmdLine += " \"" + ModuleInfoFileName + "\" -LogCmds=\"loginit warning, logexit warning, logdatabase error\"";
                    if (UnrealBuildTool.RunningRocket())
                    {
                        CmdLine += " -rocket -installed";
                    }

                    if (UEBuildConfiguration.bFailIfGeneratedCodeChanges)
                    {
                        CmdLine += " -FailIfGeneratedCodeChanges";
                    }

                    Log.TraceInformation("  Running UnrealHeaderTool {0}", CmdLine);

                    Stopwatch s = new Stopwatch();
                    s.Start();
                    UHTResult = (ECompilationResult)RunExternalExecutable(ExternalExecution.GetHeaderToolPath(), CmdLine);
                    s.Stop();

                    if (UHTResult != ECompilationResult.Succeeded)
                    {
                        // On Linux and Mac, the shell will return 128+signal number exit codes if UHT gets a signal (e.g. crashes or is interrupted)
                        if ((BuildHostPlatform.Current.Platform == UnrealTargetPlatform.Linux ||
                             BuildHostPlatform.Current.Platform == UnrealTargetPlatform.Mac) &&
                            (int)(UHTResult) >= 128
                            )
                        {
                            // SIGINT is 2, so 128 + SIGINT is 130
                            UHTResult = ((int)(UHTResult) == 130) ? ECompilationResult.Canceled : ECompilationResult.CrashOrAssert;
                        }

                        Log.TraceInformation("Error: Failed to generate code for {0} - error code: {2} ({1})", ActualTargetName, (int)UHTResult, UHTResult.ToString());
                        return(false);
                    }

                    Log.TraceInformation("Reflection code generated for {0} in {1} seconds", ActualTargetName, s.Elapsed.TotalSeconds);
                    if (BuildConfiguration.bPrintPerformanceInfo)
                    {
                        Log.TraceInformation("UnrealHeaderTool took {1}", ActualTargetName, (double)s.ElapsedMilliseconds / 1000.0);
                    }

                    // Now that UHT has successfully finished generating code, we need to update all cached FileItems in case their last write time has changed.
                    // Otherwise UBT might not detect changes UHT made.
                    DateTime StartTime = DateTime.UtcNow;
                    FileItem.ResetInfos();
                    double ResetDuration = (DateTime.UtcNow - StartTime).TotalSeconds;
                    Log.TraceVerbose("FileItem.ResetInfos() duration: {0}s", ResetDuration);
                }
                else
                {
                    Log.TraceVerbose("Generated code is up to date.");
                }

                Progress.Write(2, 3);

                // There will never be generated code if we're building UHT, so this should never be called.
                if (!bIsBuildingUHT)
                {
                    // Allow generated code to be sync'd to remote machines if needed. This needs to be done even if UHT did not run because
                    // generated headers include other generated headers using absolute paths which in case of building remotely are already
                    // the remote machine absolute paths. Because of that parsing headers will not result in finding all includes properly.
                    // @todo ubtmake: Need to figure out what this does in the assembler case, and whether we need to run it
                    ToolChain.PostCodeGeneration(Manifest);
                }

                // touch the directories
                UpdateDirectoryTimestamps(UObjectModules);

                Progress.Write(3, 3);
            }
            if (ProgressWriter.bWriteMarkup)
            {
                Log.WriteLine(TraceEventType.Information, "@progress pop");
            }
            return(true);
        }
Exemplo n.º 6
0
        private bool WriteCMakeLists()
        {
            string BuildCommand     = "";
            var    FileName         = "CMakeLists.txt";
            var    CMakefileContent = new StringBuilder();

            var CMakeSectionEnd = " )\n\n";

            var CMakeSourceFilesList = "set(SOURCE_FILES \n";
            var CMakeHeaderFilesList = "set(HEADER_FILES \n";
            var CMakeConfigFilesList = "set(CONFIG_FILES \n";

            var CMakeGameRootPath = "";
            var CMakeUE4RootPath  = "set(UE4_ROOT_PATH " + Path.GetFullPath(ProjectFileGenerator.RootRelativePath) + ")\n";

            string GameProjectPath = "";
            string GameProjectFile = "";

            string CMakeGameProjectFile = "";

            if (!String.IsNullOrEmpty(GameProjectName))
            {
                CMakeGameRootPath = "set(GAME_ROOT_PATH \"" + UnrealBuildTool.GetUProjectPath() + "\")\n";

                GameProjectPath = UnrealBuildTool.GetUProjectPath();
                GameProjectFile = UnrealBuildTool.GetUProjectFile();

                CMakeGameProjectFile = "set(GAME_PROJECT_FILE \"" + GameProjectFile + "\")\n";

                BuildCommand = "set(BUILD mono ${UE4_ROOT_PATH}/Engine/Binaries/DotNET/UnrealBuildTool.exe )\n";                 // -project=\"\\\"" + UnrealBuildTool.GetUProjectPath () + "/" + GameProjectName + ".uproject\\\"\")\n";
            }
            else
            {
                BuildCommand = "set(BUILD bash ${UE4_ROOT_PATH}/Engine/Build/BatchFiles/Linux/Build.sh)\n";
            }

            CMakefileContent.Append(
                "# Makefile generated by CMakefileGenerator.cs\n" +
                "# *DO NOT EDIT*\n\n" +
                "cmake_minimum_required (VERSION 2.6)\n" +
                "project (UE4)\n\n" +
                CMakeUE4RootPath +
                CMakeGameProjectFile +
                BuildCommand +
                CMakeGameRootPath + "\n"
                );

            // Create SourceFiles, HeaderFiles, and ConfigFiles sections.
            var AllModuleFiles = DiscoverModules();

            foreach (string CurModuleFile in AllModuleFiles)
            {
                var FoundFiles = SourceFileSearch.FindModuleSourceFiles(CurModuleFile, ExcludeNoRedistFiles: bExcludeNoRedistFiles);
                foreach (string CurSourceFile in FoundFiles)
                {
                    string SourceFileRelativeToRoot = Utils.MakePathRelativeTo(CurSourceFile, Path.Combine(EngineRelativePath));
                    // Exclude Windows, Mac, and iOS only files/folders.
                    // This got ugly quick.
                    if (!SourceFileRelativeToRoot.Contains("Source/ThirdParty/") &&
                        !SourceFileRelativeToRoot.Contains("/Windows/") &&
                        !SourceFileRelativeToRoot.Contains("/Mac/") &&
                        !SourceFileRelativeToRoot.Contains("/IOS/") &&
                        !SourceFileRelativeToRoot.Contains("/iOS/") &&
                        !SourceFileRelativeToRoot.Contains("/VisualStudioSourceCodeAccess/") &&
                        !SourceFileRelativeToRoot.Contains("/XCodeSourceCodeAccess/") &&
                        !SourceFileRelativeToRoot.Contains("/WmfMedia/") &&
                        !SourceFileRelativeToRoot.Contains("/IOSDeviceProfileSelector/") &&
                        !SourceFileRelativeToRoot.Contains("/WindowsDeviceProfileSelector/") &&
                        !SourceFileRelativeToRoot.Contains("/WindowsMoviePlayer/") &&
                        !SourceFileRelativeToRoot.Contains("/AppleMoviePlayer/") &&
                        !SourceFileRelativeToRoot.Contains("/MacGraphicsSwitching/") &&
                        !SourceFileRelativeToRoot.Contains("/Apple/") &&
                        !SourceFileRelativeToRoot.Contains("/WinRT/")
                        )
                    {
                        if (SourceFileRelativeToRoot.EndsWith(".cpp"))
                        {
                            if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                            {
                                // SourceFileRelativeToRoot = "Engine/" + SourceFileRelativeToRoot;
                                CMakeSourceFilesList += ("\t\"${UE4_ROOT_PATH}/Engine/" + SourceFileRelativeToRoot + "\"\n");
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(GameProjectName))
                                {
                                    // SourceFileRelativeToRoot = SourceFileRelativeToRoot.Substring (3);
                                    CMakeSourceFilesList += ("\t\"" + SourceFileRelativeToRoot.Substring(3) + "\"\n");
                                }
                                else
                                {
                                    CMakeSourceFilesList += ("\t\"${GAME_ROOT_PATH}/" + Utils.MakePathRelativeTo(CurSourceFile, GameProjectPath) + "\"\n");
                                }
                            }
                        }
                        if (SourceFileRelativeToRoot.EndsWith(".h"))
                        {
                            if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                            {
                                // SourceFileRelativeToRoot = "Engine/" + SourceFileRelativeToRoot;
                                CMakeHeaderFilesList += ("\t\"${UE4_ROOT_PATH}/Engine/" + SourceFileRelativeToRoot + "\"\n");
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(GameProjectName))
                                {
                                    // SourceFileRelativeToRoot = SourceFileRelativeToRoot.Substring (3);
                                    CMakeHeaderFilesList += ("\t\"" + SourceFileRelativeToRoot.Substring(3) + "\"\n");
                                }
                                else
                                {
                                    CMakeHeaderFilesList += ("\t\"${GAME_ROOT_PATH}/" + Utils.MakePathRelativeTo(CurSourceFile, GameProjectPath) + "\"\n");
                                }
                            }
                        }
                        if (SourceFileRelativeToRoot.EndsWith(".cs"))
                        {
                            if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                            {
                                // SourceFileRelativeToRoot = "Engine/" + SourceFileRelativeToRoot;
                                CMakeConfigFilesList += ("\t\"${UE4_ROOT_PATH}/Engine/" + SourceFileRelativeToRoot + "\"\n");
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(GameProjectName))
                                {
                                    // SourceFileRelativeToRoot = SourceFileRelativeToRoot.Substring (3);
                                    CMakeConfigFilesList += ("\t\"" + SourceFileRelativeToRoot.Substring(3) + "\"\n");
                                }
                                else
                                {
                                    CMakeConfigFilesList += ("\t\"${GAME_ROOT_PATH}/" + Utils.MakePathRelativeTo(CurSourceFile, GameProjectPath) + "\"\n");
                                };
                            }
                        }
                    }
                }
            }

            // Add section end to section strings;
            CMakeSourceFilesList += CMakeSectionEnd;
            CMakeHeaderFilesList += CMakeSectionEnd;
            CMakeConfigFilesList += CMakeSectionEnd;

            // Append sections to the CMakeLists.txt file
            CMakefileContent.Append(CMakeSourceFilesList);
            CMakefileContent.Append(CMakeHeaderFilesList);
            CMakefileContent.Append(CMakeConfigFilesList);

            string CMakeProjectCmdArg = "";

            foreach (string TargetFilePath in DiscoverTargets())
            {
                var TargetName = Utils.GetFilenameWithoutAnyExtensions(TargetFilePath);                         // Remove both ".cs" and ".

                foreach (UnrealTargetConfiguration CurConfiguration in Enum.GetValues(typeof(UnrealTargetConfiguration)))
                {
                    if (CurConfiguration != UnrealTargetConfiguration.Unknown && CurConfiguration != UnrealTargetConfiguration.Development)
                    {
                        if (UnrealBuildTool.IsValidConfiguration(CurConfiguration))
                        {
                            if (TargetName == GameProjectName || TargetName == (GameProjectName + "Editor"))
                            {
                                CMakeProjectCmdArg = " -project=\"\\\"${GAME_PROJECT_FILE}\\\"\"";
                            }
                            var ConfName = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration);
                            CMakefileContent.Append(String.Format("add_custom_target({0}-Linux-{1} ${{BUILD}} {2} {0} Linux {1} $(ARGS))\n", TargetName, ConfName, CMakeProjectCmdArg));
                        }
                    }
                }

                if (TargetName == GameProjectName || TargetName == (GameProjectName + "Editor"))
                {
                    CMakeProjectCmdArg = " -project=\"\\\"${GAME_PROJECT_FILE}\\\"\"";
                }
                CMakefileContent.Append(String.Format("add_custom_target({0} ${{BUILD}} {1} {0} Linux Development $(ARGS) SOURCES ${{SOURCE_FILES}} ${{HEADER_FILES}} ${{CONFIG_FILES}})\n\n", TargetName, CMakeProjectCmdArg));
            }

            var FullFileName = Path.Combine(MasterProjectRelativePath, FileName);

            return(WriteFileIfChanged(FullFileName, CMakefileContent.ToString()));
        }
Exemplo n.º 7
0
        private bool WriteQMakePro()
        {
            string GameProjectPath     = "";
            string GameProjectFile     = "";
            string GameProjectRootPath = "";

            string BuildCommand = "";

            string QMakeGameProjectFile = "";

            if (!String.IsNullOrEmpty(GameProjectName))
            {
                GameProjectPath      = UnrealBuildTool.GetUProjectPath();
                GameProjectFile      = UnrealBuildTool.GetUProjectFile();
                QMakeGameProjectFile = "gameProjectFile=" + GameProjectFile + "\n";
                BuildCommand         = "build=mono $$unrealRootPath/Engine/Binaries/DotNET/UnrealBuildTool.exe\n\n";
            }
            else
            {
                BuildCommand = "build=bash $$unrealRootPath/Engine/Build/BatchFiles/Linux/Build.sh\n";
            }

            var UnrealRootPath = Path.GetFullPath(ProjectFileGenerator.RootRelativePath);

            var FileName         = MasterProjectName + ".pro";
            var QMakeFileContent = new StringBuilder();

            var QMakeSectionEnd = " \n\n";

            var QMakeSourceFilesList = "SOURCES += \\ \n";
            var QMakeHeaderFilesList = "HEADERS += \\ \n";
            var QMakeConfigFilesList = "OTHER_FILES += \\ \n";
            var QMakeTargetList      = "QMAKE_EXTRA_TARGETS += \\ \n";

            if (!String.IsNullOrEmpty(GameProjectName))
            {
                GameProjectRootPath = GameProjectName + "RootPath=" + GameProjectPath + "\n\n";
            }

            QMakeFileContent.Append(
                "# UnrealEngine.pro generated by QMakefileGenerator.cs\n" +
                "# *DO NOT EDIT*\n\n" +
                "TEMPLATE = aux\n" +
                "CONFIG -= console\n" +
                "CONFIG -= app_bundle\n" +
                "CONFIG -= qt\n\n" +
                "TARGET = UE4 \n\n" +
                "unrealRootPath=" + UnrealRootPath + "\n" +
                GameProjectRootPath +
                QMakeGameProjectFile +
                BuildCommand +
                "args=$(ARGS)\n\n"
                );

            // Create SourceFiles, HeaderFiles, and ConfigFiles sections.
            var AllModuleFiles = DiscoverModules();

            foreach (string CurModuleFile in AllModuleFiles)
            {
                var FoundFiles = SourceFileSearch.FindModuleSourceFiles(CurModuleFile, ExcludeNoRedistFiles: bExcludeNoRedistFiles);
                foreach (string CurSourceFile in FoundFiles)
                {
                    string SourceFileRelativeToRoot = Utils.MakePathRelativeTo(CurSourceFile, Path.Combine(EngineRelativePath));
                    // Exclude Windows, Mac, and iOS only files/folders.
                    // This got ugly quick.
                    if (!SourceFileRelativeToRoot.Contains("Source/ThirdParty/") &&
                        !SourceFileRelativeToRoot.Contains("/Windows/") &&
                        !SourceFileRelativeToRoot.Contains("/Mac/") &&
                        !SourceFileRelativeToRoot.Contains("/IOS/") &&
                        !SourceFileRelativeToRoot.Contains("/iOS/") &&
                        !SourceFileRelativeToRoot.Contains("/VisualStudioSourceCodeAccess/") &&
                        !SourceFileRelativeToRoot.Contains("/XCodeSourceCodeAccess/") &&
                        !SourceFileRelativeToRoot.Contains("/WmfMedia/") &&
                        !SourceFileRelativeToRoot.Contains("/IOSDeviceProfileSelector/") &&
                        !SourceFileRelativeToRoot.Contains("/WindowsDeviceProfileSelector/") &&
                        !SourceFileRelativeToRoot.Contains("/WindowsMoviePlayer/") &&
                        !SourceFileRelativeToRoot.Contains("/AppleMoviePlayer/") &&
                        !SourceFileRelativeToRoot.Contains("/MacGraphicsSwitching/") &&
                        !SourceFileRelativeToRoot.Contains("/Apple/") &&
                        !SourceFileRelativeToRoot.Contains("/WinRT/")
                        )
                    {
                        if (SourceFileRelativeToRoot.EndsWith(".cpp"))
                        {
                            if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                            {
                                // SourceFileRelativeToRoot = "Engine/" + SourceFileRelativeToRoot;
                                QMakeSourceFilesList += ("\t\"" + "$$unrealRootPath/Engine/" + SourceFileRelativeToRoot + "\" \\\n");
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(GameProjectName))
                                {
                                    // SourceFileRelativeToRoot = SourceFileRelativeToRoot.Substring (3);
                                    QMakeSourceFilesList += ("\t\"" + SourceFileRelativeToRoot.Substring(3) + "\" \\\n");
                                }
                                else if (!String.IsNullOrEmpty(GameProjectName))
                                {
                                    QMakeSourceFilesList += ("\t\"$$" + GameProjectName + "RootPath/" + Utils.MakePathRelativeTo(CurSourceFile, GameProjectPath) + "\" \\\n");
                                }
                                else
                                {
                                    System.Console.WriteLine("Error!, you should not be here.");
                                }
                            }
                        }
                        if (SourceFileRelativeToRoot.EndsWith(".h"))
                        {
                            if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                            {
                                // SourceFileRelativeToRoot = "Engine/" + SourceFileRelativeToRoot;
                                QMakeHeaderFilesList += ("\t\"" + "$$unrealRootPath/Engine/" + SourceFileRelativeToRoot + "\" \\\n");
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(GameProjectName))
                                {
                                    // SourceFileRelativeToRoot = SourceFileRelativeToRoot.Substring (3);
                                    QMakeHeaderFilesList += ("\t\"" + SourceFileRelativeToRoot.Substring(3) + "\" \\\n");
                                }
                                else if (!String.IsNullOrEmpty(GameProjectName))
                                {
                                    QMakeHeaderFilesList += ("\t\"$$" + GameProjectName + "RootPath/" + Utils.MakePathRelativeTo(CurSourceFile, GameProjectPath) + "\" \\\n");
                                }
                                else
                                {
                                    System.Console.WriteLine("Error!, you should not be here.");
                                }
                            }
                        }
                        if (SourceFileRelativeToRoot.EndsWith(".cs"))
                        {
                            if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                            {
                                // SourceFileRelativeToRoot = "Engine/" + SourceFileRelativeToRoot;
                                QMakeConfigFilesList += ("\t\"" + "$$unrealRootPath/Engine/" + SourceFileRelativeToRoot + "\" \\\n");
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(GameProjectName))
                                {
                                    // SourceFileRelativeToRoot = SourceFileRelativeToRoot.Substring (3);
                                    QMakeConfigFilesList += ("\t\"" + SourceFileRelativeToRoot.Substring(3) + "\" \\\n");
                                }
                                else if (!String.IsNullOrEmpty(GameProjectName))
                                {
                                    QMakeConfigFilesList += ("\t\"$$" + GameProjectName + "RootPath/" + Utils.MakePathRelativeTo(CurSourceFile, GameProjectPath) + "\" \\\n");
                                }
                                else
                                {
                                    System.Console.WriteLine("Error!, you should not be here.");
                                }
                            }
                        }
                    }
                }
            }

            // Add section end to section strings;
            QMakeSourceFilesList += QMakeSectionEnd;
            QMakeHeaderFilesList += QMakeSectionEnd;
            QMakeConfigFilesList += QMakeSectionEnd;

            // Append sections to the QMakeLists.txt file
            QMakeFileContent.Append(QMakeSourceFilesList);
            QMakeFileContent.Append(QMakeHeaderFilesList);
            QMakeFileContent.Append(QMakeConfigFilesList);

            string QMakeProjectCmdArg = "";

            foreach (string TargetFilePath in DiscoverTargets())
            {
                var TargetName = Utils.GetFilenameWithoutAnyExtensions(TargetFilePath);                         // Remove both ".cs" and ".

                foreach (UnrealTargetConfiguration CurConfiguration in Enum.GetValues(typeof(UnrealTargetConfiguration)))
                {
                    if (CurConfiguration != UnrealTargetConfiguration.Unknown && CurConfiguration != UnrealTargetConfiguration.Development)
                    {
                        if (UnrealBuildTool.IsValidConfiguration(CurConfiguration))
                        {
                            if (TargetName == GameProjectName || TargetName == (GameProjectName + "Editor"))
                            {
                                QMakeProjectCmdArg = " -project=\"\\\"$$gameProjectFile\\\"\"";
                            }
                            var ConfName = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration);
                            QMakeFileContent.Append(String.Format("{0}-Linux-{1}.commands = $$build {2} {0} Linux {1} $$args\n", TargetName, ConfName, QMakeProjectCmdArg));
                            QMakeTargetList += "\t" + TargetName + "-Linux-" + ConfName + " \\\n";                             // , TargetName, ConfName);
                        }
                    }
                }

                if (TargetName == GameProjectName || TargetName == (GameProjectName + "Editor"))
                {
                    QMakeProjectCmdArg = " -project=\"\\\"$$gameProjectFile\\\"\"";
                }

                QMakeFileContent.Append(String.Format("{0}.commands = $$build {1} {0} Linux Development $$args\n\n", TargetName, QMakeProjectCmdArg));
                QMakeTargetList += "\t" + TargetName + " \\\n";
            }

            QMakeFileContent.Append(QMakeTargetList.TrimEnd('\\'));

            var FullFileName = Path.Combine(MasterProjectRelativePath, FileName);

            return(WriteFileIfChanged(FullFileName, QMakeFileContent.ToString()));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Write the Command Sub section for .kdev4/$ProjectName.kdev4 file
        /// </summary>
        /// <param name="FileContent">File content.</param>
        /// <param name="TargetName">Target name.</param>
        /// <param name="ConfName">Conf name.</param>
        /// <param name="BuildConfigIndex">Build config index.</param>
        /// <param name="Type">Type.</param>
        private void WriteCommandSubSection(ref StringBuilder FileContent, string TargetName, string ConfName, int BuildConfigIndex, int Type)
        {
            string ToolType      = "";
            string Executable    = "";
            string ProjectCmdArg = "";
            string BuildCommand  = "";

            if (TargetName == GameProjectName)
            {
                ProjectCmdArg = " -project=\"" + UnrealBuildTool.GetUProjectFile() + "\"";
                Executable    = "mono";
                BuildCommand  = "Engine/Binaries/DotNET/UnrealBuildTool.exe";

                if (Type == 1)
                {
                    ProjectCmdArg = " -makefile -kdevelopfile " + ProjectCmdArg + " -game -engine ";
                }
            }
            else if (TargetName == (GameProjectName + "Editor"))
            {
                ProjectCmdArg = " -editorrecompile -project=\"" + UnrealBuildTool.GetUProjectFile() + "\"";
                Executable    = "mono";
                BuildCommand  = "Engine/Binaries/DotNET/UnrealBuildTool.exe";

                if (Type == 1)
                {
                    ProjectCmdArg = " -makefile -kdevelopfile " + ProjectCmdArg + " -game -engine ";
                }
            }
            else
            {
                Executable   = "bash";
                BuildCommand = "Engine/Build/BatchFiles/Linux/Build.sh";

                if (Type == 1)
                {
                    // Override BuildCommand and ProjectCmdArg
                    BuildCommand = "./GenerateProjectFiles.sh";
                    // ProjectCmdArg = "";
                }
            }

            if (Type == 0)
            {
                ToolType = "Build";
            }
            else if (Type == 1)
            {
                ToolType = "Configure";
            }
            else if (Type == 3)
            {
                ToolType = "Clean";
                ConfName = ConfName + " -clean";
            }

            FileContent.Append(String.Format("[CustomBuildSystem][BuildConfig{0}][Tool{1}]\n", BuildConfigIndex, ToolType));
            FileContent.Append(String.Format("Arguments={0} {1} {2} Linux {3}\n", BuildCommand, ProjectCmdArg, TargetName, ConfName));
            FileContent.Append("Enabled=true\n");
            FileContent.Append("Environment=\n");
            FileContent.Append(String.Format("Executable={0}\n", Executable));
            FileContent.Append(String.Format("Type={0}\n\n", Type));
        }
Exemplo n.º 9
0
        private bool WriteCMakeLists()
        {
            string BuildCommand     = "";
            var    FileName         = "CMakeLists.txt";
            var    CMakefileContent = new StringBuilder();

            var CMakeSectionEnd = " )\n\n";

            var CMakeSourceFilesList        = "set(SOURCE_FILES \n";
            var CMakeHeaderFilesList        = "set(HEADER_FILES \n";
            var CMakeConfigFilesList        = "set(CONFIG_FILES \n";
            var IncludeDirectoriesList      = "include_directories( \n";
            var PreprocessorDefinitionsList = "add_definitions( \n";

            var CMakeGameRootPath = "";
            var CMakeUE4RootPath  = "set(UE4_ROOT_PATH " + Path.GetFullPath(ProjectFileGenerator.RootRelativePath) + ")\n";

            string GameProjectPath = "";
            string GameProjectFile = "";

            string CMakeGameProjectFile = "";

            bool bIsMac   = BuildHostPlatform.Current.Platform == UnrealTargetPlatform.Mac;
            bool bIsLinux = BuildHostPlatform.Current.Platform == UnrealTargetPlatform.Linux;
            bool bIsWin64 = BuildHostPlatform.Current.Platform == UnrealTargetPlatform.Win64;

            String HostArchitecture = null;

            if (bIsLinux)
            {
                HostArchitecture = "Linux";
            }
            else if (bIsMac)
            {
                HostArchitecture = "Mac";
            }
            else if (bIsWin64)
            {
                HostArchitecture = "Win64";
            }
            else
            {
                throw new BuildException("ERROR: CMakefileGenerator does not support this platform");
            }

            if (!String.IsNullOrEmpty(GameProjectName))
            {
                CMakeGameRootPath = "set(GAME_ROOT_PATH \"" + UnrealBuildTool.GetUProjectPath() + "\")\n";

                GameProjectPath = UnrealBuildTool.GetUProjectPath();
                GameProjectFile = UnrealBuildTool.GetUProjectFile();

                CMakeGameProjectFile = "set(GAME_PROJECT_FILE \"" + GameProjectFile + "\")\n";

                BuildCommand = "set(BUILD mono ${UE4_ROOT_PATH}/Engine/Binaries/DotNET/UnrealBuildTool.exe )\n";
            }
            else if (bIsLinux || bIsMac)
            {
                BuildCommand = String.Format("set(BUILD cd ${{UE4_ROOT_PATH}} && bash ${{UE4_ROOT_PATH}}/Engine/Build/BatchFiles/{0}/Build.sh)\n", HostArchitecture);
            }
            else if (bIsWin64)
            {
                BuildCommand = "set(BUILD bash ${{UE4_ROOT_PATH}}/Engine/Build/BatchFiles/Build.bat)\n";
            }

            CMakefileContent.Append(
                "# Makefile generated by CMakefileGenerator.cs\n" +
                "# *DO NOT EDIT*\n\n" +
                "cmake_minimum_required (VERSION 2.6)\n" +
                "project (UE4)\n\n" +
                CMakeUE4RootPath +
                CMakeGameProjectFile +
                BuildCommand +
                CMakeGameRootPath + "\n"
                );

            List <String> IncludeDirectories      = new List <String>();
            List <String> PreprocessorDefinitions = new List <String>();

            foreach (var CurProject in GeneratedProjectFiles)
            {
                foreach (var CurPath in CurProject.IntelliSenseIncludeSearchPaths)
                {
                    string IncludeDirectory = GetIncludeDirectory(CurPath, Path.GetDirectoryName(CurProject.ProjectFilePath));
                    if (IncludeDirectory != null && !IncludeDirectories.Contains(IncludeDirectory))
                    {
                        IncludeDirectories.Add(IncludeDirectory);
                    }
                }

                foreach (var CurDefinition in CurProject.IntelliSensePreprocessorDefinitions)
                {
                    string Definition          = CurDefinition;
                    string AlternateDefinition = Definition.Contains("=0") ? Definition.Replace("=0", "=1") : Definition.Replace("=1", "=0");
                    if (Definition.Equals("WITH_EDITORONLY_DATA=0") || Definition.Equals("WITH_DATABASE_SUPPORT=1"))
                    {
                        Definition = AlternateDefinition;
                    }
                    if (!PreprocessorDefinitions.Contains(Definition) && !PreprocessorDefinitions.Contains(AlternateDefinition) && !Definition.StartsWith("UE_ENGINE_DIRECTORY") && !Definition.StartsWith("ORIGINAL_FILE_NAME"))
                    {
                        PreprocessorDefinitions.Add(Definition);
                    }
                }
            }

            // Create SourceFiles, HeaderFiles, and ConfigFiles sections.
            var AllModuleFiles = DiscoverModules();

            foreach (string CurModuleFile in AllModuleFiles)
            {
                var FoundFiles = SourceFileSearch.FindModuleSourceFiles(CurModuleFile, ExcludeNoRedistFiles: bExcludeNoRedistFiles);
                foreach (string CurSourceFile in FoundFiles)
                {
                    string SourceFileRelativeToRoot = Utils.MakePathRelativeTo(CurSourceFile, Path.Combine(EngineRelativePath));
                    // Exclude files/folders on a per-platform basis.
                    if ((bIsLinux && IsLinuxFiltered(SourceFileRelativeToRoot)) || (bIsMac && IsMacFiltered(SourceFileRelativeToRoot)) ||
                        (bIsWin64 && IsWinFiltered(SourceFileRelativeToRoot))
                        )
                    {
                        if (SourceFileRelativeToRoot.EndsWith(".cpp"))
                        {
                            if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                            {
                                // SourceFileRelativeToRoot = "Engine/" + SourceFileRelativeToRoot;
                                CMakeSourceFilesList += ("\t\"${UE4_ROOT_PATH}/Engine/" + SourceFileRelativeToRoot + "\"\n");
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(GameProjectName))
                                {
                                    // SourceFileRelativeToRoot = SourceFileRelativeToRoot.Substring (3);
                                    CMakeSourceFilesList += ("\t\"" + SourceFileRelativeToRoot.Substring(3) + "\"\n");
                                }
                                else
                                {
                                    CMakeSourceFilesList += ("\t\"${GAME_ROOT_PATH}/" + Utils.MakePathRelativeTo(CurSourceFile, GameProjectPath) + "\"\n");
                                }
                            }
                        }
                        if (SourceFileRelativeToRoot.EndsWith(".h"))
                        {
                            if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                            {
                                // SourceFileRelativeToRoot = "Engine/" + SourceFileRelativeToRoot;
                                CMakeHeaderFilesList += ("\t\"${UE4_ROOT_PATH}/Engine/" + SourceFileRelativeToRoot + "\"\n");
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(GameProjectName))
                                {
                                    // SourceFileRelativeToRoot = SourceFileRelativeToRoot.Substring (3);
                                    CMakeHeaderFilesList += ("\t\"" + SourceFileRelativeToRoot.Substring(3) + "\"\n");
                                }
                                else
                                {
                                    CMakeHeaderFilesList += ("\t\"${GAME_ROOT_PATH}/" + Utils.MakePathRelativeTo(CurSourceFile, GameProjectPath) + "\"\n");
                                }
                            }
                        }
                        if (SourceFileRelativeToRoot.EndsWith(".cs"))
                        {
                            if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                            {
                                // SourceFileRelativeToRoot = "Engine/" + SourceFileRelativeToRoot;
                                CMakeConfigFilesList += ("\t\"${UE4_ROOT_PATH}/Engine/" + SourceFileRelativeToRoot + "\"\n");
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(GameProjectName))
                                {
                                    // SourceFileRelativeToRoot = SourceFileRelativeToRoot.Substring (3);
                                    CMakeConfigFilesList += ("\t\"" + SourceFileRelativeToRoot.Substring(3) + "\"\n");
                                }
                                else
                                {
                                    CMakeConfigFilesList += ("\t\"${GAME_ROOT_PATH}/" + Utils.MakePathRelativeTo(CurSourceFile, GameProjectPath) + "\"\n");
                                };
                            }
                        }
                    }
                }
            }

            foreach (string IncludeDirectory in IncludeDirectories)
            {
                IncludeDirectoriesList += ("\t\"" + IncludeDirectory + "\"\n");
            }

            foreach (string PreprocessorDefinition in PreprocessorDefinitions)
            {
                PreprocessorDefinitionsList += ("\t-D" + PreprocessorDefinition + "\n");
            }

            // Add section end to section strings;
            CMakeSourceFilesList        += CMakeSectionEnd;
            CMakeHeaderFilesList        += CMakeSectionEnd;
            CMakeConfigFilesList        += CMakeSectionEnd;
            IncludeDirectoriesList      += CMakeSectionEnd;
            PreprocessorDefinitionsList += CMakeSectionEnd;

            // Append sections to the CMakeLists.txt file
            CMakefileContent.Append(CMakeSourceFilesList);
            CMakefileContent.Append(CMakeHeaderFilesList);
            CMakefileContent.Append(CMakeConfigFilesList);
            CMakefileContent.Append(IncludeDirectoriesList);
            CMakefileContent.Append(PreprocessorDefinitionsList);

            string CMakeProjectCmdArg = "";

            foreach (var Project in GeneratedProjectFiles)
            {
                foreach (var TargetFile in Project.ProjectTargets)
                {
                    if (TargetFile.TargetFilePath == null)
                    {
                        continue;
                    }

                    var TargetName = Utils.GetFilenameWithoutAnyExtensions(TargetFile.TargetFilePath);                                  // Remove both ".cs" and ".

                    foreach (UnrealTargetConfiguration CurConfiguration in Enum.GetValues(typeof(UnrealTargetConfiguration)))
                    {
                        if (CurConfiguration != UnrealTargetConfiguration.Unknown && CurConfiguration != UnrealTargetConfiguration.Development)
                        {
                            if (UnrealBuildTool.IsValidConfiguration(CurConfiguration))
                            {
                                if (TargetName == GameProjectName || TargetName == (GameProjectName + "Editor"))
                                {
                                    CMakeProjectCmdArg = " -project=\"\\\"${GAME_PROJECT_FILE}\\\"\"";
                                }
                                var ConfName = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration);
                                CMakefileContent.Append(String.Format("add_custom_target({0}-{3}-{1} ${{BUILD}} {2} {0} {3} {1} $(ARGS))\n", TargetName, ConfName, CMakeProjectCmdArg, HostArchitecture));
                            }
                        }
                    }

                    if (TargetName == GameProjectName || TargetName == (GameProjectName + "Editor"))
                    {
                        CMakeProjectCmdArg = " -project=\"\\\"${GAME_PROJECT_FILE}\\\"\"";
                    }
                    if (HostArchitecture != null)
                    {
                        CMakefileContent.Append(String.Format("add_custom_target({0} ${{BUILD}} {1} {0} {2} Development $(ARGS) SOURCES ${{SOURCE_FILES}} ${{HEADER_FILES}} ${{CONFIG_FILES}})\n\n", TargetName, CMakeProjectCmdArg, HostArchitecture));
                    }
                }
            }

            var FullFileName = Path.Combine(MasterProjectRelativePath, FileName);

            return(WriteFileIfChanged(FullFileName, CMakefileContent.ToString()));
        }