Add support for building engine target as shared library on all platforms
This commit is contained in:
@@ -16,6 +16,11 @@ namespace Flax.Build
|
||||
{
|
||||
private static Version _engineVersion;
|
||||
|
||||
/// <summary>
|
||||
/// Name of the native engine library.
|
||||
/// </summary>
|
||||
public const string LibraryName = "FlaxEngine";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the engine project.
|
||||
/// </summary>
|
||||
@@ -50,6 +55,11 @@ namespace Flax.Build
|
||||
defines.Add(string.Format("FLAX_{0}_{1}_OR_NEWER", engineVersion.Major, minor));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// True if target is built as monolithic executable with Main module inside, otherwise built as shared library with separate executable made of Main module only.
|
||||
/// </summary>
|
||||
public bool IsMonolithicExecutable = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Init()
|
||||
{
|
||||
@@ -65,14 +75,23 @@ namespace Flax.Build
|
||||
/// <inheritdoc />
|
||||
public override string GetOutputFilePath(BuildOptions options, TargetOutputType? outputType)
|
||||
{
|
||||
var useSeparateMainExe = UseSeparateMainExecutable(options);
|
||||
|
||||
// If building engine executable for platform doesn't support referencing it when linking game shared libraries
|
||||
if (outputType == null && UseSeparateMainExecutable(options))
|
||||
if (outputType == null && useSeparateMainExe)
|
||||
{
|
||||
// Build into shared library
|
||||
outputType = TargetOutputType.Library;
|
||||
}
|
||||
|
||||
return base.GetOutputFilePath(options, outputType);
|
||||
// Override output name to shared library name when building library for the separate main executable
|
||||
var outputName = OutputName;
|
||||
if (useSeparateMainExe && (outputType ?? OutputType) == TargetOutputType.Library)
|
||||
OutputName = LibraryName;
|
||||
|
||||
var result = base.GetOutputFilePath(options, outputType);
|
||||
OutputName = outputName;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -123,9 +142,13 @@ namespace Flax.Build
|
||||
/// <summary>
|
||||
/// Returns true if this build target should use separate (aka main-only) executable file and separate runtime (in shared library). Used on platforms that don't support linking again executable file but only shared library (see HasExecutableFileReferenceSupport).
|
||||
/// </summary>
|
||||
public bool UseSeparateMainExecutable(BuildOptions buildOptions)
|
||||
public virtual bool UseSeparateMainExecutable(BuildOptions buildOptions)
|
||||
{
|
||||
return UseSymbolsExports && OutputType == TargetOutputType.Executable && !buildOptions.Platform.HasExecutableFileReferenceSupport && !Configuration.BuildBindingsOnly;
|
||||
if (OutputType == TargetOutputType.Executable && !Configuration.BuildBindingsOnly)
|
||||
{
|
||||
return !IsMonolithicExecutable || (!buildOptions.Platform.HasExecutableFileReferenceSupport && UseSymbolsExports);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void BuildMainExecutable(TaskGraph graph, BuildOptions buildOptions)
|
||||
@@ -175,7 +198,10 @@ namespace Flax.Build
|
||||
Builder.BuildModuleInner(buildData, mainModule, mainModuleOptions, false);
|
||||
|
||||
// Link executable
|
||||
exeBuildOptions.LinkEnv.InputLibraries.Add(Path.Combine(buildOptions.OutputFolder, buildOptions.Platform.GetLinkOutputFileName(OutputName, LinkerOutput.SharedLibrary)));
|
||||
var engineLibraryType = LinkerOutput.SharedLibrary;
|
||||
if (buildOptions.Toolchain?.Compiler == TargetCompiler.MSVC)
|
||||
engineLibraryType = LinkerOutput.ImportLibrary; // MSVC links DLL against import library
|
||||
exeBuildOptions.LinkEnv.InputLibraries.Add(Path.Combine(buildOptions.OutputFolder, buildOptions.Platform.GetLinkOutputFileName(LibraryName, engineLibraryType)));
|
||||
exeBuildOptions.LinkEnv.InputFiles.AddRange(mainModuleOptions.OutputFiles);
|
||||
exeBuildOptions.DependencyFiles.AddRange(mainModuleOptions.DependencyFiles);
|
||||
exeBuildOptions.OptionalDependencyFiles.AddRange(mainModuleOptions.OptionalDependencyFiles);
|
||||
|
||||
Reference in New Issue
Block a user