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())); }
private bool WriteMakefile() { var FileName = "Makefile"; // MasterProjectName + ".mk"; var MakefileContent = new StringBuilder(); MakefileContent.Append( "# Makefile generated by MakefileGenerator.cs\n" + "# *DO NOT EDIT*\n\n" + "TARGETS =" ); foreach (string Target in DiscoverTargets()) { var Basename = Path.GetFileNameWithoutExtension(Target); Basename = Path.GetFileNameWithoutExtension(Basename); foreach (UnrealTargetConfiguration CurConfiguration in Enum.GetValues(typeof(UnrealTargetConfiguration))) { if (CurConfiguration != UnrealTargetConfiguration.Unknown && CurConfiguration != UnrealTargetConfiguration.Development) { if (UnrealBuildTool.IsValidConfiguration(CurConfiguration)) { var Confname = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration); MakefileContent.Append(String.Format(" \\\n {0}-Linux-{1}", Basename, Confname)); } } } MakefileContent.Append(" \\\n " + Basename); } MakefileContent.Append("\n\nBUILD = Engine/Build/BatchFiles/Linux/Build.sh\n\n" + "all: $(TARGETS)\n" ); foreach (string Target in DiscoverTargets()) { var Basename = Path.GetFileNameWithoutExtension(Target); Basename = Path.GetFileNameWithoutExtension(Basename); foreach (UnrealTargetConfiguration CurConfiguration in Enum.GetValues(typeof(UnrealTargetConfiguration))) { if (CurConfiguration != UnrealTargetConfiguration.Unknown && CurConfiguration != UnrealTargetConfiguration.Development) { if (UnrealBuildTool.IsValidConfiguration(CurConfiguration)) { var Confname = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration); MakefileContent.Append(String.Format("\n{0}-Linux-{1}:\n\t$(BUILD) {0} Linux {1} $(ARGS)\n", Basename, Confname)); } } } MakefileContent.Append(String.Format("\n{0}:\n\t$(BUILD) {0} Linux Development $(ARGS)\n", Basename)); } MakefileContent.Append("\n.PHONY: $(TARGETS)\n"); var FullFileName = Path.Combine(MasterProjectRelativePath, FileName); return(WriteFileIfChanged(FullFileName, MakefileContent.ToString())); }
private bool WriteQMakePro() { // Some more stuff borrowed from Mac side of things. List <string> IncludeDirectories = new List <string>(); List <string> SystemIncludeDirectories = new List <string>(); List <string> DefinesAndValues = new List <string> (); // DefineList.Add (""); var QMakeIncludesFileName = MasterProjectName + "Includes.pri"; var QMakeIncludesPriFileContent = new StringBuilder(); var QMakeDefinesFileName = MasterProjectName + "Defines.pri"; var QMakeDefinesPriFileContent = new StringBuilder(); string GameProjectPath = ""; string GameProjectFile = ""; string GameProjectRootPath = ""; string BuildCommand = ""; string QMakeGameProjectFile = ""; foreach (var CurProject in GeneratedProjectFiles) { QMakefileProjectFile QMakeProject = CurProject as QMakefileProjectFile; if (QMakeProject == null) { System.Console.WriteLine("QMakeProject == null"); continue; } foreach (var CurPath in QMakeProject.IntelliSenseIncludeSearchPaths) { AddIncludeDirectory(ref IncludeDirectories, CurPath, Path.GetDirectoryName(QMakeProject.ProjectFilePath)); // System.Console.WriteLine ("Not empty now? CurPath == ", CurPath); } foreach (var CurPath in QMakeProject.IntelliSenseSystemIncludeSearchPaths) { AddIncludeDirectory(ref SystemIncludeDirectories, CurPath, Path.GetDirectoryName(QMakeProject.ProjectFilePath)); } } // Iterate through all the defines for the projects that are generated by // UnrealBuildTool.exe // !RAKE: move to seperate function QMakeDefinesPriFileContent.Append("DEFINES += \\\n"); foreach (var CurProject in GeneratedProjectFiles) { QMakefileProjectFile QMakeProject = CurProject as QMakefileProjectFile; if (QMakeProject == null) { System.Console.WriteLine("QMakeProject == null"); continue; } foreach (var CurDefine in QMakeProject.IntelliSensePreprocessorDefinitions) { String define = ""; String value = ""; SplitDefinitionAndValue(CurDefine, out define, out value); if (!DefinesAndValues.Contains(define)) { // System.Console.WriteLine (CurDefine); if (string.IsNullOrEmpty(value)) { DefinesAndValues.Add("\t"); DefinesAndValues.Add(String.Format("{0}=", define)); DefinesAndValues.Add(" \\\n"); } else { DefinesAndValues.Add("\t"); DefinesAndValues.Add(define); DefinesAndValues.Add("="); DefinesAndValues.Add(value); DefinesAndValues.Add(" \\\n"); } } } } foreach (var Def in DefinesAndValues) { QMakeDefinesPriFileContent.Append(Def); } // Iterate through all the include paths that // UnrealBuildTool.exe generates // !RAKE: Move to seperate function QMakeIncludesPriFileContent.Append("INCLUDEPATH += \\\n"); foreach (var CurPath in IncludeDirectories) { QMakeIncludesPriFileContent.Append("\t"); QMakeIncludesPriFileContent.Append(CurPath); QMakeIncludesPriFileContent.Append(" \\\n"); } foreach (var CurPath in SystemIncludeDirectories) { QMakeIncludesPriFileContent.Append("\t"); QMakeIncludesPriFileContent.Append(CurPath); QMakeIncludesPriFileContent.Append(" \\\n"); } QMakeIncludesPriFileContent.Append("\n"); if (!String.IsNullOrEmpty(GameProjectName)) { GameProjectPath = UnrealBuildTool.GetUProjectPath(); GameProjectFile = UnrealBuildTool.GetUProjectFile(); QMakeGameProjectFile = "gameProjectFile=" + GameProjectFile + "\n"; BuildCommand = "build=mono $$unrealRootPath/Engine/Binaries/DotNET/UnrealBuildTool.exe\n\n"; } else { BuildCommand = "build=bash $$unrealRootPath/Engine/Build/BatchFiles/Linux/Build.sh\n"; } var UnrealRootPath = Path.GetFullPath(ProjectFileGenerator.RootRelativePath); var FileName = MasterProjectName + ".pro"; var QMakeSourcePriFileName = MasterProjectName + "Source.pri"; var QMakeHeaderPriFileName = MasterProjectName + "Header.pri"; var QMakeConfigPriFileName = MasterProjectName + "Config.pri"; var QMakeFileContent = new StringBuilder(); var QMakeSourcePriFileContent = new StringBuilder(); var QMakeHeaderPriFileContent = new StringBuilder(); var QMakeConfigPriFileContent = new StringBuilder(); var QMakeSectionEnd = " \n\n"; var QMakeSourceFilesList = "SOURCES += \\ \n"; var QMakeHeaderFilesList = "HEADERS += \\ \n"; var QMakeConfigFilesList = "OTHER_FILES += \\ \n"; var QMakeTargetList = "QMAKE_EXTRA_TARGETS += \\ \n"; if (!String.IsNullOrEmpty(GameProjectName)) { GameProjectRootPath = GameProjectName + "RootPath=" + GameProjectPath + "\n\n"; } QMakeFileContent.Append( "# UnrealEngine.pro generated by QMakefileGenerator.cs\n" + "# *DO NOT EDIT*\n\n" + "TEMPLATE = aux\n" + "CONFIG -= console\n" + "CONFIG -= app_bundle\n" + "CONFIG -= qt\n\n" + "TARGET = UE4 \n\n" + "unrealRootPath=" + UnrealRootPath + "\n" + GameProjectRootPath + QMakeGameProjectFile + BuildCommand + "args=$(ARGS)\n\n" + "include(" + QMakeSourcePriFileName + ")\n" + "include(" + QMakeHeaderPriFileName + ")\n" + "include(" + QMakeConfigPriFileName + ")\n" + "include(" + QMakeIncludesFileName + ")\n" + "include(" + QMakeDefinesFileName + ")\n\n" ); // Create SourceFiles, HeaderFiles, and ConfigFiles sections. var AllModuleFiles = DiscoverModules(); foreach (string CurModuleFile in AllModuleFiles) { var FoundFiles = SourceFileSearch.FindModuleSourceFiles(CurModuleFile, ExcludeNoRedistFiles: bExcludeNoRedistFiles); foreach (string CurSourceFile in FoundFiles) { string SourceFileRelativeToRoot = Utils.MakePathRelativeTo(CurSourceFile, Path.Combine(EngineRelativePath)); // Exclude some directories that we don't compile (note that we still want Windows/Mac etc for code navigation) if (!SourceFileRelativeToRoot.Contains("Source/ThirdParty/")) { if (SourceFileRelativeToRoot.EndsWith(".cpp")) { if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot)) { QMakeSourceFilesList += ("\t\"" + "$$unrealRootPath/Engine/" + SourceFileRelativeToRoot + "\" \\\n"); } else { if (String.IsNullOrEmpty(GameProjectName)) { QMakeSourceFilesList += ("\t\"" + SourceFileRelativeToRoot.Substring(3) + "\" \\\n"); } else if (!String.IsNullOrEmpty(GameProjectName)) { QMakeSourceFilesList += ("\t\"$$" + GameProjectName + "RootPath/" + Utils.MakePathRelativeTo(CurSourceFile, GameProjectPath) + "\" \\\n"); } else { System.Console.WriteLine("Error!, you should not be here."); } } } if (SourceFileRelativeToRoot.EndsWith(".h")) { if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot)) { // SourceFileRelativeToRoot = "Engine/" + SourceFileRelativeToRoot; QMakeHeaderFilesList += ("\t\"" + "$$unrealRootPath/Engine/" + SourceFileRelativeToRoot + "\" \\\n"); } else { if (String.IsNullOrEmpty(GameProjectName)) { // SourceFileRelativeToRoot = SourceFileRelativeToRoot.Substring (3); QMakeHeaderFilesList += ("\t\"" + SourceFileRelativeToRoot.Substring(3) + "\" \\\n"); } else if (!String.IsNullOrEmpty(GameProjectName)) { QMakeHeaderFilesList += ("\t\"$$" + GameProjectName + "RootPath/" + Utils.MakePathRelativeTo(CurSourceFile, GameProjectPath) + "\" \\\n"); } else { System.Console.WriteLine("Error!, you should not be here."); } } } if (SourceFileRelativeToRoot.EndsWith(".cs")) { if (!SourceFileRelativeToRoot.StartsWith("..") && !Path.IsPathRooted(SourceFileRelativeToRoot)) { // SourceFileRelativeToRoot = "Engine/" + SourceFileRelativeToRoot; QMakeConfigFilesList += ("\t\"" + "$$unrealRootPath/Engine/" + SourceFileRelativeToRoot + "\" \\\n"); } else { if (String.IsNullOrEmpty(GameProjectName)) { // SourceFileRelativeToRoot = SourceFileRelativeToRoot.Substring (3); QMakeConfigFilesList += ("\t\"" + SourceFileRelativeToRoot.Substring(3) + "\" \\\n"); } else if (!String.IsNullOrEmpty(GameProjectName)) { QMakeConfigFilesList += ("\t\"$$" + GameProjectName + "RootPath/" + Utils.MakePathRelativeTo(CurSourceFile, GameProjectPath) + "\" \\\n"); } else { System.Console.WriteLine("Error!, you should not be here."); } } } } } } // Add section end to section strings; QMakeSourceFilesList += QMakeSectionEnd; QMakeHeaderFilesList += QMakeSectionEnd; QMakeConfigFilesList += QMakeSectionEnd; // Append sections to the QMakeLists.txt file QMakeSourcePriFileContent.Append(QMakeSourceFilesList); QMakeHeaderPriFileContent.Append(QMakeHeaderFilesList); QMakeConfigPriFileContent.Append(QMakeConfigFilesList); string QMakeProjectCmdArg = ""; foreach (string TargetFilePath in DiscoverTargets()) { var TargetName = Utils.GetFilenameWithoutAnyExtensions(TargetFilePath); // Remove both ".cs" and ". foreach (UnrealTargetConfiguration CurConfiguration in Enum.GetValues(typeof(UnrealTargetConfiguration))) { if (CurConfiguration != UnrealTargetConfiguration.Unknown && CurConfiguration != UnrealTargetConfiguration.Development) { if (UnrealBuildTool.IsValidConfiguration(CurConfiguration)) { if (TargetName == GameProjectName || TargetName == (GameProjectName + "Editor")) { QMakeProjectCmdArg = " -project=\"\\\"$$gameProjectFile\\\"\""; } var ConfName = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration); QMakeFileContent.Append(String.Format("{0}-Linux-{1}.commands = $$build {2} {0} Linux {1} $$args\n", TargetName, ConfName, QMakeProjectCmdArg)); QMakeTargetList += "\t" + TargetName + "-Linux-" + ConfName + " \\\n"; // , TargetName, ConfName); } } } if (TargetName == GameProjectName || TargetName == (GameProjectName + "Editor")) { QMakeProjectCmdArg = " -project=\"\\\"$$gameProjectFile\\\"\""; } QMakeFileContent.Append(String.Format("{0}.commands = $$build {1} {0} Linux Development $$args\n\n", TargetName, QMakeProjectCmdArg)); QMakeTargetList += "\t" + TargetName + " \\\n"; } QMakeFileContent.Append(QMakeTargetList.TrimEnd('\\')); var FullFileName = Path.Combine(MasterProjectRelativePath, FileName); var FullQMakeDefinesFileName = Path.Combine(MasterProjectRelativePath, QMakeDefinesFileName); var FullQMakeIncludesFileName = Path.Combine(MasterProjectRelativePath, QMakeIncludesFileName); var FullQMakeSourcePriFileName = Path.Combine(MasterProjectRelativePath, QMakeSourcePriFileName); var FullQMakeHeaderPriFileName = Path.Combine(MasterProjectRelativePath, QMakeHeaderPriFileName); var FullQMakeConfigPriFileName = Path.Combine(MasterProjectRelativePath, QMakeConfigPriFileName); WriteFileIfChanged(FullQMakeDefinesFileName, QMakeDefinesPriFileContent.ToString()); WriteFileIfChanged(FullQMakeIncludesFileName, QMakeIncludesPriFileContent.ToString()); WriteFileIfChanged(FullQMakeSourcePriFileName, QMakeSourcePriFileContent.ToString()); WriteFileIfChanged(FullQMakeHeaderPriFileName, QMakeHeaderPriFileContent.ToString()); WriteFileIfChanged(FullQMakeConfigPriFileName, QMakeConfigPriFileContent.ToString()); return(WriteFileIfChanged(FullFileName, QMakeFileContent.ToString())); }
private bool WriteMakefile() { string GameProjectFile = ""; string BuildCommand = ""; string ProjectBuildCommand = ""; string MakeGameProjectFile = ""; var UnrealRootPath = UnrealBuildTool.RootDirectory.FullName; if (!String.IsNullOrEmpty(GameProjectName)) { GameProjectFile = OnlyGameProject.FullName; MakeGameProjectFile = "GAMEPROJECTFILE =" + GameProjectFile + "\n"; ProjectBuildCommand = "PROJECTBUILD = mono \"$(UNREALROOTPATH)/Engine/Binaries/DotNET/UnrealBuildTool.exe\"\n"; } BuildCommand = "BUILD = bash \"$(UNREALROOTPATH)/Engine/Build/BatchFiles/Linux/Build.sh\"\n"; var FileName = "Makefile"; // MasterProjectName + ".mk"; var MakefileContent = new StringBuilder(); MakefileContent.Append( "# Makefile generated by MakefileGenerator.cs\n" + "# *DO NOT EDIT*\n\n" + "UNREALROOTPATH = " + UnrealRootPath + "\n" + MakeGameProjectFile + "\n" + "TARGETS =" ); String MakeProjectCmdArg = ""; String MakeBuildCommand = ""; foreach (var Project in GeneratedProjectFiles) { foreach (var TargetFile in Project.ProjectTargets) { if (TargetFile.TargetFilePath == null) { continue; } string TargetFileName = TargetFile.TargetFilePath.GetFileNameWithoutExtension(); string Basename = TargetFileName.Substring(0, TargetFileName.LastIndexOf(".Target")); foreach (UnrealTargetConfiguration CurConfiguration in Enum.GetValues(typeof(UnrealTargetConfiguration))) { if (CurConfiguration != UnrealTargetConfiguration.Unknown && CurConfiguration != UnrealTargetConfiguration.Development) { if (UnrealBuildTool.IsValidConfiguration(CurConfiguration)) { var Confname = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration); MakefileContent.Append(String.Format(" \\\n\t{0}-Linux-{1} ", Basename, Confname)); } } } MakefileContent.Append(" \\\n\t" + Basename); } } MakefileContent.Append("\\\n\tconfigure"); MakefileContent.Append("\n\n" + BuildCommand + ProjectBuildCommand + "\n" + "all: StandardSet\n\n" + "RequiredTools: CrashReportClient-Linux-Shipping ShaderCompileWorker UnrealLightmass\n\n" + "StandardSet: RequiredTools UnrealFrontend UE4Editor\n\n" + "DebugSet: RequiredTools UnrealFrontend-Linux-Debug UE4Editor-Linux-Debug\n\n" ); foreach (var Project in GeneratedProjectFiles) { foreach (var TargetFile in Project.ProjectTargets) { if (TargetFile.TargetFilePath == null) { continue; } string TargetFileName = TargetFile.TargetFilePath.GetFileNameWithoutExtension(); string Basename = TargetFileName.Substring(0, TargetFileName.LastIndexOf(".Target")); if (Basename == GameProjectName || Basename == (GameProjectName + "Editor")) { MakeProjectCmdArg = " -project=\"$(GAMEPROJECTFILE)\""; MakeBuildCommand = "$(PROJECTBUILD)"; } else { MakeBuildCommand = "$(BUILD)"; } foreach (UnrealTargetConfiguration CurConfiguration in Enum.GetValues(typeof(UnrealTargetConfiguration))) { if (Basename == GameProjectName || Basename == (GameProjectName + "Editor")) { MakeProjectCmdArg = " -project=\"$(GAMEPROJECTFILE)\""; MakeBuildCommand = "$(PROJECTBUILD)"; } else { MakeBuildCommand = "$(BUILD)"; } if (CurConfiguration != UnrealTargetConfiguration.Unknown && CurConfiguration != UnrealTargetConfiguration.Development) { if (UnrealBuildTool.IsValidConfiguration(CurConfiguration)) { var Confname = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration); MakefileContent.Append(String.Format("\n{1}-Linux-{2}:\n\t {0} {1} Linux {2} {3} $(ARGS)\n", MakeBuildCommand, Basename, Confname, MakeProjectCmdArg)); } } } MakefileContent.Append(String.Format("\n{1}:\n\t {0} {1} Linux Development {2} $(ARGS)\n", MakeBuildCommand, Basename, MakeProjectCmdArg)); } } MakefileContent.Append("\nconfigure:\n"); if (!String.IsNullOrEmpty(GameProjectName)) { // Make sure UBT is updated. MakefileContent.Append("\txbuild /property:Configuration=Development /property:TargetFrameworkVersion=v4.5 /verbosity:quiet /nologo "); MakefileContent.Append("\"$(UNREALROOTPATH)/Engine/Source/Programs/UnrealBuildTool/UnrealBuildTool.csproj\"\n"); MakefileContent.Append("\t$(PROJECTBUILD) -projectfiles -project=\"\\\"$(GAMEPROJECTFILE)\\\"\" -game -engine \n"); } else { MakefileContent.Append("\tbash \"$(UNREALROOTPATH)/GenerateProjectFiles.sh\" \n"); } MakefileContent.Append("\n.PHONY: $(TARGETS)\n"); FileReference FullFileName = FileReference.Combine(MasterProjectPath, FileName); return(WriteFileIfChanged(FullFileName.FullName, MakefileContent.ToString())); }
/// <summary> /// Write the Command section for a .kdev4/$ProjectName.kdev4 file. /// </summary> /// <param name="FileContent">File content.</param> private void WriteCommandSection(ref StringBuilder FileContent) { int BuildConfigIndex = 1; var UnrealRootPath = Path.GetFullPath(ProjectFileGenerator.RootRelativePath); FileContent.Append("[CustomBuildSystem]\n"); FileContent.Append("CurrentConfiguration=BuildConfig0\n\n"); // // The Basics to get up and running with the editor, utilizing the Makefile. FileContent.Append(String.Format("[CustomBuildSystem][BuildConfig0]\nBuildDir=file://{0}\n", UnrealRootPath)); FileContent.Append("Title=BuildMeFirst\n\n"); FileContent.Append("[CustomBuildSystem][BuildConfig0][ToolBuild]\n"); FileContent.Append("Arguments=-f Makefile UE4Editor UE4Game ShaderCompileWorker UnrealLightmass UnrealPak\n"); FileContent.Append("Enabled=true\n"); FileContent.Append("Environment=\n"); FileContent.Append("Executable=make\n"); FileContent.Append("Type=0\n\n"); FileContent.Append("[CustomBuildSystem][BuildConfig0][ToolClean]\n"); FileContent.Append("Arguments=-f Makefile UE4Editor UE4Game ShaderCompileWorker UnrealLightmass UnrealPak -clean\n"); FileContent.Append("Enabled=true\n"); FileContent.Append("Environment=\n"); FileContent.Append("Executable=make\n"); FileContent.Append("Type=3\n\n"); FileContent.Append("[CustomBuildSystem][BuildConfig0][ToolConfigure]\n"); FileContent.Append("Arguments=./GenerateProjectFiles.sh\n"); FileContent.Append("Enabled=true\n"); FileContent.Append("Environment=\n"); FileContent.Append("Executable=bash\n"); FileContent.Append("Type=1\n\n"); 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)) { var ConfName = Enum.GetName(typeof(UnrealTargetConfiguration), CurConfiguration); FileContent.Append(String.Format("[CustomBuildSystem][BuildConfig{0}]\nBuildDir=file://{1}\n", BuildConfigIndex, UnrealRootPath)); if (TargetName == GameProjectName) { FileContent.Append(String.Format("Title={0}-Linux-{1}\n\n", TargetName, ConfName)); WriteCommandSubSection(ref FileContent, TargetName, ConfName, BuildConfigIndex, 0); WriteCommandSubSection(ref FileContent, TargetName, ConfName, BuildConfigIndex, 1); WriteCommandSubSection(ref FileContent, TargetName, ConfName, BuildConfigIndex, 3); } else if (TargetName == (GameProjectName + "Editor")) { FileContent.Append(String.Format("Title={0}-Linux-{1}\n\n", TargetName, ConfName)); WriteCommandSubSection(ref FileContent, TargetName, ConfName, BuildConfigIndex, 0); WriteCommandSubSection(ref FileContent, TargetName, ConfName, BuildConfigIndex, 1); WriteCommandSubSection(ref FileContent, TargetName, ConfName, BuildConfigIndex, 3); } else { FileContent.Append(String.Format("Title={0}-Linux-{1}\n\n", TargetName, ConfName)); WriteCommandSubSection(ref FileContent, TargetName, ConfName, BuildConfigIndex, 0); WriteCommandSubSection(ref FileContent, TargetName, ConfName, BuildConfigIndex, 1); WriteCommandSubSection(ref FileContent, TargetName, ConfName, BuildConfigIndex, 3); } BuildConfigIndex++; } } } FileContent.Append(String.Format("[CustomBuildSystem][BuildConfig{0}]\nBuildDir=file://{1}\n", BuildConfigIndex, UnrealRootPath)); if (TargetName == GameProjectName) { FileContent.Append(String.Format("Title={0}\n\n", TargetName)); WriteCommandSubSection(ref FileContent, TargetName, "Development", BuildConfigIndex, 0); WriteCommandSubSection(ref FileContent, TargetName, "Development", BuildConfigIndex, 1); WriteCommandSubSection(ref FileContent, TargetName, "Development", BuildConfigIndex, 3); } else if (TargetName == (GameProjectName + "Editor")) { FileContent.Append(String.Format("Title={0}\n\n", TargetName)); WriteCommandSubSection(ref FileContent, TargetName, "Development", BuildConfigIndex, 0); WriteCommandSubSection(ref FileContent, TargetName, "Development", BuildConfigIndex, 1); WriteCommandSubSection(ref FileContent, TargetName, "Development", BuildConfigIndex, 3); } else { FileContent.Append(String.Format("Title={0}\n\n", TargetName)); WriteCommandSubSection(ref FileContent, TargetName, "Development", BuildConfigIndex, 0); WriteCommandSubSection(ref FileContent, TargetName, "Development", BuildConfigIndex, 1); WriteCommandSubSection(ref FileContent, TargetName, "Development", BuildConfigIndex, 3); } BuildConfigIndex++; } } }
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); }
protected override bool WriteMasterProjectFile(ProjectFile UBTProject) { var SolutionFileName = MasterProjectName + SolutionExtension; var CodeCompletionFile = MasterProjectName + CodeCompletionFileName; var CodeCompletionPreProcessorFile = MasterProjectName + CodeCompletionPreProcessorFileName; var FullCodeLiteMasterFile = Path.Combine(MasterProjectPath.FullName, SolutionFileName); var FullCodeLiteCodeCompletionFile = Path.Combine(MasterProjectPath.FullName, CodeCompletionFile); var FullCodeLiteCodeCompletionPreProcessorFile = Path.Combine(MasterProjectPath.FullName, CodeCompletionPreProcessorFile); // // HACK // TODO This is for now a hack. According to the original submitter, Eranif (a CodeLite developer) will support code completion folders in *.workspace files. // We create a separate file with all the folder name in it to copy manually into the code completion // filed of CodeLite workspace. (Workspace Settings/Code Completion -> copy the content of the file threre.) List <string> IncludeDirectories = new List <string>(); List <string> PreProcessor = new List <string>(); foreach (var CurProject in GeneratedProjectFiles) { CodeLiteProject Project = CurProject as CodeLiteProject; if (Project == null) { continue; } foreach (var CurrentPath in Project.IntelliSenseIncludeSearchPaths) { // Convert relative path into absolute. DirectoryReference IntelliSenseIncludeSearchPath = DirectoryReference.Combine(Project.ProjectFilePath.Directory, CurrentPath); IncludeDirectories.Add(IntelliSenseIncludeSearchPath.FullName); } foreach (var CurrentPath in Project.IntelliSenseSystemIncludeSearchPaths) { // Convert relative path into absolute. DirectoryReference IntelliSenseSystemIncludeSearchPath = DirectoryReference.Combine(Project.ProjectFilePath.Directory, CurrentPath); IncludeDirectories.Add(IntelliSenseSystemIncludeSearchPath.FullName); } foreach (var CurDef in Project.IntelliSensePreprocessorDefinitions) { if (!PreProcessor.Contains(CurDef)) { PreProcessor.Add(CurDef); } } } // // Write code completions data into files. // File.WriteAllLines(FullCodeLiteCodeCompletionFile, IncludeDirectories); File.WriteAllLines(FullCodeLiteCodeCompletionPreProcessorFile, PreProcessor); // // Write CodeLites Workspace // XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; XElement CodeLiteWorkspace = new XElement("CodeLite_Workspace"); XAttribute CodeLiteWorkspaceName = new XAttribute("Name", MasterProjectName); XAttribute CodeLiteWorkspaceSWTLW = new XAttribute("SWTLW", "Yes"); // This flag will only work in CodeLite version > 8.0. See below CodeLiteWorkspace.Add(CodeLiteWorkspaceName); CodeLiteWorkspace.Add(CodeLiteWorkspaceSWTLW); // // ATTN This part will work for the next release of CodeLite. That may // be CodeLite version > 8.0. CodeLite 8.0 does not have this functionality. // TODO Macros are ignored for now. // // Write Code Completion folders into the WorkspaceParserPaths section. // XElement CodeLiteWorkspaceParserPaths = new XElement("WorkspaceParserPaths"); foreach (var CurrentPath in IncludeDirectories) { XElement CodeLiteWorkspaceParserPathInclude = new XElement("Include"); XAttribute CodeLiteWorkspaceParserPath = new XAttribute("Path", CurrentPath); CodeLiteWorkspaceParserPathInclude.Add(CodeLiteWorkspaceParserPath); CodeLiteWorkspaceParserPaths.Add(CodeLiteWorkspaceParserPathInclude); } CodeLiteWorkspace.Add(CodeLiteWorkspaceParserPaths); // // Write project file information into CodeLite's workspace file. // foreach (var CurProject in AllProjectFiles) { var ProjectExtension = CurProject.ProjectFilePath.GetExtension(); // // TODO For now ignore C# project files. // if (ProjectExtension == ".csproj") { continue; } // // Iterate through all targets. // foreach (ProjectTarget CurrentTarget in CurProject.ProjectTargets) { string[] tmp = CurrentTarget.ToString().Split('.'); string ProjectTargetFileName = CurProject.ProjectFilePath.Directory.MakeRelativeTo(MasterProjectPath) + "/" + tmp[0] + ProjectExtension; String ProjectName = tmp[0]; XElement CodeLiteWorkspaceProject = new XElement("Project"); XAttribute CodeLiteWorkspaceProjectName = new XAttribute("Name", ProjectName); XAttribute CodeLiteWorkspaceProjectPath = new XAttribute("Path", ProjectTargetFileName); XAttribute CodeLiteWorkspaceProjectActive = new XAttribute("Active", "No"); CodeLiteWorkspaceProject.Add(CodeLiteWorkspaceProjectName); CodeLiteWorkspaceProject.Add(CodeLiteWorkspaceProjectPath); CodeLiteWorkspaceProject.Add(CodeLiteWorkspaceProjectActive); CodeLiteWorkspace.Add(CodeLiteWorkspaceProject); } } // // We need to create the configuration matrix. That will assign the project configuration to // the samge workspace configuration. // XElement CodeLiteWorkspaceBuildMatrix = new XElement("BuildMatrix"); foreach (UnrealTargetConfiguration CurConfiguration in SupportedConfigurations) { if (UnrealBuildTool.IsValidConfiguration(CurConfiguration)) { XElement CodeLiteWorkspaceBuildMatrixConfiguration = new XElement("WorkspaceConfiguration"); XAttribute CodeLiteWorkspaceProjectName = new XAttribute("Name", CurConfiguration.ToString()); XAttribute CodeLiteWorkspaceProjectSelected = new XAttribute("Selected", "no"); CodeLiteWorkspaceBuildMatrixConfiguration.Add(CodeLiteWorkspaceProjectName); CodeLiteWorkspaceBuildMatrixConfiguration.Add(CodeLiteWorkspaceProjectSelected); foreach (var CurProject in AllProjectFiles) { var ProjectExtension = CurProject.ProjectFilePath.GetExtension(); // // TODO For now ignore C# project files. // if (ProjectExtension == ".csproj") { continue; } foreach (ProjectTarget target in CurProject.ProjectTargets) { string[] tmp = target.ToString().Split('.'); String ProjectName = tmp[0]; XElement CodeLiteWorkspaceBuildMatrixConfigurationProject = new XElement("Project"); XAttribute CodeLiteWorkspaceBuildMatrixConfigurationProjectName = new XAttribute("Name", ProjectName); XAttribute CodeLiteWorkspaceBuildMatrixConfigurationProjectConfigName = new XAttribute("ConfigName", CurConfiguration.ToString()); CodeLiteWorkspaceBuildMatrixConfigurationProject.Add(CodeLiteWorkspaceBuildMatrixConfigurationProjectName); CodeLiteWorkspaceBuildMatrixConfigurationProject.Add(CodeLiteWorkspaceBuildMatrixConfigurationProjectConfigName); CodeLiteWorkspaceBuildMatrixConfiguration.Add(CodeLiteWorkspaceBuildMatrixConfigurationProject); } } CodeLiteWorkspaceBuildMatrix.Add(CodeLiteWorkspaceBuildMatrixConfiguration); } } CodeLiteWorkspace.Add(CodeLiteWorkspaceBuildMatrix); CodeLiteWorkspace.Save(FullCodeLiteMasterFile); return(true); }
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())); }
protected override bool WriteMasterProjectFile(ProjectFile UBTProject) { bool bSuccess = true; var SolutionFileName = MasterProjectName + ".sln"; // Setup solution file content var VCSolutionFileContent = new StringBuilder(); const string VersionTag = "# UnrealEngineGeneratedSolutionVersion=1.0"; // Solution file header if (ProjectFileFormat == VCProjectFileFormat.VisualStudio2015) { VCSolutionFileContent.Append( ProjectFileGenerator.NewLine + "Microsoft Visual Studio Solution File, Format Version 12.00" + ProjectFileGenerator.NewLine + "# Visual Studio 14" + ProjectFileGenerator.NewLine + "VisualStudioVersion = 14.0.22310.1" + ProjectFileGenerator.NewLine + "MinimumVisualStudioVersion = 10.0.40219.1" + ProjectFileGenerator.NewLine); } else if (ProjectFileFormat == VCProjectFileFormat.VisualStudio2013) { VCSolutionFileContent.Append( ProjectFileGenerator.NewLine + "Microsoft Visual Studio Solution File, Format Version 12.00" + ProjectFileGenerator.NewLine + "# Visual Studio 2013" + ProjectFileGenerator.NewLine + VersionTag + ProjectFileGenerator.NewLine); } else if (ProjectFileFormat == VCProjectFileFormat.VisualStudio2012) { VCSolutionFileContent.Append( ProjectFileGenerator.NewLine + "Microsoft Visual Studio Solution File, Format Version 12.00" + ProjectFileGenerator.NewLine + "# Visual Studio 2012" + ProjectFileGenerator.NewLine + VersionTag + ProjectFileGenerator.NewLine); } else { throw new BuildException("Unexpected ProjectFileFormat"); } // Solution folders, files and project entries { // This the GUID that Visual Studio uses to identify a solution folder var SolutionFolderEntryGUID = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}"; // Solution folders { var AllSolutionFolders = new List <MasterProjectFolder>(); System.Action <List <MasterProjectFolder> /* Folders */> GatherFoldersFunction = null; GatherFoldersFunction = FolderList => { AllSolutionFolders.AddRange(FolderList); foreach (var CurSubFolder in FolderList) { GatherFoldersFunction(CurSubFolder.SubFolders); } }; GatherFoldersFunction(RootFolder.SubFolders); foreach (VisualStudioSolutionFolder CurFolder in AllSolutionFolders) { var FolderGUIDString = CurFolder.FolderGUID.ToString("B").ToUpperInvariant(); VCSolutionFileContent.Append( "Project(\"" + SolutionFolderEntryGUID + "\") = \"" + CurFolder.FolderName + "\", \"" + CurFolder.FolderName + "\", \"" + FolderGUIDString + "\"" + ProjectFileGenerator.NewLine); // Add any files that are inlined right inside the solution folder if (CurFolder.Files.Count > 0) { VCSolutionFileContent.Append( " ProjectSection(SolutionItems) = preProject"+ ProjectFileGenerator.NewLine); foreach (var CurFile in CurFolder.Files) { // Syntax is: <relative file path> = <relative file path> VCSolutionFileContent.Append( " "+ CurFile + " = " + CurFile + ProjectFileGenerator.NewLine); } VCSolutionFileContent.Append( " EndProjectSection"+ ProjectFileGenerator.NewLine); } VCSolutionFileContent.Append( "EndProject" + ProjectFileGenerator.NewLine ); } } // Project files foreach (MSBuildProjectFile CurProject in AllProjectFiles) { // Visual Studio uses different GUID types depending on the project type string ProjectTypeGUID = CurProject.ProjectTypeGUID; // NOTE: The project name in the solution doesn't actually *have* to match the project file name on disk. However, // we prefer it when it does match so we use the actual file name here. var ProjectNameInSolution = Path.GetFileNameWithoutExtension(CurProject.ProjectFilePath); // Use the existing project's GUID that's already known to us var ProjectGUID = CurProject.ProjectGUID.ToString("B").ToUpperInvariant(); VCSolutionFileContent.Append( "Project(\"" + ProjectTypeGUID + "\") = \"" + ProjectNameInSolution + "\", \"" + CurProject.RelativeProjectFilePath + "\", \"" + ProjectGUID + "\"" + ProjectFileGenerator.NewLine); // Setup dependency on UnrealBuildTool, if we need that. This makes sure that UnrealBuildTool is // freshly compiled before kicking off any build operations on this target project if (!CurProject.IsStubProject) { var Dependencies = new List <ProjectFile>(); if (CurProject.IsGeneratedProject && UBTProject != null && CurProject != UBTProject) { Dependencies.Add(UBTProject); Dependencies.AddRange(UBTProject.DependsOnProjects); } Dependencies.AddRange(CurProject.DependsOnProjects); if (Dependencies.Count > 0) { VCSolutionFileContent.Append("\tProjectSection(ProjectDependencies) = postProject" + ProjectFileGenerator.NewLine); // Setup any addition dependencies this project has... foreach (var DependsOnProject in Dependencies) { var DependsOnProjectGUID = ((MSBuildProjectFile)DependsOnProject).ProjectGUID.ToString("B").ToUpperInvariant(); VCSolutionFileContent.Append("\t\t" + DependsOnProjectGUID + " = " + DependsOnProjectGUID + ProjectFileGenerator.NewLine); } VCSolutionFileContent.Append("\tEndProjectSection" + ProjectFileGenerator.NewLine); } } VCSolutionFileContent.Append( "EndProject" + ProjectFileGenerator.NewLine ); } } // Solution configuration platforms. This is just a list of all of the platforms and configurations that // appear in Visual Studio's build configuration selector. var SolutionConfigCombinations = new List <VCSolutionConfigCombination>(); // The "Global" section has source control, solution configurations, project configurations, // preferences, and project hierarchy data { VCSolutionFileContent.Append( "Global" + ProjectFileGenerator.NewLine); { { VCSolutionFileContent.Append( " GlobalSection(SolutionConfigurationPlatforms) = preSolution"+ ProjectFileGenerator.NewLine); var SolutionConfigurationsValidForProjects = new Dictionary <string, Tuple <UnrealTargetConfiguration, string> >(); var PlatformsValidForProjects = new HashSet <UnrealTargetPlatform>(); foreach (var CurConfiguration in SupportedConfigurations) { if (UnrealBuildTool.IsValidConfiguration(CurConfiguration)) { foreach (var CurPlatform in SupportedPlatforms) { if (UnrealBuildTool.IsValidPlatform(CurPlatform)) { foreach (var CurProject in AllProjectFiles) { if (!CurProject.IsStubProject) { if (CurProject.ProjectTargets.Count == 0) { throw new BuildException("Expecting project '" + CurProject.ProjectFilePath + "' to have at least one ProjectTarget associated with it!"); } // Figure out the set of valid target configuration names foreach (var ProjectTarget in CurProject.ProjectTargets) { if (VCProjectFile.IsValidProjectPlatformAndConfiguration(ProjectTarget, CurPlatform, CurConfiguration)) { PlatformsValidForProjects.Add(CurPlatform); // Default to a target configuration name of "Game", since that will collapse down to an empty string var TargetConfigurationName = TargetRules.TargetType.Game.ToString(); if (ProjectTarget.TargetRules != null) { TargetConfigurationName = ProjectTarget.TargetRules.ConfigurationName; } var SolutionConfigName = MakeSolutionConfigurationName(CurConfiguration, TargetConfigurationName); SolutionConfigurationsValidForProjects[SolutionConfigName] = new Tuple <UnrealTargetConfiguration, string>(CurConfiguration, TargetConfigurationName); } } } } } } } } foreach (var CurPlatform in PlatformsValidForProjects) { foreach (var SolutionConfigKeyValue in SolutionConfigurationsValidForProjects) { // e.g. "Development|Win64 = Development|Win64" var SolutionConfigName = SolutionConfigKeyValue.Key; var Configuration = SolutionConfigKeyValue.Value.Item1; var TargetConfigurationName = SolutionConfigKeyValue.Value.Item2; var SolutionPlatformName = CurPlatform.ToString(); var SolutionConfigAndPlatformPair = SolutionConfigName + "|" + SolutionPlatformName; SolutionConfigCombinations.Add( new VCSolutionConfigCombination { VCSolutionConfigAndPlatformName = SolutionConfigAndPlatformPair, Configuration = Configuration, Platform = CurPlatform, TargetConfigurationName = TargetConfigurationName } ); } } // Sort the list of solution platform strings alphabetically (Visual Studio prefers it) SolutionConfigCombinations.Sort( new Comparison <VCSolutionConfigCombination>( (x, y) => { return(String.Compare(x.VCSolutionConfigAndPlatformName, y.VCSolutionConfigAndPlatformName, StringComparison.InvariantCultureIgnoreCase)); } ) ); var AppendedSolutionConfigAndPlatformNames = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase); foreach (var SolutionConfigCombination in SolutionConfigCombinations) { // We alias "Game" and "Program" to both have the same solution configuration, so we're careful not to add the same combination twice. if (!AppendedSolutionConfigAndPlatformNames.Contains(SolutionConfigCombination.VCSolutionConfigAndPlatformName)) { VCSolutionFileContent.Append( " "+ SolutionConfigCombination.VCSolutionConfigAndPlatformName + " = " + SolutionConfigCombination.VCSolutionConfigAndPlatformName + ProjectFileGenerator.NewLine); AppendedSolutionConfigAndPlatformNames.Add(SolutionConfigCombination.VCSolutionConfigAndPlatformName); } } VCSolutionFileContent.Append( " EndGlobalSection"+ ProjectFileGenerator.NewLine); } // Assign each project's "project configuration" to our "solution platform + configuration" pairs. This // also sets up which projects are actually built when building the solution. { VCSolutionFileContent.Append( " GlobalSection(ProjectConfigurationPlatforms) = postSolution"+ ProjectFileGenerator.NewLine); var CombinationsThatWereMatchedToProjects = new List <VCSolutionConfigCombination>(); foreach (MSBuildProjectFile CurProject in AllProjectFiles) { // NOTE: We don't emit solution configuration entries for "stub" projects. Those projects are only // built using UnrealBuildTool and don't require a presence in the solution project list // NOTE: We also process projects that were "imported" here, hoping to match those to our solution // configurations. In some cases this may not be successful though. Imported projects // should always be carefully setup to match our project generator's solution configs. if (!CurProject.IsStubProject) { if (CurProject.ProjectTargets.Count == 0) { throw new BuildException("Expecting project '" + CurProject.ProjectFilePath + "' to have at least one ProjectTarget associated with it!"); } var IsProgramProject = CurProject.ProjectTargets[0].TargetRules != null && CurProject.ProjectTargets[0].TargetRules.Type == TargetRules.TargetType.Program; var GameOrProgramConfigsAlreadyMapped = new HashSet <string>(); foreach (var SolutionConfigCombination in SolutionConfigCombinations) { // Handle aliasing of Program and Game target configuration names if ((IsProgramProject && GameOrProgramConfigsAlreadyMapped.Add(SolutionConfigCombination.VCSolutionConfigAndPlatformName)) || IsProgramProject && SolutionConfigCombination.TargetConfigurationName != TargetRules.TargetType.Game.ToString() || !IsProgramProject && SolutionConfigCombination.TargetConfigurationName != TargetRules.TargetType.Program.ToString()) { var TargetConfigurationName = SolutionConfigCombination.TargetConfigurationName; if (IsProgramProject && TargetConfigurationName == TargetRules.TargetType.Game.ToString()) { TargetConfigurationName = TargetRules.TargetType.Program.ToString(); } // Now, we want to find a target in this project that maps to the current solution config combination. Only up to one target should // and every solution config combination should map to at least one target in one project (otherwise we shouldn't have added it!). ProjectTarget MatchingProjectTarget = null; foreach (var ProjectTarget in CurProject.ProjectTargets) { bool IsMatchingCombination = VCProjectFile.IsValidProjectPlatformAndConfiguration(ProjectTarget, SolutionConfigCombination.Platform, SolutionConfigCombination.Configuration); if (ProjectTarget.TargetRules != null) { if (TargetConfigurationName != ProjectTarget.TargetRules.ConfigurationName) { // Solution configuration name for this combination doesn't match this target's configuration name. It's not buildable. IsMatchingCombination = false; } } else { // UBT gets a pass because it is a dependency of every single configuration combination if (CurProject != UBTProject && !CurProject.ShouldBuildForAllSolutionTargets && TargetConfigurationName != TargetRules.TargetType.Game.ToString()) { // Can't build non-generated project in configurations except for the default (Game) IsMatchingCombination = false; } } if (IsMatchingCombination) { if (MatchingProjectTarget != null) { // Not expecting more than one target to match a single solution configuration per project! throw new BuildException("Not expecting more than one target for project " + CurProject.ProjectFilePath + " to match solution configuration " + SolutionConfigCombination.VCSolutionConfigAndPlatformName); } MatchingProjectTarget = ProjectTarget; // NOTE: For faster perf, we could "break" here and bail out early, but that would circumvent the error checking // for multiple targets within a project that may map to a single solution configuration. } } var SolutionConfiguration = SolutionConfigCombination.Configuration; var SolutionPlatform = SolutionConfigCombination.Platform; if (MatchingProjectTarget == null) { // The current configuration/platform and target configuration name doesn't map to anything our project actually supports. // We'll map it to a default config. SolutionConfiguration = UnrealTargetConfiguration.Development; // Prefer using Win64 as the default, but fall back to a platform the project file actually supports if needed. This is for // projects that can never be compiled in Windows, such as UnrealLaunchDaemon which is an iOS-only program SolutionPlatform = UnrealTargetPlatform.Win64; if (CurProject.ProjectTargets[0].TargetRules != null) { var ProjectSupportedPlatforms = new List <UnrealTargetPlatform>(); CurProject.ProjectTargets[0].TargetRules.GetSupportedPlatforms(ref ProjectSupportedPlatforms); if (!ProjectSupportedPlatforms.Contains(SolutionPlatform)) { SolutionPlatform = ProjectSupportedPlatforms[0]; } } if (IsProgramProject) { TargetConfigurationName = TargetRules.TargetType.Program.ToString(); } else { TargetConfigurationName = TargetRules.TargetType.Game.ToString(); } } // If the project wants to always build in "Development", regardless of what the solution // configuration is set to, then we'll do that here. This is used for projects like // UnrealBuildTool and ShaderCompileWorker if (MatchingProjectTarget != null) { if (MatchingProjectTarget.ForceDevelopmentConfiguration) { SolutionConfiguration = UnrealTargetConfiguration.Development; } } string ProjectConfigName; string ProjectPlatformName; CurProject.MakeProjectPlatformAndConfigurationNames(SolutionPlatform, SolutionConfiguration, TargetConfigurationName, out ProjectPlatformName, out ProjectConfigName); var ProjectConfigAndPlatformPair = ProjectConfigName.ToString() + "|" + ProjectPlatformName.ToString(); // e.g. "{4232C52C-680F-4850-8855-DC39419B5E9B}.Debug|iOS.ActiveCfg = iOS_Debug|Win32" var CurProjectGUID = CurProject.ProjectGUID.ToString("B").ToUpperInvariant(); VCSolutionFileContent.Append( " "+ CurProjectGUID + "." + SolutionConfigCombination.VCSolutionConfigAndPlatformName + ".ActiveCfg = " + ProjectConfigAndPlatformPair + ProjectFileGenerator.NewLine); // Set whether this project configuration should be built when the user initiates "build solution" if (MatchingProjectTarget != null && CurProject.ShouldBuildByDefaultForSolutionTargets) { VCSolutionFileContent.Append( " "+ CurProjectGUID + "." + SolutionConfigCombination.VCSolutionConfigAndPlatformName + ".Build.0 = " + ProjectConfigAndPlatformPair + ProjectFileGenerator.NewLine); var ProjGen = UEPlatformProjectGenerator.GetPlatformProjectGenerator(SolutionConfigCombination.Platform, true); if (MatchingProjectTarget.ProjectDeploys || ((ProjGen != null) && (ProjGen.GetVisualStudioDeploymentEnabled(SolutionPlatform, SolutionConfiguration) == true))) { VCSolutionFileContent.Append( " "+ CurProjectGUID + "." + SolutionConfigCombination.VCSolutionConfigAndPlatformName + ".Deploy.0 = " + ProjectConfigAndPlatformPair + ProjectFileGenerator.NewLine); } } CombinationsThatWereMatchedToProjects.Add(SolutionConfigCombination); } } } } // Check for problems foreach (var SolutionConfigCombination in SolutionConfigCombinations) { if (!CombinationsThatWereMatchedToProjects.Contains(SolutionConfigCombination)) { throw new BuildException("Unable to find a ProjectTarget that matches the solution configuration/platform mapping: " + SolutionConfigCombination.Configuration.ToString() + ", " + SolutionConfigCombination.Platform.ToString() + ", " + SolutionConfigCombination.TargetConfigurationName); } } VCSolutionFileContent.Append( " EndGlobalSection"+ ProjectFileGenerator.NewLine); } // Setup other solution properties { VCSolutionFileContent.Append( " GlobalSection(SolutionProperties) = preSolution"+ ProjectFileGenerator.NewLine); // HideSolutionNode sets whether or not the top-level solution entry is completely hidden in the UI. // We don't want that, as we need users to be able to right click on the solution tree item. VCSolutionFileContent.Append( " HideSolutionNode = FALSE"+ ProjectFileGenerator.NewLine); VCSolutionFileContent.Append( " EndGlobalSection"+ ProjectFileGenerator.NewLine); } // Solution directory hierarchy { VCSolutionFileContent.Append( " GlobalSection(NestedProjects) = preSolution"+ ProjectFileGenerator.NewLine); // Every entry in this section is in the format "Guid1 = Guid2". Guid1 is the child project (or solution // filter)'s GUID, and Guid2 is the solution filter directory to parent the child project (or solution // filter) to. This sets up the hierarchical solution explorer tree for all solution folders and projects. System.Action <StringBuilder /* VCSolutionFileContent */, List <MasterProjectFolder> /* Folders */> FolderProcessorFunction = null; FolderProcessorFunction = (LocalVCSolutionFileContent, LocalMasterProjectFolders) => { foreach (VisualStudioSolutionFolder CurFolder in LocalMasterProjectFolders) { var CurFolderGUIDString = CurFolder.FolderGUID.ToString("B").ToUpperInvariant(); foreach (MSBuildProjectFile ChildProject in CurFolder.ChildProjects) { // e.g. "{BF6FB09F-A2A6-468F-BE6F-DEBE07EAD3EA} = {C43B6BB5-3EF0-4784-B896-4099753BCDA9}" LocalVCSolutionFileContent.Append( " "+ ChildProject.ProjectGUID.ToString("B").ToUpperInvariant() + " = " + CurFolderGUIDString + ProjectFileGenerator.NewLine); } foreach (VisualStudioSolutionFolder SubFolder in CurFolder.SubFolders) { // e.g. "{BF6FB09F-A2A6-468F-BE6F-DEBE07EAD3EA} = {C43B6BB5-3EF0-4784-B896-4099753BCDA9}" LocalVCSolutionFileContent.Append( " "+ SubFolder.FolderGUID.ToString("B").ToUpperInvariant() + " = " + CurFolderGUIDString + ProjectFileGenerator.NewLine); } // Recurse into subfolders FolderProcessorFunction(LocalVCSolutionFileContent, CurFolder.SubFolders); } }; FolderProcessorFunction(VCSolutionFileContent, RootFolder.SubFolders); VCSolutionFileContent.Append( " EndGlobalSection"+ ProjectFileGenerator.NewLine); } } VCSolutionFileContent.Append( "EndGlobal" + ProjectFileGenerator.NewLine); } // Save the solution file if (bSuccess) { var SolutionFilePath = Path.Combine(MasterProjectRelativePath, SolutionFileName); bSuccess = WriteFileIfChanged(SolutionFilePath, VCSolutionFileContent.ToString()); } // Save a solution config file which selects the development editor configuration by default. if (bSuccess) { // Figure out the filename for the SUO file. VS will automatically import the options from earlier versions if necessary. string SolutionOptionsExtension = "vUnknown.suo"; switch (ProjectFileFormat) { case VCProjectFileFormat.VisualStudio2012: SolutionOptionsExtension = "v11.suo"; break; case VCProjectFileFormat.VisualStudio2013: SolutionOptionsExtension = "v12.suo"; break; case VCProjectFileFormat.VisualStudio2015: SolutionOptionsExtension = "v14.suo"; break; } // Check it doesn't exist before overwriting it. Since these files store the user's preferences, it'd be bad form to overwrite them. string SolutionOptionsFileName = Path.Combine(MasterProjectRelativePath, Path.ChangeExtension(SolutionFileName, SolutionOptionsExtension)); if (!File.Exists(SolutionOptionsFileName)) { VCSolutionOptions Options = new VCSolutionOptions(); // Set the default configuration and startup project VCSolutionConfigCombination DefaultConfig = SolutionConfigCombinations.Find(x => x.Configuration == UnrealTargetConfiguration.Development && x.Platform == UnrealTargetPlatform.Win64 && x.TargetConfigurationName == "Editor"); if (DefaultConfig != null) { List <VCBinarySetting> Settings = new List <VCBinarySetting>(); Settings.Add(new VCBinarySetting("ActiveCfg", DefaultConfig.VCSolutionConfigAndPlatformName)); if (DefaultProject != null) { Settings.Add(new VCBinarySetting("StartupProject", ((MSBuildProjectFile)DefaultProject).ProjectGUID.ToString("B"))); } Options.SetConfiguration(Settings); } // Mark all the projects as closed by default, apart from the startup project VCSolutionExplorerState ExplorerState = new VCSolutionExplorerState(); foreach (ProjectFile ProjectFile in AllProjectFiles) { string ProjectName = Path.GetFileNameWithoutExtension(ProjectFile.ProjectFilePath); if (ProjectFile == DefaultProject) { ExplorerState.OpenProjects.Add(new Tuple <string, string[]>(ProjectName, new string[] { ProjectName })); } else { ExplorerState.OpenProjects.Add(new Tuple <string, string[]>(ProjectName, new string[] { })); } } if (IncludeEnginePrograms) { ExplorerState.OpenProjects.Add(new Tuple <string, string[]>("Automation", new string[0])); } Options.SetExplorerState(ExplorerState); // Write the file if (Options.Sections.Count > 0) { Options.Write(SolutionOptionsFileName); } } } return(bSuccess); }
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())); }
private bool WriteCMakeLists() { string BuildCommand; const string CMakeSectionEnd = " )\n\n"; var 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, '/'); var CMakeGameRootPath = ""; string GameProjectPath = ""; string CMakeGameProjectFile = ""; string HostArchitecture; 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\""; 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).ToString(); string ProjectHeadersFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeProjectHeadersFileName).ToString(); string EngineSourcesFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeEngineSourcesFileName).ToString(); string ProjectSourcesFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeProjectSourcesFileName).ToString(); string ProjectFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeProjectSourcesFileName).ToString(); string IncludeFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeIncludesFileName).ToString(); string EngineConfigsFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeEngineConfigsFileName).ToString(); string ProjectConfigsFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeProjectConfigsFileName).ToString(); string EngineCSFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeEngineCSFileName).ToString(); string ProjectCSFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeProjectCSFileName).ToString(); string EngineShadersFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeEngineShadersFileName).ToString(); string ProjectShadersFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeProjectShadersFileName).ToString(); string DefinitionsFilePath = FileReference.Combine(IntermediateProjectFilesPath, CMakeDefinitionsFileName).ToString(); 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" + "# 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 (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, 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 (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")) { 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) { PreprocessorDefinitionsList.Append("\t-D" + PreprocessorDefinition + "\n"); } // Add Engine/Shaders files (game are added via modules) var 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) var 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 (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) && !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} 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} 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})"); } var 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); }
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())); }