using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace UnrealBuildTool
{
///
/// Information about a target, passed along when creating a module descriptor
///
[Serializable]
public class TargetInfo : ISerializable
{
///
/// Name of the target
///
public readonly string Name;
///
/// The platform that the target is being built for
///
public readonly UnrealTargetPlatform Platform;
///
/// The configuration being built
///
public readonly UnrealTargetConfiguration Configuration;
///
/// Architecture that the target is being built for (or an empty string for the default)
///
public readonly string Architecture;
///
/// The project containing the target
///
public readonly FileReference ProjectFile;
///
/// The type of the target (if known)
///
public readonly TargetType? Type;
///
/// Whether the target is monolithic or not (if known)
///
public readonly bool? bIsMonolithic;
///
/// Constructs a TargetInfo for passing to the TargetRules constructor.
///
/// Name of the target being built
/// The platform that the target is being built for
/// The configuration being built
/// The architecture being built for
/// Path to the project file containing the target
public TargetInfo(string Name, UnrealTargetPlatform Platform, UnrealTargetConfiguration Configuration, string Architecture, FileReference ProjectFile)
{
this.Name = Name;
this.Platform = Platform;
this.Configuration = Configuration;
this.Architecture = Architecture;
this.ProjectFile = ProjectFile;
}
///
/// Constructs a TargetInfo for passing to the ModuleRules constructor.
///
/// The constructed target rules object. This is null when passed into a TargetRules constructor, but should be valid at all other times.
public TargetInfo(ReadOnlyTargetRules Rules)
{
this.Name = Rules.Name;
this.Platform = Rules.Platform;
this.Configuration = Rules.Configuration;
this.Architecture = Rules.Architecture;
this.ProjectFile = Rules.ProjectFile;
this.Type = Rules.Type;
this.bIsMonolithic = (Rules.LinkType == TargetLinkType.Monolithic);
}
///
/// Reads a TargetInfo object from a binary archve
///
/// Serialization info
/// Streaming context
public TargetInfo(SerializationInfo Info, StreamingContext Context)
{
Name = Info.GetString("nm");
Platform = (UnrealTargetPlatform)Info.GetInt32("pl");
Architecture = Info.GetString("ar");
Configuration = (UnrealTargetConfiguration)Info.GetInt32("co");
ProjectFile = (FileReference)Info.GetValue("pf", typeof(FileReference));
if (Info.GetBoolean("t?"))
{
Type = (TargetType)Info.GetInt32("tt");
}
if (Info.GetBoolean("m?"))
{
bIsMonolithic = Info.GetBoolean("mo");
}
}
///
/// Serialize the object
///
/// Serialization info
/// Streaming context
public void GetObjectData(SerializationInfo Info, StreamingContext Context)
{
Info.AddValue("nm", Name);
Info.AddValue("pl", (int)Platform);
Info.AddValue("ar", Architecture);
Info.AddValue("co", (int)Configuration);
Info.AddValue("pf", ProjectFile);
Info.AddValue("t?", Type.HasValue);
if (Type.HasValue)
{
Info.AddValue("tt", (int)Type.Value);
}
Info.AddValue("m?", bIsMonolithic.HasValue);
if (bIsMonolithic.HasValue)
{
Info.AddValue("mo", bIsMonolithic);
}
}
///
/// True if the target type is a cooked game.
///
public bool IsCooked
{
get
{
if (!Type.HasValue)
{
throw new BuildException("Trying to access TargetInfo.IsCooked when TargetInfo.Type is not set. Make sure IsCooked is used only in ModuleRules.");
}
return Type == TargetType.Client || Type == TargetType.Game || Type == TargetType.Server;
}
}
///
/// True if the target type is a monolithic binary
///
public bool IsMonolithic
{
get
{
if (!bIsMonolithic.HasValue)
{
throw new BuildException("Trying to access TargetInfo.IsMonolithic when bIsMonolithic is not set. Make sure IsMonolithic is used only in ModuleRules.");
}
return bIsMonolithic.Value;
}
}
}
}