/// <summary>
        /// Whether the required external SDKs are installed for this platform
        /// </summary>
        protected override SDKStatus HasRequiredManualSDKInternal()
        {
            // FIXME: UBT should loop across all the architectures and compile for all the selected ones.

            // do not cache this value - it may be changed after sourcing OutputEnvVars.txt
            string BaseLinuxPath = GetBaseLinuxPathForArchitecture(LinuxPlatform.DefaultArchitecture);

            // BaseLinuxPath is specified
            if (!String.IsNullOrEmpty(BaseLinuxPath))
            {
                // paths to our toolchains
                BaseLinuxPath = BaseLinuxPath.Replace("\"", "");

                if (IsValidClangPath(new DirectoryReference(BaseLinuxPath)))
                {
                    return(SDKStatus.Valid);
                }
            }

            if (CanUseSystemCompiler())
            {
                if (!String.IsNullOrEmpty(LinuxCommon.WhichClang()) || !String.IsNullOrEmpty(LinuxCommon.WhichGcc()))
                {
                    return(SDKStatus.Valid);
                }
            }

            return(SDKStatus.Invalid);
        }
        private bool WriteCMakeLists()
        {
            string       BuildCommand;
            const string CMakeSectionEnd = " )\n\n";

            var CMakefileContent = new StringBuilder();

            StringBuilder CMakeSourceFilesList        = new StringBuilder("set(SOURCE_FILES \n");
            StringBuilder CMakeHeaderFilesList        = new StringBuilder("set(HEADER_FILES \n");
            StringBuilder CMakeConfigFilesList        = new StringBuilder("set(CONFIG_FILES \n");
            StringBuilder IncludeDirectoriesList      = new StringBuilder("include_directories( \n");
            StringBuilder PreprocessorDefinitionsList = new StringBuilder("add_definitions( \n");
            string        CMakeCC = "\n";
            string        CMakeC  = "\n";

            var CMakeGameRootPath = "";
            var CMakeUE4RootPath  = "set(UE4_ROOT_PATH " + Utils.CleanDirectorySeparators(UnrealBuildTool.RootDirectory.FullName, '/') + ")\n";

            string GameProjectPath      = "";
            string CMakeGameProjectFile = "";

            string HostArchitecture;

            switch (BuildHostPlatform.Current.Platform)
            {
            case UnrealTargetPlatform.Win64:
            {
                HostArchitecture = "Win64";
                BuildCommand     = "set(BUILD cmd /c \"${UE4_ROOT_PATH}/Engine/Build/BatchFiles/Build.bat\")\n";
                break;
            }

            case UnrealTargetPlatform.Mac:
            {
                MacToolChainSettings Settings = new MacToolChainSettings(false);
                HostArchitecture = "Mac";
                BuildCommand     = "set(BUILD cd \"${UE4_ROOT_PATH}\" && bash \"${UE4_ROOT_PATH}/Engine/Build/BatchFiles/" + HostArchitecture + "/Build.sh\")\n";
                CMakeCC          = "set(CMAKE_CXX_COMPILER " + Settings.ToolchainDir + "clang++)\n";
                CMakeC           = "set(CMAKE_C_COMPILER " + Settings.ToolchainDir + "clang)\n";
                break;
            }

            case UnrealTargetPlatform.Linux:
            {
                HostArchitecture = "Linux";
                BuildCommand     = "set(BUILD cd \"${UE4_ROOT_PATH}\" && bash \"${UE4_ROOT_PATH}/Engine/Build/BatchFiles/" + HostArchitecture + "/Build.sh\")\n";
                string Compiler = LinuxCommon.WhichClang();
                if (String.IsNullOrEmpty(Compiler))
                {
                    Compiler = LinuxCommon.WhichGcc();
                }
                // Should not be possible, but...
                if (String.IsNullOrEmpty(Compiler))
                {
                    Compiler = "clang++";
                }
                CMakeCC = "set(CMAKE_CXX_COMPILER \"" + Compiler + "\")\n";
                string CCompiler = Compiler.Replace("++", "");
                CMakeC = "set(CMAKE_C_COMPILER \"" + CCompiler + "\")\n";
                break;
            }

            default:
            {
                throw new BuildException("ERROR: CMakefileGenerator does not support this platform");
            }
            }

            if (!String.IsNullOrEmpty(GameProjectName))
            {
                GameProjectPath = OnlyGameProject.Directory.FullName;

                CMakeGameRootPath    = "set(GAME_ROOT_PATH \"" + Utils.CleanDirectorySeparators(OnlyGameProject.Directory.FullName, '/') + "\")\n";
                CMakeGameProjectFile = "set(GAME_PROJECT_FILE \"" + Utils.CleanDirectorySeparators(OnlyGameProject.FullName, '/') + "\")\n";
            }

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

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

            foreach (var CurProject in GeneratedProjectFiles)
            {
                foreach (var IncludeSearchPath in CurProject.IntelliSenseIncludeSearchPaths)
                {
                    string IncludeDirectory = GetIncludeDirectory(IncludeSearchPath, Path.GetDirectoryName(CurProject.ProjectFilePath.FullName));
                    if (IncludeDirectory != null && !IncludeDirectories.Contains(IncludeDirectory))
                    {
                        if (IncludeDirectory.Contains(UnrealBuildTool.RootDirectory.FullName))
                        {
                            IncludeDirectories.Add(IncludeDirectory.Replace(UnrealBuildTool.RootDirectory.FullName, "${UE4_ROOT_PATH}"));
                        }
                        else
                        {
                            IncludeDirectories.Add("${GAME_ROOT_PATH}/" + IncludeDirectory);
                        }
                    }
                }

                foreach (var PreProcessorDefinition in CurProject.IntelliSensePreprocessorDefinitions)
                {
                    string Definition          = PreProcessorDefinition;
                    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(FindGameProjects());

            foreach (FileReference CurModuleFile in AllModuleFiles)
            {
                var FoundFiles = SourceFileSearch.FindModuleSourceFiles(CurModuleFile);
                foreach (FileReference CurSourceFile in FoundFiles)
                {
                    string SourceFileRelativeToRoot = CurSourceFile.MakeRelativeTo(UnrealBuildTool.EngineDirectory);

                    // Exclude files/folders on a per-platform basis.
                    if (!IsPathExcludedOnPlatform(SourceFileRelativeToRoot, BuildHostPlatform.Current.Platform))
                    {
                        if (SourceFileRelativeToRoot.EndsWith(".cpp"))
                        {
                            if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                            {
                                CMakeSourceFilesList.Append("\t\"${UE4_ROOT_PATH}/Engine/" + Utils.CleanDirectorySeparators(SourceFileRelativeToRoot, '/') + "\"\n");
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(GameProjectName))
                                {
                                    CMakeSourceFilesList.Append("\t\"" + Utils.CleanDirectorySeparators(SourceFileRelativeToRoot, '/').Substring(3) + "\"\n");
                                }
                                else
                                {
                                    string RelativeGameSourcePath = Utils.MakePathRelativeTo(CurSourceFile.FullName, GameProjectPath);
                                    CMakeSourceFilesList.Append("\t\"${GAME_ROOT_PATH}/" + Utils.CleanDirectorySeparators(RelativeGameSourcePath, '/') + "\"\n");
                                }
                            }
                        }
                        else if (SourceFileRelativeToRoot.EndsWith(".h"))
                        {
                            if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                            {
                                CMakeHeaderFilesList.Append("\t\"${UE4_ROOT_PATH}/Engine/" + Utils.CleanDirectorySeparators(SourceFileRelativeToRoot, '/') + "\"\n");
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(GameProjectName))
                                {
                                    CMakeHeaderFilesList.Append("\t\"" + Utils.CleanDirectorySeparators(SourceFileRelativeToRoot, '/').Substring(3) + "\"\n");
                                }
                                else
                                {
                                    string relativeGameSourcePath = Utils.MakePathRelativeTo(CurSourceFile.FullName, GameProjectPath);
                                    CMakeHeaderFilesList.Append("\t\"${GAME_ROOT_PATH}/" + Utils.CleanDirectorySeparators(relativeGameSourcePath, '/') + "\"\n");
                                }
                            }
                        }
                        else if (SourceFileRelativeToRoot.EndsWith(".cs"))
                        {
                            if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                            {
                                CMakeConfigFilesList.Append("\t\"${UE4_ROOT_PATH}/Engine/" + Utils.CleanDirectorySeparators(SourceFileRelativeToRoot, '/') + "\"\n");
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(GameProjectName))
                                {
                                    CMakeConfigFilesList.Append("\t\"" + Utils.CleanDirectorySeparators(SourceFileRelativeToRoot, '/').Substring(3) + "\"\n");
                                }
                                else
                                {
                                    string relativeGameSourcePath = Utils.MakePathRelativeTo(CurSourceFile.FullName, GameProjectPath);
                                    CMakeConfigFilesList.Append("\t\"${GAME_ROOT_PATH}/" + Utils.CleanDirectorySeparators(relativeGameSourcePath, '/') + "\"\n");
                                }
                            }
                        }
                    }
                }
            }

            foreach (string IncludeDirectory in IncludeDirectories)
            {
                IncludeDirectoriesList.Append("\t\"" + Utils.CleanDirectorySeparators(IncludeDirectory, '/') + "\"\n");
            }

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

            // Add section end to section strings;
            CMakeSourceFilesList.Append(CMakeSectionEnd);
            CMakeHeaderFilesList.Append(CMakeSectionEnd);
            CMakeConfigFilesList.Append(CMakeSectionEnd);
            IncludeDirectoriesList.Append(CMakeSectionEnd);
            PreprocessorDefinitionsList.Append(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 = TargetFile.TargetFilePath.GetFileNameWithoutAnyExtensions();                               // 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}\"";
                                }

                                string ConfName = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration);
                                CMakefileContent.Append(String.Format("add_custom_target({0}-{3}-{1} ${{BUILD}} {0} {3} {1} {2} $(ARGS))\n", TargetName, ConfName, CMakeProjectCmdArg, HostArchitecture));
                            }
                        }
                    }

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

                    CMakefileContent.Append(String.Format("add_custom_target({0} ${{BUILD}} {0} {2} Development {1} $(ARGS) SOURCES ${{SOURCE_FILES}} ${{HEADER_FILES}} ${{CONFIG_FILES}})\n\n", TargetName, CMakeProjectCmdArg, HostArchitecture));
                }
            }

            // Append a dummy executable target
            CMakefileContent.AppendLine("add_executable(FakeTarget ${SOURCE_FILES})");

            var FullFileName = Path.Combine(MasterProjectPath.FullName, ProjectFileName);

            bool writeSuccess = WriteFileIfChanged(FullFileName, CMakefileContent.ToString());

            return(writeSuccess);
        }
