Beispiel #1
0
        /// <summary>
        /// Binds artificial module to given binary.
        /// </summary>
        /// <param name="Module">Module to bind.</param>
        /// <param name="Binary">Binary to bind.</param>
        private void BindArtificialModuleToBinary(UEBuildModuleCPP Module, UEBuildBinary Binary)
        {
            Module.Binary = Binary;
            Module.bIncludedInTarget = true;

            // Process dependencies for this new module
            Module.CachePCHUsageForModuleSourceFiles(Module.CreateModuleCompileEnvironment(GlobalCompileEnvironment));

            // Add module to binary
            Binary.AddModule(Module.Name);
        }
        /// <summary>
        /// All non-program monolithic binaries implicitly depend on all static plugin libraries so they are always linked appropriately
        /// In order to do this, we create a new module here with a cpp file we emit that invokes an empty function in each library.
        /// If we do not do this, there will be no static initialization for libs if no symbols are referenced in them.
        /// </summary>
        private void CreateLinkerFixupsCPPFile()
        {
            var ExecutableBinary = AppBinaries[0];

            List<string> PrivateDependencyModuleNames = new List<string>();

            UEBuildBinaryCPP BinaryCPP = ExecutableBinary as UEBuildBinaryCPP;
            if (BinaryCPP != null)
            {
                TargetInfo CurrentTarget = new TargetInfo(Platform, Configuration, (Rules != null) ? TargetType : (TargetRules.TargetType?)null);
                foreach (var TargetModuleName in BinaryCPP.ModuleNames)
                {
                    string UnusedFilename;
                    ModuleRules CheckRules = RulesCompiler.CreateModuleRules(TargetModuleName, CurrentTarget, out UnusedFilename);
                    if ((CheckRules != null) && (CheckRules.Type != ModuleRules.ModuleType.External))
                    {
                        PrivateDependencyModuleNames.Add(TargetModuleName);
                    }
                }
            }
            foreach (PluginInfo Plugin in EnabledPlugins)
            {
                foreach (PluginInfo.PluginModuleInfo Module in Plugin.Modules)
                {
                    if(ShouldIncludePluginModule(Plugin, Module))
                    {
                        PrivateDependencyModuleNames.Add(Module.Name);
                    }
                }
            }

            // We ALWAYS have to write this file as the IMPLEMENT_PRIMARY_GAME_MODULE function depends on the UELinkerFixups function existing.
            {
                List<string> LinkerFixupsFileContents = new List<string>();

                string LinkerFixupsName = "UELinkerFixups";

                // Include an empty header so UEBuildModule.Compile does not complain about a lack of PCH
                string HeaderFilename                    = LinkerFixupsName + "Name.h";
                string LinkerFixupHeaderFilenameWithPath = Path.Combine(GlobalCompileEnvironment.Config.OutputDirectory, HeaderFilename);

                LinkerFixupsFileContents.Add("#include \"" + HeaderFilename + "\"");

                // Add a function that is not referenced by anything that invokes all the empty functions in the different static libraries
                LinkerFixupsFileContents.Add("void " + LinkerFixupsName + "()");
                LinkerFixupsFileContents.Add("{");

                // Fill out the body of the function with the empty function calls. This is what causes the static libraries to be considered relevant
                {
                    var UObjectModules = new List<UEBuildModuleCPP>();
                    foreach (var Binary in AppBinaries)
                    {
                        var DependencyModules = Binary.GetAllDependencyModules(bIncludeDynamicallyLoaded: false, bForceCircular: false);
                        foreach (var Module in DependencyModules.OfType<UEBuildModuleCPP>().Where(CPPModule => CPPModule.AutoGenerateCppInfo != null && !UObjectModules.Any(Module => Module.Name == CPPModule.Name)))
                        {
                            UObjectModules.Add(Module);
                        }
                    }
                    foreach (var Module in UObjectModules)
                    {
                        LinkerFixupsFileContents.Add("    extern void EmptyLinkFunctionForGeneratedCode" + Module.Name + "();");
                        LinkerFixupsFileContents.Add("    EmptyLinkFunctionForGeneratedCode" + Module.Name + "();");
                    }
                }
                foreach (var DependencyModuleName in PrivateDependencyModuleNames)
                {
                    LinkerFixupsFileContents.Add("    extern void EmptyLinkFunctionForStaticInitialization" + DependencyModuleName + "();");
                    LinkerFixupsFileContents.Add("    EmptyLinkFunctionForStaticInitialization" + DependencyModuleName + "();");
                }

                // End the function body that was started above
                LinkerFixupsFileContents.Add("}");

                // Create the cpp file
                string LinkerFixupCPPFilename = Path.Combine(GlobalCompileEnvironment.Config.OutputDirectory, LinkerFixupsName + ".cpp");

                // Determine if the file changed. Write it if it either doesn't exist or the contents are different.
                bool bShouldWriteFile = true;
                if (File.Exists(LinkerFixupCPPFilename))
                {
                    string[] ExistingFixupText = File.ReadAllLines(LinkerFixupCPPFilename);
                    string JoinedNewContents = string.Join("", LinkerFixupsFileContents.ToArray());
                    string JoinedOldContents = string.Join("", ExistingFixupText);
                    bShouldWriteFile = (JoinedNewContents != JoinedOldContents);
                }

                // If we determined that we should write the file, write it now.
                if (bShouldWriteFile)
                {
                    ResponseFile.Create(LinkerFixupHeaderFilenameWithPath, new List<string>());
                    ResponseFile.Create(LinkerFixupCPPFilename, LinkerFixupsFileContents);
                }

                // Create the source file list (just the one cpp file)
                List<FileItem> SourceFiles = new List<FileItem>();
                SourceFiles.Add(FileItem.GetItemByPath(LinkerFixupCPPFilename));

                // Create the CPP module
                var FakeModuleDirectory = Path.GetDirectoryName( LinkerFixupCPPFilename );
                UEBuildModuleCPP NewModule = new UEBuildModuleCPP(
                    InTarget: this,
                    InName: LinkerFixupsName,
                    InType: UEBuildModuleType.Game,
                    InModuleDirectory:FakeModuleDirectory,
                    InOutputDirectory: GlobalCompileEnvironment.Config.OutputDirectory,
                    InIsRedistributableOverride: null,
                    InIntelliSenseGatherer: null,
                    InSourceFiles: SourceFiles,
                    InPublicIncludePaths: new List<string>(),
                    InPublicSystemIncludePaths: new List<string>(),
                    InDefinitions: new List<string>(),
                    InPublicIncludePathModuleNames: new List<string>(),
                    InPublicDependencyModuleNames: new List<string>(),
                    InPublicDelayLoadDLLs: new List<string>(),
                    InPublicAdditionalLibraries: new List<string>(),
                    InPublicFrameworks: new List<string>(),
                    InPublicWeakFrameworks: new List<string>(),
                    InPublicAdditionalShadowFiles: new List<string>(),
                    InPublicAdditionalBundleResources: new List<UEBuildBundleResource>(),
                    InPublicAdditionalFrameworks: new List<UEBuildFramework>(),
                    InPrivateIncludePaths: new List<string>(),
                    InPrivateIncludePathModuleNames: new List<string>(),
                    InPrivateDependencyModuleNames: PrivateDependencyModuleNames,
                    InCircularlyReferencedDependentModules: new List<string>(),
                    InDynamicallyLoadedModuleNames: new List<string>(),
                    InPlatformSpecificDynamicallyLoadedModuleNames: new List<string>(),
                    InOptimizeCode: ModuleRules.CodeOptimization.Default,
                    InAllowSharedPCH: false,
                    InSharedPCHHeaderFile: "",
                    InUseRTTI: false,
                    InEnableBufferSecurityChecks: true,
                    InFasterWithoutUnity: true,
                    InMinFilesUsingPrecompiledHeaderOverride: 0,
                    InEnableExceptions: false,
                    bInBuildSourceFiles: true
                    );

                // Now bind this new module to the executable binary so it will link the plugin libs correctly
                NewModule.Binary = ExecutableBinary;
                NewModule.bIncludedInTarget = true;

                // Process dependencies for this new module
                NewModule.CachePCHUsageForModuleSourceFiles(NewModule.CreateModuleCompileEnvironment(GlobalCompileEnvironment));

                // Add module to binary
                ExecutableBinary.AddModule(NewModule.Name);
            }
        }