// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace UnrealBuildTool
{
class HTML5Platform : UEBuildPlatform
{
///
/// Architecture to build for. Use -win32 for win32 builds (build html5 platform as a win32 binary for debugging).
///
[XmlConfigFile]
public static string HTML5Architecture = "";
HTML5PlatformSDK SDK;
public HTML5Platform(HTML5PlatformSDK InSDK) : base(UnrealTargetPlatform.HTML5, CppPlatform.HTML5)
{
SDK = InSDK;
}
///
/// Whether the required external SDKs are installed for this platform. Could be either a manual install or an AutoSDK.
///
public override SDKStatus HasRequiredSDKsInstalled()
{
return SDK.HasRequiredSDKsInstalled();
}
// The current architecture - affects everything about how UBT operates on HTML5
public override string GetDefaultArchitecture(FileReference ProjectFile)
{
// by default, use an empty architecture (which is really just a modifier to the platform for some paths/names)
return HTML5Platform.HTML5Architecture;
}
public override void ResetTarget(TargetRules Target)
{
ValidateTarget(Target);
}
public override void ValidateTarget(TargetRules Target)
{
Target.bCompileLeanAndMeanUE = true;
Target.bCompileAPEX = false;
Target.bCompileNvCloth = false;
Target.bCompilePhysX = true;
Target.bRuntimePhysicsCooking = false;
Target.bCompileSimplygon = false;
Target.bCompileSimplygonSSF = false;
Target.bCompileForSize = true;
Target.bUsePCHFiles = false;
Target.bDeployAfterCompile = true;
}
public override void PreBuildSync()
{
HTML5ToolChain.PreBuildSync();
}
// F5 should always try to run the Win32 version
public override FileReference ModifyNMakeOutput(FileReference ExeName)
{
// nmake Run should always run the win32 version
return (ExeName + "-win32").ChangeExtension(".exe");
}
public override bool CanUseXGE()
{
return (HTML5Architecture == "-win32");
}
///
/// Get the extension to use for the given binary type
///
/// The binary type being built
/// string The binary extension (ie 'exe' or 'dll')
public override string GetBinaryExtension(UEBuildBinaryType InBinaryType)
{
if (HTML5Architecture == "-win32")
{
switch (InBinaryType)
{
case UEBuildBinaryType.DynamicLinkLibrary:
return ".dll";
case UEBuildBinaryType.Executable:
return ".exe";
case UEBuildBinaryType.StaticLibrary:
return ".lib";
case UEBuildBinaryType.Object:
return ".o";
case UEBuildBinaryType.PrecompiledHeader:
return ".gch";
}
return base.GetBinaryExtension(InBinaryType);
}
else
{
switch (InBinaryType)
{
case UEBuildBinaryType.DynamicLinkLibrary:
return ".js";
case UEBuildBinaryType.Executable:
return ".js";
case UEBuildBinaryType.StaticLibrary:
return ".bc";
case UEBuildBinaryType.Object:
return ".bc";
case UEBuildBinaryType.PrecompiledHeader:
return ".gch";
}
return base.GetBinaryExtension(InBinaryType);
}
}
///
/// Get the extension to use for debug info for the given binary type
///
/// The target being built
/// The binary type being built
/// string The debug info extension (i.e. 'pdb')
public override string GetDebugInfoExtension(ReadOnlyTargetRules InTarget, UEBuildBinaryType InBinaryType)
{
if (HTML5Architecture == "-win32")
{
switch (InBinaryType)
{
case UEBuildBinaryType.DynamicLinkLibrary:
return ".pdb";
case UEBuildBinaryType.Executable:
return ".pdb";
}
return "";
}
else
{
return "";
}
}
///
/// Whether this platform should build a monolithic binary
///
public override bool ShouldCompileMonolithicBinary(UnrealTargetPlatform InPlatform)
{
// This platform currently always compiles monolithic
return true;
}
///
/// Whether the editor should be built for this platform or not
///
/// The UnrealTargetPlatform being built
/// The UnrealTargetConfiguration being built
/// bool true if the editor should be built, false if not
public override bool ShouldNotBuildEditor(UnrealTargetPlatform InPlatform, UnrealTargetConfiguration InConfiguration)
{
return true;
}
public override bool BuildRequiresCookedData(UnrealTargetPlatform InPlatform, UnrealTargetConfiguration InConfiguration)
{
return true;
}
///
/// Modify the rules for a newly created module, where the target is a different host platform.
/// This is not required - but allows for hiding details of a particular platform.
///
/// The name of the module
/// The module rules
/// The target being build
public override void ModifyModuleRulesForOtherPlatform(string ModuleName, ModuleRules Rules, ReadOnlyTargetRules Target)
{
if (Target.Platform == UnrealTargetPlatform.Win32 ||
Target.Platform == UnrealTargetPlatform.Win64 ||
Target.Platform == UnrealTargetPlatform.Mac ||
Target.Platform == UnrealTargetPlatform.Linux)
{
// allow standalone tools to use targetplatform modules, without needing Engine
if ((!Target.bBuildRequiresCookedData
&& ModuleName == "Engine"
&& Target.bBuildDeveloperTools)
|| (Target.bForceBuildTargetPlatforms && ModuleName == "TargetPlatform"))
{
Rules.PlatformSpecificDynamicallyLoadedModuleNames.Add("HTML5TargetPlatform");
}
}
}
///
/// Modify the rules for a newly created module, in a target that's being built for this platform.
/// This is not required - but allows for hiding details of a particular platform.
///
/// The name of the module
/// The module rules
/// The target being build
public override void ModifyModuleRulesForActivePlatform(string ModuleName, ModuleRules Rules, ReadOnlyTargetRules Target)
{
if (ModuleName == "Core")
{
Rules.PublicIncludePaths.Add("Runtime/Core/Public/HTML5");
Rules.PublicDependencyModuleNames.Add("zlib");
}
else if (ModuleName == "Engine")
{
Rules.PrivateDependencyModuleNames.Add("zlib");
Rules.PrivateDependencyModuleNames.Add("UElibPNG");
Rules.PublicDependencyModuleNames.Add("UEOgg");
Rules.PublicDependencyModuleNames.Add("Vorbis");
}
}
///
/// Setup the target environment for building
///
/// Settings for the target being compiled
/// The compile environment for this target
/// The link environment for this target
public override void SetUpEnvironment(ReadOnlyTargetRules Target, CppCompileEnvironment CompileEnvironment, LinkEnvironment LinkEnvironment)
{
if (Target.Architecture == "-win32")
{
LinkEnvironment.ExcludedLibraries.Add("LIBCMT");
}
CompileEnvironment.Definitions.Add("PLATFORM_HTML5=1");
if (CompileEnvironment.Architecture == "-win32")
{
CompileEnvironment.Definitions.Add("PLATFORM_HTML5_WIN32=1");
LinkEnvironment.AdditionalLibraries.Add("delayimp.lib");
}
else
{
CompileEnvironment.Definitions.Add("PLATFORM_HTML5_BROWSER=1");
}
// @todo needed?
CompileEnvironment.Definitions.Add("UNICODE");
CompileEnvironment.Definitions.Add("_UNICODE");
CompileEnvironment.Definitions.Add("WITH_AUTOMATION_WORKER=0");
CompileEnvironment.Definitions.Add("REQUIRES_ALIGNED_INT_ACCESS");
CompileEnvironment.Definitions.Add("WITH_OGGVORBIS=1");
CompileEnvironment.Definitions.Add("USE_SCENE_LOCK=0");
}
///
/// Whether this platform should create debug information or not
///
/// The target being built
/// true if debug info should be generated, false if not
public override bool ShouldCreateDebugInfo(ReadOnlyTargetRules Target)
{
switch (Target.Configuration)
{
case UnrealTargetConfiguration.Development:
case UnrealTargetConfiguration.Shipping:
case UnrealTargetConfiguration.Test:
return !Target.bOmitPCDebugInfoInDevelopment;
case UnrealTargetConfiguration.Debug:
default:
// We don't need debug info for Emscripten, and it causes a bunch of issues with linking
return true;
};
}
///
/// Setup the binaries for this specific platform.
///
/// The target being built
///
public override void AddExtraModules(ReadOnlyTargetRules Target, List ExtraModuleNames)
{
ExtraModuleNames.Add("HTML5PlatformFeatures");
}
///
/// Creates a toolchain instance for the given platform.
///
/// The platform to create a toolchain for
/// The target being built
/// New toolchain instance.
public override UEToolChain CreateToolChain(CppPlatform CppPlatform, ReadOnlyTargetRules Target)
{
return new HTML5ToolChain();
}
///
/// Deploys the given target
///
/// Information about the target being deployed
public override void Deploy(UEBuildDeployTarget Target)
{
}
}
class HTML5PlatformSDK : UEBuildPlatformSDK
{
///
/// Whether platform supports switching SDKs during runtime
///
/// true if supports
protected override bool PlatformSupportsAutoSDKs()
{
return true;
}
// platforms can choose if they prefer a correct the the AutoSDK install over the manual install.
protected override bool PreferAutoSDK()
{
return false;
}
public override string GetSDKTargetPlatformName()
{
return "HTML5";
}
///
/// Returns SDK string as required by the platform
///
/// Valid SDK string
protected override string GetRequiredSDKString()
{
return HTML5SDKInfo.EmscriptenVersion();
}
protected override String GetRequiredScriptVersionString()
{
return "3.0";
}
///
/// Whether the required external SDKs are installed for this platform
///
protected override SDKStatus HasRequiredManualSDKInternal()
{
if (!HTML5SDKInfo.IsSDKInstalled())
{
return SDKStatus.Invalid;
}
return SDKStatus.Valid;
}
}
class HTML5PlatformFactory : UEBuildPlatformFactory
{
protected override UnrealTargetPlatform TargetPlatform
{
get { return UnrealTargetPlatform.HTML5; }
}
///
/// Register the platform with the UEBuildPlatform class
///
protected override void RegisterBuildPlatforms(SDKOutputLevel OutputLevel)
{
HTML5PlatformSDK SDK = new HTML5PlatformSDK();
SDK.ManageAndValidateSDK(OutputLevel);
// Make sure the SDK is installed
if ((ProjectFileGenerator.bGenerateProjectFiles == true) || (SDK.HasRequiredSDKsInstalled() == SDKStatus.Valid))
{
bool bRegisterBuildPlatform = true;
// make sure we have the HTML5 files; if not, then this user doesn't really have HTML5 access/files, no need to compile HTML5!
FileReference HTML5TargetPlatformFile = FileReference.Combine(UnrealBuildTool.EngineSourceDirectory, "Developer", "HTML5", "HTML5TargetPlatform", "HTML5TargetPlatform.Build.cs");
if (!FileReference.Exists(HTML5TargetPlatformFile))
{
bRegisterBuildPlatform = false;
Log.TraceWarning("Missing required components (.... HTML5TargetPlatformFile, others here...). Check source control filtering, or try resyncing.");
}
if (bRegisterBuildPlatform == true)
{
// Register this build platform for HTML5
Log.TraceVerbose(" Registering for {0}", UnrealTargetPlatform.HTML5.ToString());
UEBuildPlatform.RegisterBuildPlatform(new HTML5Platform(SDK));
if (HTML5Platform.HTML5Architecture == "-win32")
{
UEBuildPlatform.RegisterPlatformWithGroup(UnrealTargetPlatform.HTML5, UnrealPlatformGroup.Simulator);
}
else
{
UEBuildPlatform.RegisterPlatformWithGroup(UnrealTargetPlatform.HTML5, UnrealPlatformGroup.Device);
}
}
}
}
}
}