Exemple #3
0
        private bool WriteCMakeLists()
        {
            string        BuildCommand;
            const string  CMakeSectionEnd  = " )\n\n";
            StringBuilder CMakefileContent = new StringBuilder();

            // Create Engine/Project specific lists
            StringBuilder CMakeEngineSourceFilesList  = new StringBuilder("set(ENGINE_SOURCE_FILES \n");
            StringBuilder CMakeProjectSourceFilesList = new StringBuilder("set(PROJECT_SOURCE_FILES \n");
            StringBuilder CMakeEngineHeaderFilesList  = new StringBuilder("set(ENGINE_HEADER_FILES \n");
            StringBuilder CMakeProjectHeaderFilesList = new StringBuilder("set(PROJECT_HEADER_FILES \n");
            StringBuilder CMakeEngineCSFilesList      = new StringBuilder("set(ENGINE_CSHARP_FILES \n");
            StringBuilder CMakeProjectCSFilesList     = new StringBuilder("set(PROJECT_CSHARP_FILES \n");
            StringBuilder CMakeEngineConfigFilesList  = new StringBuilder("set(ENGINE_CONFIG_FILES \n");
            StringBuilder CMakeProjectConfigFilesList = new StringBuilder("set(PROJECT_CONFIG_FILES \n");
            StringBuilder CMakeEngineShaderFilesList  = new StringBuilder("set(ENGINE_SHADER_FILES \n");
            StringBuilder CMakeProjectShaderFilesList = new StringBuilder("set(PROJECT_SHADER_FILES \n");

            StringBuilder IncludeDirectoriesList      = new StringBuilder("include_directories( \n");
            StringBuilder PreprocessorDefinitionsList = new StringBuilder("add_definitions( \n");

            string UE4RootPath          = Utils.CleanDirectorySeparators(UnrealBuildTool.RootDirectory.FullName, '/');
            string CMakeGameRootPath    = "";
            string GameProjectPath      = "";
            string CMakeGameProjectFile = "";

            string HostArchitecture;
            string SetCompiler = "";

            switch (BuildHostPlatform.Current.Platform)
            {
            case UnrealTargetPlatform.Win64:
            {
                HostArchitecture = "Win64";
                BuildCommand     = "call \"" + UE4RootPath + "/Engine/Build/BatchFiles/Build.bat\"";
                break;
            }

            case UnrealTargetPlatform.Mac:
            {
                HostArchitecture    = "Mac";
                BuildCommand        = "cd \"" + UE4RootPath + "\" && bash \"" + UE4RootPath + "/Engine/Build/BatchFiles/" + HostArchitecture + "/Build.sh\"";
                bIncludeIOSTargets  = true;
                bIncludeTVOSTargets = true;
                break;
            }

            case UnrealTargetPlatform.Linux:
            {
                HostArchitecture = "Linux";
                BuildCommand     = "cd \"" + UE4RootPath + "\" && bash \"" + UE4RootPath + "/Engine/Build/BatchFiles/" + HostArchitecture + "/Build.sh\"";

                string CompilerPath = LinuxCommon.WhichClang();
                if (CompilerPath == null)
                {
                    CompilerPath = LinuxCommon.WhichGcc();
                }
                SetCompiler = "set(CMAKE_CXX_COMPILER " + CompilerPath + ")\n\n";
                break;
            }

            default:
            {
                throw new BuildException("ERROR: CMakefileGenerator does not support this platform");
            }
            }

            if (IsProjectBuild)
            {
                GameProjectPath      = OnlyGameProject.Directory.FullName;
                CMakeGameRootPath    = Utils.CleanDirectorySeparators(OnlyGameProject.Directory.FullName, '/');
                CMakeGameProjectFile = Utils.CleanDirectorySeparators(OnlyGameProject.FullName, '/');
            }

            // Additional CMake file definitions
            string EngineHeadersFilePath  = FileReference.Combine(IntermediateProjectFilesPath, CMakeEngineHeadersFileName).ToNormalizedPath();
            string ProjectHeadersFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeProjectHeadersFileName).ToNormalizedPath();
            string EngineSourcesFilePath  = FileReference.Combine(IntermediateProjectFilesPath, CMakeEngineSourcesFileName).ToNormalizedPath();
            string ProjectSourcesFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeProjectSourcesFileName).ToNormalizedPath();
            string ProjectFilePath        = FileReference.Combine(IntermediateProjectFilesPath, CMakeProjectSourcesFileName).ToNormalizedPath();
            string IncludeFilePath        = FileReference.Combine(IntermediateProjectFilesPath, CMakeIncludesFileName).ToNormalizedPath();
            string EngineConfigsFilePath  = FileReference.Combine(IntermediateProjectFilesPath, CMakeEngineConfigsFileName).ToNormalizedPath();
            string ProjectConfigsFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeProjectConfigsFileName).ToNormalizedPath();
            string EngineCSFilePath       = FileReference.Combine(IntermediateProjectFilesPath, CMakeEngineCSFileName).ToNormalizedPath();
            string ProjectCSFilePath      = FileReference.Combine(IntermediateProjectFilesPath, CMakeProjectCSFileName).ToNormalizedPath();
            string EngineShadersFilePath  = FileReference.Combine(IntermediateProjectFilesPath, CMakeEngineShadersFileName).ToNormalizedPath();
            string ProjectShadersFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeProjectShadersFileName).ToNormalizedPath();
            string DefinitionsFilePath    = FileReference.Combine(IntermediateProjectFilesPath, CMakeDefinitionsFileName).ToNormalizedPath();

            CMakefileContent.Append(
                "# Makefile generated by CMakefileGenerator.cs (v1.2)\n" +
                "# *DO NOT EDIT*\n\n" +
                "cmake_minimum_required (VERSION 2.6)\n" +
                "project (UE4)\n\n" +
                "# CMake Flags\n" +
                "set(CMAKE_CXX_STANDARD 14)\n" +                 // Need to keep this updated
                "set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1 CACHE BOOL \"\" FORCE)\n" +
                "set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 1 CACHE BOOL \"\" FORCE)\n\n" +
                SetCompiler +
                "# Standard Includes\n" +
                "include(\"" + IncludeFilePath + "\")\n" +
                "include(\"" + DefinitionsFilePath + "\")\n" +
                "include(\"" + EngineHeadersFilePath + "\")\n" +
                "include(\"" + ProjectHeadersFilePath + "\")\n" +
                "include(\"" + EngineSourcesFilePath + "\")\n" +
                "include(\"" + ProjectSourcesFilePath + "\")\n" +
                "include(\"" + EngineCSFilePath + "\")\n" +
                "include(\"" + ProjectCSFilePath + "\")\n\n"
                );

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

            foreach (ProjectFile CurProject in GeneratedProjectFiles)
            {
                foreach (string IncludeSearchPath in CurProject.IntelliSenseIncludeSearchPaths)
                {
                    string IncludeDirectory = GetIncludeDirectory(IncludeSearchPath, Path.GetDirectoryName(CurProject.ProjectFilePath.FullName));
                    if (IncludeDirectory != null && !IncludeDirectories.Contains(IncludeDirectory))
                    {
                        if (IncludeDirectory.Contains(UnrealBuildTool.RootDirectory.FullName))
                        {
                            IncludeDirectories.Add(IncludeDirectory.Replace(UnrealBuildTool.RootDirectory.FullName, UE4RootPath));
                        }
                        else
                        {
                            // If the path isn't rooted, then it is relative to the game root
                            if (!Path.IsPathRooted(IncludeDirectory))
                            {
                                IncludeDirectories.Add(CMakeGameRootPath + "/" + IncludeDirectory);
                            }
                            else
                            {
                                // This is a rooted path like /usr/local/sometool/include
                                IncludeDirectories.Add(IncludeDirectory);
                            }
                        }
                    }
                }

                foreach (string PreProcessorDefinition in CurProject.IntelliSensePreprocessorDefinitions)
                {
                    string Definition          = PreProcessorDefinition.Replace("TEXT(\"", "").Replace("\")", "").Replace("()=", "=");
                    string AlternateDefinition = Definition.Contains("=0") ? Definition.Replace("=0", "=1") : Definition.Replace("=1", "=0");

                    if (Definition.Equals("WITH_EDITORONLY_DATA=0"))
                    {
                        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.
            List <FileReference> AllModuleFiles = DiscoverModules(FindGameProjects());

            foreach (FileReference CurModuleFile in AllModuleFiles)
            {
                List <FileReference> FoundFiles = SourceFileSearch.FindModuleSourceFiles(CurModuleFile);
                foreach (FileReference CurSourceFile in FoundFiles)
                {
                    string SourceFileRelativeToRoot = CurSourceFile.MakeRelativeTo(UnrealBuildTool.EngineDirectory);

                    // Exclude files/folders on a per-platform basis.
                    if (!IsPathExcludedOnPlatform(SourceFileRelativeToRoot, BuildHostPlatform.Current.Platform))
                    {
                        if (SourceFileRelativeToRoot.EndsWith(".cpp"))
                        {
                            AppendCleanedPathToList(CMakeEngineSourceFilesList, CMakeProjectSourceFilesList, SourceFileRelativeToRoot, CurSourceFile.FullName, GameProjectPath, UE4RootPath, CMakeGameRootPath);
                        }
                        else if (SourceFileRelativeToRoot.EndsWith(".h"))
                        {
                            AppendCleanedPathToList(CMakeEngineHeaderFilesList, CMakeProjectHeaderFilesList, SourceFileRelativeToRoot, CurSourceFile.FullName, GameProjectPath, UE4RootPath, CMakeGameRootPath);
                        }
                        else if (SourceFileRelativeToRoot.EndsWith(".cs"))
                        {
                            AppendCleanedPathToList(CMakeEngineCSFilesList, CMakeProjectCSFilesList, SourceFileRelativeToRoot, CurSourceFile.FullName, GameProjectPath, UE4RootPath, CMakeGameRootPath);
                        }
                        else if (SourceFileRelativeToRoot.EndsWith(".usf") || SourceFileRelativeToRoot.EndsWith(".ush"))
                        {
                            AppendCleanedPathToList(CMakeEngineShaderFilesList, CMakeProjectShaderFilesList, SourceFileRelativeToRoot, CurSourceFile.FullName, GameProjectPath, UE4RootPath, CMakeGameRootPath);
                        }
                        else if (SourceFileRelativeToRoot.EndsWith(".ini"))
                        {
                            AppendCleanedPathToList(CMakeEngineConfigFilesList, CMakeProjectConfigFilesList, SourceFileRelativeToRoot, CurSourceFile.FullName, GameProjectPath, UE4RootPath, CMakeGameRootPath);
                        }
                    }
                }
            }

            foreach (string IncludeDirectory in IncludeDirectories)
            {
                IncludeDirectoriesList.Append("\t\"" + Utils.CleanDirectorySeparators(IncludeDirectory, '/') + "\"\n");
            }

            foreach (string PreprocessorDefinition in PreprocessorDefinitions)
            {
                int EqPos = PreprocessorDefinition.IndexOf("=");
                if (EqPos >= 0)
                {
                    string Key   = PreprocessorDefinition.Substring(0, EqPos);
                    string Value = PreprocessorDefinition.Substring(EqPos).Replace("\"", "\\\"");
                    PreprocessorDefinitionsList.Append("\t\"-D" + Key + Value + "\"\n");
                }
                else
                {
                    PreprocessorDefinitionsList.Append("\t\"-D" + PreprocessorDefinition + "\"\n");
                }
            }

            // Add Engine/Shaders files (game are added via modules)
            List <FileReference> EngineShaderFiles = SourceFileSearch.FindFiles(DirectoryReference.Combine(UnrealBuildTool.EngineDirectory, "Shaders"));

            foreach (FileReference CurSourceFile in EngineShaderFiles)
            {
                string SourceFileRelativeToRoot = CurSourceFile.MakeRelativeTo(UnrealBuildTool.EngineDirectory);
                if (SourceFileRelativeToRoot.EndsWith(".usf") || SourceFileRelativeToRoot.EndsWith(".ush"))
                {
                    AppendCleanedPathToList(CMakeEngineShaderFilesList, CMakeProjectShaderFilesList, SourceFileRelativeToRoot, CurSourceFile.FullName, GameProjectPath, UE4RootPath, CMakeGameRootPath);
                }
            }

            // Add Engine/Config ini files (game are added via modules)
            List <FileReference> EngineConfigFiles = SourceFileSearch.FindFiles(DirectoryReference.Combine(UnrealBuildTool.EngineDirectory, "Config"));

            foreach (FileReference CurSourceFile in EngineConfigFiles)
            {
                string SourceFileRelativeToRoot = CurSourceFile.MakeRelativeTo(UnrealBuildTool.EngineDirectory);
                if (SourceFileRelativeToRoot.EndsWith(".ini"))
                {
                    AppendCleanedPathToList(CMakeEngineConfigFilesList, CMakeProjectConfigFilesList, SourceFileRelativeToRoot, CurSourceFile.FullName, GameProjectPath, UE4RootPath, CMakeGameRootPath);
                }
            }

            // Add section end to section strings;
            CMakeEngineSourceFilesList.Append(CMakeSectionEnd);
            CMakeEngineHeaderFilesList.Append(CMakeSectionEnd);
            CMakeEngineCSFilesList.Append(CMakeSectionEnd);
            CMakeEngineConfigFilesList.Append(CMakeSectionEnd);
            CMakeEngineShaderFilesList.Append(CMakeSectionEnd);

            CMakeProjectSourceFilesList.Append(CMakeSectionEnd);
            CMakeProjectHeaderFilesList.Append(CMakeSectionEnd);
            CMakeProjectCSFilesList.Append(CMakeSectionEnd);
            CMakeProjectConfigFilesList.Append(CMakeSectionEnd);
            CMakeProjectShaderFilesList.Append(CMakeSectionEnd);

            IncludeDirectoriesList.Append(CMakeSectionEnd);
            PreprocessorDefinitionsList.Append(CMakeSectionEnd);

            if (bIncludeShaderSource)
            {
                CMakefileContent.Append("# Optional Shader Include\n");
                if (!IsProjectBuild || bIncludeEngineSource)
                {
                    CMakefileContent.Append("include(\"" + EngineShadersFilePath + "\")\n");
                    CMakefileContent.Append("set_source_files_properties(${ENGINE_SHADER_FILES} PROPERTIES HEADER_FILE_ONLY TRUE)\n");
                }
                CMakefileContent.Append("include(\"" + ProjectShadersFilePath + "\")\n");
                CMakefileContent.Append("set_source_files_properties(${PROJECT_SHADER_FILES} PROPERTIES HEADER_FILE_ONLY TRUE)\n");
                CMakefileContent.Append("source_group(\"Shader Files\" REGULAR_EXPRESSION .*.usf)\n\n");
            }

            if (bIncludeConfigFiles)
            {
                CMakefileContent.Append("# Optional Config Include\n");
                if (!IsProjectBuild || bIncludeEngineSource)
                {
                    CMakefileContent.Append("include(\"" + EngineConfigsFilePath + "\")\n");
                    CMakefileContent.Append("set_source_files_properties(${ENGINE_CONFIG_FILES} PROPERTIES HEADER_FILE_ONLY TRUE)\n");
                }
                CMakefileContent.Append("include(\"" + ProjectConfigsFilePath + "\")\n");
                CMakefileContent.Append("set_source_files_properties(${PROJECT_CONFIG_FILES} PROPERTIES HEADER_FILE_ONLY TRUE)\n");
                CMakefileContent.Append("source_group(\"Config Files\" REGULAR_EXPRESSION .*.ini)\n\n");
            }

            string CMakeProjectCmdArg = "";
            string UBTArguements      = "";

            if (bGeneratingGameProjectFiles)
            {
                UBTArguements += " -game";
            }
            // Should the builder output progress ticks
            if (ProgressWriter.bWriteMarkup)
            {
                UBTArguements += " -progress";
            }

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

                    string TargetName = TargetFile.TargetFilePath.GetFileNameWithoutAnyExtensions();                           // Remove both ".cs" and ".

                    foreach (UnrealTargetConfiguration CurConfiguration in Enum.GetValues(typeof(UnrealTargetConfiguration)))
                    {
                        if (CurConfiguration != UnrealTargetConfiguration.Unknown && CurConfiguration != UnrealTargetConfiguration.Development)
                        {
                            if (InstalledPlatformInfo.IsValidConfiguration(CurConfiguration, EProjectType.Code) && !IsTargetExcluded(TargetName, BuildHostPlatform.Current.Platform, CurConfiguration))
                            {
                                if (TargetName == GameProjectName || TargetName == (GameProjectName + "Editor"))
                                {
                                    CMakeProjectCmdArg = "\"-project=" + CMakeGameProjectFile + "\"";
                                }

                                string ConfName = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration);
                                CMakefileContent.Append(String.Format("add_custom_target({0}-{3}-{1} {5} {0} {3} {1} {2}{4} -buildscw VERBATIM)\n", TargetName, ConfName, CMakeProjectCmdArg, HostArchitecture, UBTArguements, BuildCommand));

                                // Add iOS and TVOS targets if valid
                                if (bIncludeIOSTargets && !IsTargetExcluded(TargetName, UnrealTargetPlatform.IOS, CurConfiguration))
                                {
                                    CMakefileContent.Append(String.Format("add_custom_target({0}-{3}-{1} {5} {0} {3} {1} {2}{4} VERBATIM)\n", TargetName, ConfName, CMakeProjectCmdArg, UnrealTargetPlatform.IOS, UBTArguements, BuildCommand));
                                }
                                if (bIncludeTVOSTargets && !IsTargetExcluded(TargetName, UnrealTargetPlatform.TVOS, CurConfiguration))
                                {
                                    CMakefileContent.Append(String.Format("add_custom_target({0}-{3}-{1} {5} {0} {3} {1} {2}{4} VERBATIM)\n", TargetName, ConfName, CMakeProjectCmdArg, UnrealTargetPlatform.TVOS, UBTArguements, BuildCommand));
                                }
                            }
                        }
                    }
                    if (!IsTargetExcluded(TargetName, BuildHostPlatform.Current.Platform, UnrealTargetConfiguration.Development))
                    {
                        if (TargetName == GameProjectName || TargetName == (GameProjectName + "Editor"))
                        {
                            CMakeProjectCmdArg = "\"-project=" + CMakeGameProjectFile + "\"";
                        }

                        CMakefileContent.Append(String.Format("add_custom_target({0} {4} {0} {2} Development {1}{3} -buildscw VERBATIM)\n\n", TargetName, CMakeProjectCmdArg, HostArchitecture, UBTArguements, BuildCommand));

                        // Add iOS and TVOS targets if valid
                        if (bIncludeIOSTargets && !IsTargetExcluded(TargetName, UnrealTargetPlatform.IOS, UnrealTargetConfiguration.Development))
                        {
                            CMakefileContent.Append(String.Format("add_custom_target({0}-{3} {5} {0} {3} {1} {2}{4} VERBATIM)\n", TargetName, UnrealTargetConfiguration.Development, CMakeProjectCmdArg, UnrealTargetPlatform.IOS, UBTArguements, BuildCommand));
                        }
                        if (bIncludeTVOSTargets && !IsTargetExcluded(TargetName, UnrealTargetPlatform.TVOS, UnrealTargetConfiguration.Development))
                        {
                            CMakefileContent.Append(String.Format("add_custom_target({0}-{3} {5} {0} {3} {1} {2}{4} VERBATIM)\n", TargetName, UnrealTargetConfiguration.Development, CMakeProjectCmdArg, UnrealTargetPlatform.TVOS, UBTArguements, BuildCommand));
                        }
                    }
                }
            }

            // Create Build Template
            if (IsProjectBuild && !bIncludeEngineSource)
            {
                CMakefileContent.AppendLine("add_executable(FakeTarget ${PROJECT_HEADER_FILES} ${PROJECT_SOURCE_FILES} ${PROJECT_CSHARP_FILES} ${PROJECT_SHADER_FILES} ${PROJECT_CONFIG_FILES})");
            }
            else
            {
                CMakefileContent.AppendLine("add_executable(FakeTarget ${ENGINE_HEADER_FILES} ${ENGINE_SOURCE_FILES} ${ENGINE_CSHARP_FILES} ${ENGINE_SHADER_FILES} ${ENGINE_CONFIG_FILES} ${PROJECT_HEADER_FILES} ${PROJECT_SOURCE_FILES} ${PROJECT_CSHARP_FILES} ${PROJECT_SHADER_FILES} ${PROJECT_CONFIG_FILES})");
            }

            string FullFileName = Path.Combine(MasterProjectPath.FullName, ProjectFileName);

            // Write out CMake files
            bool bWriteMakeList       = WriteFileIfChanged(FullFileName, CMakefileContent.ToString());
            bool bWriteEngineHeaders  = WriteFileIfChanged(EngineHeadersFilePath, CMakeEngineHeaderFilesList.ToString());
            bool bWriteProjectHeaders = WriteFileIfChanged(ProjectHeadersFilePath, CMakeProjectHeaderFilesList.ToString());
            bool bWriteEngineSources  = WriteFileIfChanged(EngineSourcesFilePath, CMakeEngineSourceFilesList.ToString());
            bool bWriteProjectSources = WriteFileIfChanged(ProjectSourcesFilePath, CMakeProjectSourceFilesList.ToString());
            bool bWriteIncludes       = WriteFileIfChanged(IncludeFilePath, IncludeDirectoriesList.ToString());
            bool bWriteDefinitions    = WriteFileIfChanged(DefinitionsFilePath, PreprocessorDefinitionsList.ToString());
            bool bWriteEngineConfigs  = WriteFileIfChanged(EngineConfigsFilePath, CMakeEngineConfigFilesList.ToString());
            bool bWriteProjectConfigs = WriteFileIfChanged(ProjectConfigsFilePath, CMakeProjectConfigFilesList.ToString());
            bool bWriteEngineShaders  = WriteFileIfChanged(EngineShadersFilePath, CMakeEngineShaderFilesList.ToString());
            bool bWriteProjectShaders = WriteFileIfChanged(ProjectShadersFilePath, CMakeProjectShaderFilesList.ToString());
            bool bWriteEngineCS       = WriteFileIfChanged(EngineCSFilePath, CMakeEngineCSFilesList.ToString());
            bool bWriteProjectCS      = WriteFileIfChanged(ProjectCSFilePath, CMakeProjectCSFilesList.ToString());

            // Return success flag if all files were written out successfully
            return(bWriteMakeList &&
                   bWriteEngineHeaders && bWriteProjectHeaders &&
                   bWriteEngineSources && bWriteProjectSources &&
                   bWriteEngineConfigs && bWriteProjectConfigs &&
                   bWriteEngineCS && bWriteProjectCS &&
                   bWriteEngineShaders && bWriteProjectShaders &&
                   bWriteIncludes && bWriteDefinitions);
        }