private bool WriteCMakeLists()
        {
            var FileName         = "CMakeLists.txt";
            var CMakefileContent = new StringBuilder();

            CMakefileContent.Append(
                "# Makefile generated by MakefileGenerator.cs\n" +
                "# *DO NOT EDIT*\n\n" +
                "cmake_minimum_required (VERSION 2.6)\n" +
                "project (UE4)\n\n" +
                "set(BUILD ${CMAKE_SOURCE_DIR}/Engine/Build/BatchFiles/Linux/Build.sh)\n\n" +
                "set(SOURCE_FILES"
                );

            var AllModuleFiles = DiscoverModules();

            foreach (string CurModuleFile in AllModuleFiles)
            {
                CMakefileContent.Append("\n\t");

                var FoundFiles = SourceFileSearch.FindModuleSourceFiles(CurModuleFile, ExcludeNoRedistFiles: bExcludeNoRedistFiles);
                foreach (string CurSourceFile in FoundFiles)
                {
                    string SourceFileRelativeToRoot = Utils.MakePathRelativeTo(CurSourceFile, Path.Combine(EngineRelativePath));
                    if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot))
                    {
                        SourceFileRelativeToRoot = "Engine/" + SourceFileRelativeToRoot;
                    }
                    else
                    {
                        SourceFileRelativeToRoot = SourceFileRelativeToRoot.Substring(3);
                    }

                    CMakefileContent.Append(String.Format("\"{0}\" ", SourceFileRelativeToRoot));
                }
            }
            CMakefileContent.Append("\n)\n\n");
            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))
                        {
                            var ConfName = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration);
                            CMakefileContent.Append(String.Format("add_custom_target({0}-Linux-{1} ${{BUILD}} {0} Linux {1})\n", TargetName, ConfName));
                        }
                    }
                }

                CMakefileContent.Append(String.Format("add_custom_target({0} ${{BUILD}} {0} Linux Development SOURCES ${{SOURCE_FILES}})\n\n", TargetName));
            }
            var FullFileName = Path.Combine(MasterProjectRelativePath, FileName);

            return(WriteFileIfChanged(FullFileName, CMakefileContent.ToString()));
        }
예제 #2
0
        /// Finds mouse source files
        public static List <string> FindModuleSourceFiles(string ModuleRulesFile, bool ExcludeNoRedistFiles, bool SearchSubdirectories = true, bool IncludePrivateSourceCode = true)
        {
            // The module's "base directory" is simply the directory where its xxx.Build.cs file is stored.  We'll always
            // harvest source files for this module in this base directory directory and all of its sub-directories.
            var ModuleBaseDirectory = Path.GetDirectoryName(ModuleRulesFile);

            // Find all of the source files (and other files) and add them to the project
            var DirectoriesToSearch = new List <string>();

            DirectoriesToSearch.Add(ModuleBaseDirectory);
            var FoundFiles = SourceFileSearch.FindFiles(DirectoriesToSearch, ExcludeNoRedistFiles: ExcludeNoRedistFiles, SubdirectoryNamesToExclude: null, SearchSubdirectories: SearchSubdirectories, IncludePrivateSourceCode: IncludePrivateSourceCode);

            return(FoundFiles);
        }
예제 #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 ("");

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

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

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

            string BuildCommand = "";

            string QMakeGameProjectFile = "";

            foreach (ProjectFile CurProject in GeneratedProjectFiles)
            {
                QMakefileProjectFile QMakeProject = CurProject as QMakefileProjectFile;
                if (QMakeProject == null)
                {
                    Log.TraceInformation("QMakeProject == null");
                    continue;
                }

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

            // Remove duplicate paths from include dir and system include dir list
            IncludeDirectories       = IncludeDirectories.Distinct().ToList();
            SystemIncludeDirectories = SystemIncludeDirectories.Distinct().ToList();

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

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

                    SplitDefinitionAndValue(CurDefine, out define, out value);

                    if (!DefinesAndValues.Contains(define))
                    {
                        // Log.TraceInformation (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 (string 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 (string CurPath in IncludeDirectories)
            {
                QMakeIncludesPriFileContent.Append("\t");
                QMakeIncludesPriFileContent.Append(CurPath);
                QMakeIncludesPriFileContent.Append(" \\\n");
            }

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

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

            string UnrealRootPath = UnrealBuildTool.RootDirectory.FullName;

            string FileName = MasterProjectName + ".pro";

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

            StringBuilder QMakeFileContent = new StringBuilder();

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

            string QMakeSectionEnd = " \n\n";

            string QMakeSourceFilesList = "SOURCES += \\ \n";
            string QMakeHeaderFilesList = "HEADERS += \\ \n";
            string QMakeConfigFilesList = "OTHER_FILES += \\ \n";
            string 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 += c++14\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.
            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 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
                                {
                                    QMakeSourceFilesList += ("\t\"$$" + GameProjectName + "RootPath/" + Utils.MakePathRelativeTo(CurSourceFile.FullName, GameProjectPath) + "\" \\\n");
                                }
                            }
                        }
                        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
                                {
                                    QMakeHeaderFilesList += ("\t\"$$" + GameProjectName + "RootPath/" + Utils.MakePathRelativeTo(CurSourceFile.FullName, GameProjectPath) + "\" \\\n");
                                }
                            }
                        }
                        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
                                {
                                    QMakeConfigFilesList += ("\t\"$$" + GameProjectName + "RootPath/" + Utils.MakePathRelativeTo(CurSourceFile.FullName, GameProjectPath) + "\" \\\n");
                                }
                            }
                        }
                    }
                }
            }

            // 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 (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))
                            {
                                if (TargetName == GameProjectName || TargetName == (GameProjectName + "Editor"))
                                {
                                    QMakeProjectCmdArg = " -project=\"\\\"$$gameProjectFile\\\"\"";
                                }
                                string ConfName = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration);
                                QMakeFileContent.Append(String.Format("{0}-Linux-{1}.commands = $$build {0} Linux {1} {2} $$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 {0} Linux Development {1} $$args\n\n", TargetName, QMakeProjectCmdArg));
                    QMakeTargetList += "\t" + TargetName + " \\\n";
                }
            }

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

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

            string FullQMakeDefinesFileName   = Path.Combine(MasterProjectPath.FullName, QMakeDefinesFileName);
            string FullQMakeIncludesFileName  = Path.Combine(MasterProjectPath.FullName, QMakeIncludesFileName);
            string FullQMakeSourcePriFileName = Path.Combine(MasterProjectPath.FullName, QMakeSourcePriFileName);
            string FullQMakeHeaderPriFileName = Path.Combine(MasterProjectPath.FullName, QMakeHeaderPriFileName);
            string FullQMakeConfigPriFileName = Path.Combine(MasterProjectPath.FullName, 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()));
        }
예제 #4
0
 /// Finds mouse source files
 public static List <FileReference> FindModuleSourceFiles(FileReference ModuleRulesFile, bool SearchSubdirectories = true, HashSet <DirectoryReference> SearchedDirectories = null)
 {
     // The module's "base directory" is simply the directory where its xxx.Build.cs file is stored.  We'll always
     // harvest source files for this module in this base directory directory and all of its sub-directories.
     return(SourceFileSearch.FindFiles(ModuleRulesFile.Directory, SubdirectoryNamesToExclude: null, SearchSubdirectories: SearchSubdirectories, SearchedDirectories: SearchedDirectories));
 }
        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);
        }
예제 #6
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);
        }
예제 #7
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()));
        }
예제 #8
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()));
        }
예제 #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()));
        }