Refactor GDK platform to be base for Xbox consoles
This commit is contained in:
69
Source/Tools/Flax.Build/Platforms/GDK/GDK.cs
Normal file
69
Source/Tools/Flax.Build/Platforms/GDK/GDK.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Flax.Build.Platforms
|
||||
{
|
||||
/// <summary>
|
||||
/// The Microsoft Game Development Kit.
|
||||
/// </summary>
|
||||
/// <seealso cref="Sdk" />
|
||||
public sealed class GDK : Sdk
|
||||
{
|
||||
/// <summary>
|
||||
/// The singleton instance.
|
||||
/// </summary>
|
||||
public static readonly GDK Instance = new GDK();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override TargetPlatform[] Platforms => new[]
|
||||
{
|
||||
TargetPlatform.Windows,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GDK"/> class.
|
||||
/// </summary>
|
||||
public GDK()
|
||||
{
|
||||
if (!Platforms.Contains(Platform.BuildTargetPlatform))
|
||||
return;
|
||||
|
||||
var sdkDir = Environment.GetEnvironmentVariable("GameDKLatest");
|
||||
if (!Directory.Exists(sdkDir))
|
||||
sdkDir = Environment.GetEnvironmentVariable("GRDKLatest");
|
||||
if (Directory.Exists(sdkDir))
|
||||
{
|
||||
if (sdkDir.EndsWith("GRDK\\"))
|
||||
sdkDir = sdkDir.Remove(sdkDir.Length - 6);
|
||||
else if (sdkDir.EndsWith("GRDK"))
|
||||
sdkDir = sdkDir.Remove(sdkDir.Length - 5);
|
||||
RootPath = sdkDir;
|
||||
|
||||
// Read the SDK version number
|
||||
string sdkManifest = Path.Combine(RootPath, "GRDK", "grdk.ini");
|
||||
if (File.Exists(sdkManifest))
|
||||
{
|
||||
var contents = File.ReadAllText(sdkManifest);
|
||||
const string prefix = "_xbld_edition=";
|
||||
var start = contents.IndexOf(prefix) + prefix.Length;
|
||||
var end = contents.IndexOf("\r\n_xbld_full_productbuild");
|
||||
var versionText = contents.Substring(start, end - start);
|
||||
Version = new Version(int.Parse(versionText), 0);
|
||||
|
||||
var minEdition = 200500;
|
||||
if (Version.Major < minEdition)
|
||||
{
|
||||
Log.Error(string.Format("Unsupported GDK version {0}. Minimum supported is edition {1}.", Version.Major, minEdition));
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Info(string.Format("Found GDK {0} at {1}", Version.Major, RootPath));
|
||||
IsValid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
37
Source/Tools/Flax.Build/Platforms/GDK/GDKPlatform.cs
Normal file
37
Source/Tools/Flax.Build/Platforms/GDK/GDKPlatform.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System.Linq;
|
||||
using Flax.Build.Projects.VisualStudio;
|
||||
|
||||
namespace Flax.Build.Platforms
|
||||
{
|
||||
/// <summary>
|
||||
/// The GDK platform implementation.
|
||||
/// </summary>
|
||||
/// <seealso cref="Platform" />
|
||||
/// <seealso cref="Flax.Build.Platforms.WindowsPlatformBase" />
|
||||
public abstract class GDKPlatform : WindowsPlatformBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GDKPlatform"/> class.
|
||||
/// </summary>
|
||||
protected GDKPlatform()
|
||||
{
|
||||
// Visual Studio 2017 or newer required
|
||||
var visualStudio = VisualStudioInstance.GetInstances().FirstOrDefault(x => x.Version == VisualStudioVersion.VisualStudio2017 || x.Version == VisualStudioVersion.VisualStudio2019);
|
||||
if (visualStudio == null)
|
||||
_hasRequiredSDKsInstalled = false;
|
||||
|
||||
// Windows 10.0.19041.0 SDK or newer required
|
||||
var sdks = GetSDKs();
|
||||
if (!sdks.ContainsKey(WindowsPlatformSDK.v10_0_19041_0))
|
||||
_hasRequiredSDKsInstalled = false;
|
||||
|
||||
// v141 toolset or newer required
|
||||
var toolsets = GetToolsets();
|
||||
if (!toolsets.ContainsKey(WindowsPlatformToolset.v141) &&
|
||||
!toolsets.ContainsKey(WindowsPlatformToolset.v142))
|
||||
_hasRequiredSDKsInstalled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
63
Source/Tools/Flax.Build/Platforms/GDK/GDKToolchain.cs
Normal file
63
Source/Tools/Flax.Build/Platforms/GDK/GDKToolchain.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Flax.Build.NativeCpp;
|
||||
|
||||
namespace Flax.Build.Platforms
|
||||
{
|
||||
/// <summary>
|
||||
/// The GDK toolchain implementation.
|
||||
/// </summary>
|
||||
/// <seealso cref="Toolchain" />
|
||||
/// <seealso cref="Flax.Build.Platforms.WindowsToolchainBase" />
|
||||
public abstract class GDKToolchain : WindowsToolchainBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GDKToolchain"/> class.
|
||||
/// </summary>
|
||||
/// <param name="platform">The platform.</param>
|
||||
/// <param name="architecture">The architecture.</param>
|
||||
protected GDKToolchain(GDKPlatform platform, TargetArchitecture architecture)
|
||||
: base(platform, architecture, WindowsPlatformToolset.Latest, WindowsPlatformSDK.v10_0_19041_0)
|
||||
{
|
||||
// Setup system paths
|
||||
SystemIncludePaths.Add(Path.Combine(GDK.Instance.RootPath, "GRDK\\GameKit\\Include"));
|
||||
SystemLibraryPaths.Add(Path.Combine(GDK.Instance.RootPath, "GRDK\\GameKit\\Lib\\amd64"));
|
||||
SystemLibraryPaths.Add(Path.Combine(GDK.Instance.RootPath, "GRDK\\ExtensionLibraries\\Xbox.Services.API.C\\DesignTime\\CommonConfiguration\\Neutral\\Lib\\Release\\" + Toolset));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void SetupEnvironment(BuildOptions options)
|
||||
{
|
||||
base.SetupEnvironment(options);
|
||||
|
||||
options.CompileEnv.PreprocessorDefinitions.Add("PLATFORM_GDK");
|
||||
options.CompileEnv.PreprocessorDefinitions.Add("WINAPI_FAMILY=WINAPI_FAMILY_GAMES");
|
||||
options.CompileEnv.PreprocessorDefinitions.Add("_ATL_NO_DEFAULT_LIBS");
|
||||
options.CompileEnv.PreprocessorDefinitions.Add("__WRL_NO_DEFAULT_LIB__");
|
||||
|
||||
options.LinkEnv.InputLibraries.Add("xgameruntime.lib");
|
||||
options.LinkEnv.InputLibraries.Add("xgameplatform.lib");
|
||||
options.LinkEnv.InputLibraries.Add("Microsoft.Xbox.Services.142.GDK.C.lib");
|
||||
|
||||
var toolsetPath = WindowsPlatformBase.GetToolsets()[Toolset];
|
||||
var toolsPath = WindowsPlatformBase.GetVCToolPath64(Toolset);
|
||||
if (options.CompileEnv.UseDebugCRT)
|
||||
throw new Exception("Don't use debug CRT on GDK.");
|
||||
var name = Path.GetFileName(toolsetPath);
|
||||
var redistToolsPath = Path.Combine(toolsPath, "..", "..", "..", "..", "..", "..", "Redist/MSVC/");
|
||||
var paths = Directory.GetDirectories(redistToolsPath, name.Substring(0, 5) + "*");
|
||||
redistToolsPath = Path.Combine(paths[0], "x64", "Microsoft.VC" + (int)Toolset + ".CRT");
|
||||
redistToolsPath = Utilities.RemovePathRelativeParts(redistToolsPath);
|
||||
options.DependencyFiles.Add(Path.Combine(redistToolsPath, "concrt140.dll"));
|
||||
options.DependencyFiles.Add(Path.Combine(redistToolsPath, "msvcp140.dll"));
|
||||
options.DependencyFiles.Add(Path.Combine(redistToolsPath, "msvcp140_1.dll"));
|
||||
options.DependencyFiles.Add(Path.Combine(redistToolsPath, "msvcp140_2.dll"));
|
||||
options.DependencyFiles.Add(Path.Combine(redistToolsPath, "msvcp140_codecvt_ids.dll"));
|
||||
options.DependencyFiles.Add(Path.Combine(redistToolsPath, "vccorlib140.dll"));
|
||||
options.DependencyFiles.Add(Path.Combine(redistToolsPath, "vcruntime140.dll"));
|
||||
options.DependencyFiles.Add(Path.Combine(redistToolsPath, "vcruntime140_1.dll"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user