Files
FlaxEngine/Source/Tools/Flax.Build/Platforms/Linux/LinuxPlatform.cs
Wojciech Figat eebc4951de Merge branch '1.5' into dotnet7
# Conflicts:
#	Source/Platforms/DotNet/NUnit/agents/net40/nunit-agent.exe
#	Source/Platforms/DotNet/NUnit/agents/net40/nunit.engine.api.dll
#	Source/Platforms/DotNet/NUnit/agents/net40/nunit.engine.core.dll
#	Source/Platforms/DotNet/NUnit/agents/net7.0/nunit.agent.addins
#	Source/Platforms/DotNet/NUnit/nunit.engine.api.dll
#	Source/Platforms/DotNet/NUnit/nunit.engine.core.dll
#	Source/Platforms/DotNet/NUnit/nunit.engine.dll
#	Source/Platforms/DotNet/NUnit/nunit3-console.exe
#	Source/Platforms/DotNet/NUnit/nunit3-console.exe.config
#	Source/Platforms/DotNet/NUnit/testcentric.engine.metadata.dll
#	Source/Tools/Flax.Build/Deps/Downloader.cs
#	Source/Tools/Flax.Stats/CodeFrame.cs
#	Source/Tools/Flax.Stats/CodeFrameNode.cs
#	Source/Tools/Flax.Stats/Flax.Stats.Build.cs
#	Source/Tools/Flax.Stats/Languages.cs
#	Source/Tools/Flax.Stats/Program.cs
#	Source/Tools/Flax.Stats/TaskType.cs
#	Source/Tools/Flax.Stats/Tools.cs
#	Source/Tools/FlaxEngine.Tests/TestEditorUtils.cs
2023-01-10 15:49:44 +01:00

105 lines
3.7 KiB
C#

// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
using System.IO;
namespace Flax.Build.Platforms
{
/// <summary>
/// The Linux build platform implementation.
/// </summary>
/// <seealso cref="Platform" />
/// <seealso cref="UnixPlatform" />
public class LinuxPlatform : UnixPlatform
{
/// <inheritdoc />
public override TargetPlatform Target => TargetPlatform.Linux;
/// <inheritdoc />
public override bool HasRequiredSDKsInstalled { get; }
/// <inheritdoc />
public override bool HasSharedLibrarySupport => true;
/// <summary>
/// The toolchain folder root.
/// </summary>
public readonly string ToolchainRoot;
/// <summary>
/// The compiler name.
/// </summary>
public readonly string Compiler;
/// <summary>
/// Initializes a new instance of the <see cref="LinuxPlatform"/> class.
/// </summary>
public LinuxPlatform()
{
// Try to use system compiler
if (Platform.BuildTargetPlatform == TargetPlatform.Linux)
{
// Pick the newest compiler (overriden by specified in command line)
if (Which(Configuration.Compiler) != null)
Compiler = Configuration.Compiler;
else if (Which("clang++-10") != null)
Compiler = "clang++-10";
else if (Which("clang++-9") != null)
Compiler = "clang++-9";
else if (Which("clang++-8") != null)
Compiler = "clang++-8";
else if (Which("clang++-7") != null)
Compiler = "clang++-7";
else if (Which("clang++-6") != null)
Compiler = "clang++-6";
else if (Which("clang++") != null)
Compiler = "clang++";
}
if (Compiler != null)
{
// System compiler
ToolchainRoot = "/";
Log.Verbose($"Using native Linux toolchain (compiler {Compiler})");
HasRequiredSDKsInstalled = true;
}
else if (Platform.BuildTargetPlatform != TargetPlatform.Mac)
{
// Check if Linux toolchain is installed
string toolchainName = "v13_clang-7.0.1-centos7";
string toolchainsRoot = Environment.GetEnvironmentVariable("LINUX_TOOLCHAINS_ROOT");
if (string.IsNullOrEmpty(toolchainsRoot) || !Directory.Exists(Path.Combine(toolchainsRoot, toolchainName)))
{
if (string.IsNullOrEmpty(toolchainsRoot))
{
Log.Warning("Missing Linux Toolchain. Cannot build for Linux platform.");
}
return;
}
// Installed toolchain
ToolchainRoot = Path.Combine(toolchainsRoot, toolchainName).Replace('\\', '/');
Log.Verbose(string.Format("Found Linux Toolchain at {0}", ToolchainRoot));
HasRequiredSDKsInstalled = true;
}
}
/// <inheritdoc />
protected override Toolchain CreateToolchain(TargetArchitecture architecture)
{
return new LinuxToolchain(this, architecture);
}
/// <inheritdoc />
public override bool CanBuildPlatform(TargetPlatform platform)
{
switch (platform)
{
case TargetPlatform.Linux: return HasRequiredSDKsInstalled;
case TargetPlatform.Android: return AndroidSdk.Instance.IsValid && AndroidNdk.Instance.IsValid;
default: return false;
}
}
}
}