Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/Scripts/BuildPhysX.Automation.cs
Ben Marsh 7c77078af1 Copying //UE4/Dev-Core to //UE4/Dev-Main (Source: //UE4/Dev-Core @ 3345728)
#lockdown Nick.Penwarden

==========================
MAJOR FEATURES + CHANGES
==========================

Change 3315219 on 2017/02/21 by Steve.Robb

	Fix for FObjectAndNameAsStringProxyArchive when serializing a TWeakObjectPtr.

Change 3315285 on 2017/02/21 by Steve.Robb

	Explicitly pass string builder into code generation functions.

Change 3315341 on 2017/02/21 by Ben.Marsh

	UAT: Clean up some formatting in StreamCopyDescription output - remove #fyi lines, exclude merge commits, and remove some blank lines.

Change 3315350 on 2017/02/21 by Ben.Marsh

	Fix shared resource files not being rebuilt if the version header changes.

Change 3315823 on 2017/02/21 by Ben.Marsh

	UAT: Use a class derived from AutomationException to return information specific to commandlets failing, rather than putting it in the base class.

Change 3315826 on 2017/02/21 by Ben.Marsh

	UAT: Move Distiller class from general use in UAT; FileFilter provides a much safer and fully featured implementation of the same concepts.

Change 3315857 on 2017/02/21 by Ben.Marsh

	UBT: Remove the StripBaseDirectory() and MakeRerootedFilePath() utility functions from UBT. These operations can now be done more safely with FileReference objects.

Change 3315942 on 2017/02/21 by Ben.Marsh

	UBT: Convert FileFilter to use FileReference and DirectoryReference arguments everywhere.

Change 3316236 on 2017/02/22 by Maciej.Mroz

	#jira UE-42045

	Nativization
	Fixed Warning: TEnumAsByte is not intended for use with enum

Change 3316253 on 2017/02/22 by Robert.Manuszewski

	Fixes for the async log file writer hangs and crashes.

	- potential fix for the logging system hang when running out of disk space while flushing log
	- fix for unexpected concurrency assert when flushing the log buffer to disk

Change 3316293 on 2017/02/22 by Steve.Robb

	GetTypeHash and lexicographical comparison operators (operator<() etc.) for TTuple.

Change 3316342 on 2017/02/22 by Maciej.Mroz

	Nativization: Wrappers (stubs) required only by other wrappers are properly generated.

	#codereview: Mike.Beach

Change 3316344 on 2017/02/22 by Maciej.Mroz

	Fixed crash in nativized Odin
	Async loading properly handles nativized structs.

Change 3316359 on 2017/02/22 by Steve.Robb

	GitHub #3287 : Ignore #pragma in USTRUCTs

	#jira UE-42248

Change 3316389 on 2017/02/22 by Matthew.Griffin

	Switched Installed Engine Filters to multiline properties to make them more readable
	Added Oodle to list of excluded plugins
	#jira UE-42030

Change 3316392 on 2017/02/22 by Ben.Marsh

	UBT: Split out FileReference/DirectoryReference classes into their own file.

Change 3316394 on 2017/02/22 by Ben.Marsh

	UBT: Move FileReference/DirectoryReference extension methods into the appropriate file.

Change 3316411 on 2017/02/22 by Ben.Marsh

	UAT: Remove file functions that take multiple arguments. There's not really a compelling use case for these to exist over looping from the calling code.

Change 3316446 on 2017/02/22 by Ben.Marsh

	UAT: Try disabling function name prefix to log output from UAT, to see if it improves readability. Function names are still included in the log file for debugging.

Change 3316575 on 2017/02/22 by Ben.Marsh

	UAT: Remove unused functionality for dealing with labels, and output a more human readable list of P4 settings at startup.

Change 3318481 on 2017/02/22 by Steve.Robb

	Use of FMath::IsPowerOfTwo in check.
	Static assert to ensure that an inline set allocator will have a hash size of a power of two.

Change 3318496 on 2017/02/22 by Steve.Robb

	Fix for TSet visualizers.

Change 3318919 on 2017/02/23 by Steve.Robb

	Fix for hot reloading UScriptStruct-derived objects in a module, where the CDOs of these objects haven't had PrepareCppStructOps() called on them.

	#jira UE-42178

Change 3318942 on 2017/02/23 by Steve.Robb

	Removal of a redundant insertion which can cause problems on reallocation of the map.

Change 3319010 on 2017/02/23 by Ben.Marsh

	UBT: Fix exception when a file that was previously part of the working set is deleted.

Change 3319134 on 2017/02/23 by Robert.Manuszewski

	Better fix for a deadlock when flushing log while it's already being flushed due to flush timer on the async log writer thread.

Change 3319249 on 2017/02/23 by Matthew.Griffin

	Added a function to check if running with debug game libs instead of checking command line in multiple places
	Added -RunConfig parameter, which has equivalent result to -debug if value of parameter starts with 'debug'
	Added -RunConfig=$(Configuration) as a default commandline argument for Mac so that editor can use debug game libs
	Removed -Shipping argument from VCProject generation as it's not used anymore

Change 3319253 on 2017/02/23 by Maciej.Mroz

	#jira UE-41846

	New mechanism to gather modules necessary for Nativized Assets. The modules are listed based on included headers. Previously the dependencies was gathered only in FBlueprintNativeCodeGenManifest::GatherModuleDependencies.

Change 3319591 on 2017/02/23 by Ben.Marsh

	Don't strip prefixes beginning with WARNING: or ERROR: using the Postp filter.

Change 3320357 on 2017/02/23 by Steven.Hutton

	Slight changes to Add Crash method - Returning select fields instead of entity objects in queries for perf reasons.

Change 3320361 on 2017/02/23 by Steven.Hutton

	Performance improvements subsequent to the recent database changes.

Change 3320446 on 2017/02/23 by Steven.Hutton

	adding my temporary performance tracker class - reports to a private slack channel with add crash performance data.

Change 3320479 on 2017/02/23 by Ben.Marsh

	Fix CIS errors.

Change 3320576 on 2017/02/23 by Jin.Zhang

	Update CrashReporter to use AWS

Change 3320742 on 2017/02/23 by Jin.Zhang

	Merging crash caching

Change 3321119 on 2017/02/24 by Robert.Manuszewski

	DLL injection protection support for non-monolithic builds

Change 3323308 on 2017/02/27 by Matthew.Griffin

	Moved compilation of SwarmInterface after its dependencies so that we will see a build failure immediately if they change version in future

Change 3323423 on 2017/02/27 by Chad.Garyet

	Adding a script to check and warn about csproj targeted .net versions being mismatched

	#JIRA UE-39624

Change 3323442 on 2017/02/27 by Ben.Marsh

	UBT: Output an error if an engine module references a game module.

Change 3323743 on 2017/02/27 by Ben.Marsh

	PR #3303: Resolved PVS scan issues (Contributed by projectgheist)

Change 3323748 on 2017/02/27 by Ben.Marsh

	Convert whitespace to tabs.

Change 3324851 on 2017/02/28 by Chris.Wood

	Add Odin symbol locations to engine config for MDD on CR server.

	NotForLicensees

Change 3324979 on 2017/02/28 by Gil.Gribb

	Fixed bad merge of priority change in the EDL.

Change 3326889 on 2017/03/01 by Steven.Hutton

	Update to buggs controller to generate faster queries.

Change 3326910 on 2017/03/01 by Robert.Manuszewski

	Removing legacy #if from PackageFileSummary.

Change 3327118 on 2017/03/01 by Gil.Gribb

	UE4 - Fixed race that resulted in a memory leak when reading compressed paks.

Change 3327633 on 2017/03/01 by Gil.Gribb

	UE4 - Added a cvar to control the pak precacher thottle.

Change 3327674 on 2017/03/01 by Steve.Robb

	Unified boilerplate between all generated code files.

Change 3328544 on 2017/03/01 by Chris.Wood

	CrashReportProcess.config update (CRP v1.2.17)

	Tweaks to a few values.
	Update website URL to explicitly point to old, non-cloud site on devweb-02.

Change 3328714 on 2017/03/01 by Chris.Wood

	Correct CRP config regression. Point website at new cloud site. Still v1.2.17

Change 3329192 on 2017/03/02 by Matthew.Griffin

	Added Shared Build Id file to the list of Precompiled Build Dependencies in a target receipt so that it's brought into an installed build

Change 3329285 on 2017/03/02 by Ben.Marsh

	UGS: Allow a project to specify a filters for the streams that should be displayed for fast-switching to. The QuickSelectStreamList seting in the [Options] section of the project settings references a depot path containing a list of strings used to filter the stream list. An option is shown to switch back to showing all available streams, if desired.

Change 3330636 on 2017/03/02 by Ben.Marsh

	UBT: Bump version number of C++ include cache to force it to be rebuilt with additional include information for the default RC files.

Change 3331262 on 2017/03/03 by Robert.Manuszewski

	Merging Dev-LoadTimes to Dev-Core (Garbage Collection performance improvements)

	- Improved GC multithreading
	- Improved BeginDestroy performance
	- Introduced ULevelActorCluster for StaticMeshActor and ReflectionCapture actor clustering (can be toggled through project settings or console command gc.ActorClusterEnabled)
	- A few improvements to AddReferencedObjects functions
	- Misc improvements to GC code
	- Garbage Collector now properly handles clusters which had their objects marked as pending kill
	- Blueprints can now create clusters too (can be toggled through project settings or console command gc.BlueprintClusteringEnabled, defaults to disabled)

Change 3331285 on 2017/03/03 by Robert.Manuszewski

	A few fixes for the previous check-in.

Change 3332001 on 2017/03/03 by Ben.Marsh

	UBT: Add support for generating a UDN file containing the valid settings for BuildConfiguration.xml. Pass -configdoc=<filename> on the command line to generate such a file.

Change 3332022 on 2017/03/03 by Ben.Marsh

	Update documentation for where to find the BuildConfiguration settings.

Change 3332031 on 2017/03/03 by Ben.Marsh

	Remove documentation for Windows XP support; it has been removed in the 4.16 release.

Change 3332256 on 2017/03/03 by Ben.Marsh

	UBT: Add support for generating a UDN page containing module and target settings.

Change 3332458 on 2017/03/03 by Ben.Marsh

	UBT: Improvements to generated documentation.

Change 3332459 on 2017/03/03 by Ben.Marsh

	Add generated documentation for .target.cs files, .build.cs files, and BuildConfiguration.xml files.

Change 3332460 on 2017/03/03 by Ben.Marsh

	UBT: Make LinkTypePrivate actually private, so it doesn't show up in the docs.

Change 3332899 on 2017/03/06 by Robert.Manuszewski

	Making sure actor clustering is not used in the editor (fix for actors being deleted when GC runs in the editor)

	#jira UE-42548

Change 3332955 on 2017/03/06 by Maciej.Mroz

	Nativization distinguishes client and server platform:
	- Separated lists on additional assets, additional modules, excluded assets, excluded modules, excluded paths (in config)
	- Context (compilation options, nativization options and platform) is deliveren to BPCOmpilerCppBackend in FCompilerNativizationOptions struct.
	- Wrappers (for unconverted BPs) are created only when they are directly called.

	- Fortnite dedicated server can be nativized

Change 3332990 on 2017/03/06 by Ben.Marsh

	UBT: Add more comprehensive wrapper methods for System.IO.File and System.IO.Directory to FileReference and DirectoryReference.

Change 3333032 on 2017/03/06 by Ben.Marsh

	Documentation for build tools

Change 3333037 on 2017/03/06 by Ben.Marsh

	Add a build step to extract UAT and UBT documentation from XML comments.

Change 3333089 on 2017/03/06 by Ben.Marsh

	UAT: Re-enable logging the calling function to the console in UAT. Needs a pass for readability first.

Change 3333651 on 2017/03/06 by Gil.Gribb

	UE4 - Fix a werid recursive situation where StaticLoadObject could return an object that has not finished loading. Also produces a fatal error if this sometimes happens. EDL only.

Change 3335236 on 2017/03/07 by Ben.Marsh

	UGS: Set the sync changelist separately to the compatibility changelist.

Change 3335261 on 2017/03/07 by Gil.Gribb

	UE4 - Fixed batched render fences when BeginDestroy calls FlushRenderingCommands.

Change 3335740 on 2017/03/07 by Gil.Gribb

	maybe fix static analysis warning

Change 3335945 on 2017/03/07 by Steve.Robb

	Move FFindInstancedReferenceSubobjectHelper code out of header.
	Add map/set property support to allow instanced members of these container types to be handled during CPFUO.

	https://udn.unrealengine.com/questions/349232/tmap-with-instanced-object-as-value-gets-cleared-o.html

Change 3336693 on 2017/03/07 by Ben.Marsh

	UBT: Use shared PCHs for game plugins by default, to reduce time spent generating individual PCHs.

Change 3336694 on 2017/03/07 by Steve.Robb

	Static assert added to TMap to prevent the use of keys which don't implement a GetTypeHash.
	Fixes to types which relied on implicit conversions when calling GetTypeHash.
	Workaround in SAssetView.h and PropertyEditorModule.h for an apparent VC bug where the compiler wrongly instantiates TPointerIsConvertibleFromTo for certain forward-declared types, causing future TSharedPtr conversions to fail.

	#jira UE-42441

Change 3336698 on 2017/03/07 by Steve.Robb

	Hardcoded endpoint handling replaced with a generic string.
	Obsolete .proto and .java code generation removed.

Change 3336811 on 2017/03/07 by Wes.Hunt

	Add a game blacklist to the crash report processor. Fixed a syntax error in Config.cs, added a XML comment to shut up a warning.

Change 3336973 on 2017/03/08 by Steve.Robb

	Fix for missing GetTypeHash in a plugin.

Change 3336996 on 2017/03/08 by Steve.Robb

	Significant refactor of code generation, to try and make data flow more apparent.

Change 3337571 on 2017/03/08 by Steve.Robb

	CIS fixes for missing GetTypeHash functions.
	Non-unity fix.

Change 3337588 on 2017/03/08 by Gil.Gribb

	UE4 - Fixed obscure check with flushing rhi resources.

Change 3337620 on 2017/03/08 by Steve.Robb

	WITH_HOT_RELOAD_CTORS macros removed.
	UseVTableConstructors config option removed.

Change 3339369 on 2017/03/09 by Steve.Robb

	GetTypeHash overload for nn::account::Uid.

Change 3339464 on 2017/03/09 by Daniel.Lamb

	Fixed assert in 4.15 to do with trying to gather dependency info from invalid packages.
	#jira UE-42583
	#test Editor + Cook + Run shootergame

Change 3339465 on 2017/03/09 by Maciej.Mroz

	Fixed serialization issue, after UserDefinedEnum was used in EnumProperty.

Change 3339469 on 2017/03/09 by Maciej.Mroz

	Fixed Nativization problem, when default value is passed as non-const reference.

Change 3340178 on 2017/03/09 by Daniel.Lamb

	Added support for in memory only packages.  The Cooker ignores these and added core functions to recognize these packages.
	Other systems will need to add support where nessisary.

Change 3341002 on 2017/03/10 by Maciej.Mroz

	Nativization: Fixed FFindHeadersToInclude. Headers necessary for owners of subobjects are properly included.

Change 3341076 on 2017/03/10 by Steve.Robb

	Fix for FBakedTextureSourceInfo move semantics.

	#jira UE-42658

Change 3341160 on 2017/03/10 by Gil.Gribb

	UE4 - Fix hazard with SetMaterialUsage from a thread.

Change 3341409 on 2017/03/10 by Steve.Robb

	Reduction of the generated code size for StaticRegisterNatives functions.

Change 3341523 on 2017/03/10 by Steve.Robb

	Code generation simplified.

Change 3341800 on 2017/03/10 by Ben.Marsh

	UnrealVS: Fix UnrealVS compatibility with RTM version of Visual Studio 2017. 2017 toolchain for extensions is no longer able to build <= 2015 extensions due to validation of the VSIX manifest, so create a separate solution for it.

Change 3342034 on 2017/03/10 by Ben.Marsh

	Fix compiler setting not being loaded correctly into the Windows target settings dialog.

	#jira UE-42746

Change 3342041 on 2017/03/10 by Ben.Marsh

	Fix -ErrorOnEngineContentUse not being set in the cooker options correctly.

Change 3342094 on 2017/03/10 by Steve.Robb

	Fix to deteministic name order during code generation.

Change 3342251 on 2017/03/10 by Daniel.Lamb

	Integrate fix for resave lightmaps commandlet when upgrading from no mapbuilddatapackages to mapbuilddatapackages.
	#thanks Tim.Hagberg

	#test None

Change 3342961 on 2017/03/13 by Robert.Manuszewski

	Fixing memory leak when playing while running -nullrhi on the commandline in cooked games caused by shader resources not being destroyed.

	#jira FORT-38977

Change 3343022 on 2017/03/13 by Steve.Robb

	GetTypeHash fixes for FUniqueNetIdLive.

	#jira UE-42788

Change 3343448 on 2017/03/13 by Steve.Robb

	Compiled-in defer object order fixed.
	Debuggability of the deferred registration map improved.

	#jira UE-42828

[CL 3345747 by Ben Marsh in Main branch]
2017-03-14 15:48:33 -04:00

1573 lines
61 KiB
C#

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Linq;
using System.Reflection;
using Microsoft.Win32;
using System.Diagnostics;
using System.Text.RegularExpressions;
using AutomationTool;
using UnrealBuildTool;
[Help("Builds PhysX/APEX libraries using CMake build system.")]
[Help("TargetLibs", "Specify a list of target libraries to build, separated by '+' characters (eg. -TargetLibs=PhysX+APEX). Default is PhysX+APEX.")]
[Help("TargetPlatforms", "Specify a list of target platforms to build, separated by '+' characters (eg. -TargetPlatforms=Win32+Win64). Architectures are specified with '-'. Default is Win32+Win64+PS4.")]
[Help("TargetConfigs", "Specify a list of configurations to build, separated by '+' characters (eg. -TargetConfigs=profile+debug). Default is profile+release+checked.")]
[Help("TargetWindowsCompilers", "Specify a list of target compilers to use when building for Windows, separated by '+' characters (eg. -TargetCompilers=VisualStudio2012+VisualStudio2015). Default is VisualStudio2013+VisualStudio2015.")]
[Help("SkipBuild", "Do not perform build step. If this argument is not supplied libraries will be built (in accordance with TargetLibs, TargetPlatforms and TargetWindowsCompilers).")]
[Help("SkipDeployLibs", "Do not perform library deployment to the engine. If this argument is not supplied libraries will be copied into the engine.")]
[Help("SkipDeploySource", "Do not perform source deployment to the engine. If this argument is not supplied source will be copied into the engine.")]
[Help("SkipCreateChangelist", "Do not create a P4 changelist for source or libs. If this argument is not supplied source and libs will be added to a Perforce changelist.")]
[Help("SkipSubmit", "Do not perform P4 submit of source or libs. If this argument is not supplied source and libs will be automatically submitted to Perforce. If SkipCreateChangelist is specified, this argument applies by default.")]
[RequireP4]
class BuildPhysX : BuildCommand
{
const int InvalidChangeList = -1;
// The libs we can optionally build
private enum PhysXTargetLib
{
PhysX,
APEX, // Note: Building APEX deploys shared binaries and libs
NvCloth
}
private struct TargetPlatformData
{
public UnrealTargetPlatform Platform;
public string Architecture;
public TargetPlatformData(UnrealTargetPlatform InPlatform)
{
Platform = InPlatform;
// Linux never has an empty architecture. If we don't care then it's x86_64-unknown-linux-gnu
Architecture = (Platform == UnrealTargetPlatform.Linux) ? "x86_64-unknown-linux-gnu" : "";
}
public TargetPlatformData(UnrealTargetPlatform InPlatform, string InArchitecture)
{
Platform = InPlatform;
Architecture = InArchitecture;
}
public override string ToString()
{
return Architecture == "" ? Platform.ToString() : Platform.ToString() + "_" + Architecture;
}
}
// Apex libs that do not have an APEX prefix in their name
private static string[] APEXSpecialLibs = { "NvParameterized", "RenderDebug" };
// We cache our own MSDev and MSBuild executables
private static UnrealBuildTool.FileReference MsDev14Exe;
private static UnrealBuildTool.FileReference MsBuildExe;
// Cache directories under the PhysX/ directory
private static UnrealBuildTool.DirectoryReference PhysXSourceRootDirectory = UnrealBuildTool.DirectoryReference.Combine(CommandUtils.RootDirectory, "Engine", "Source", "ThirdParty", "PhysX");
private static UnrealBuildTool.DirectoryReference PhysX34SourceRootDirectory = UnrealBuildTool.DirectoryReference.Combine(PhysXSourceRootDirectory, "PhysX_3.4");
private static UnrealBuildTool.DirectoryReference APEX14SourceRootDirectory = UnrealBuildTool.DirectoryReference.Combine(PhysXSourceRootDirectory, "APEX_1.4");
private static UnrealBuildTool.DirectoryReference NvClothSourceRootDirectory = UnrealBuildTool.DirectoryReference.Combine(PhysXSourceRootDirectory, "NvCloth");
private static UnrealBuildTool.DirectoryReference SharedSourceRootDirectory = UnrealBuildTool.DirectoryReference.Combine(PhysXSourceRootDirectory, "PxShared");
private static UnrealBuildTool.DirectoryReference RootOutputBinaryDirectory = UnrealBuildTool.DirectoryReference.Combine(CommandUtils.RootDirectory, "Engine", "Binaries", "ThirdParty", "PhysX");
private static UnrealBuildTool.DirectoryReference RootOutputLibDirectory = UnrealBuildTool.DirectoryReference.Combine(PhysXSourceRootDirectory, "Lib");
//private static UnrealBuildTool.DirectoryReference PhysX34SourceLibRootDirectory = UnrealBuildTool.DirectoryReference.Combine(PhysX34SourceRootDirectory, "Lib");
//private static UnrealBuildTool.DirectoryReference APEX14SourceLibRootDirectory = UnrealBuildTool.DirectoryReference.Combine(APEX14SourceRootDirectory, "Lib");
//private static UnrealBuildTool.DirectoryReference SharedSourceLibRootDirectory = UnrealBuildTool.DirectoryReference.Combine(SharedSourceRootDirectory, "Lib");
//private static UnrealBuildTool.DirectoryReference PhysXEngineBinaryRootDirectory = UnrealBuildTool.DirectoryReference.Combine(UnrealBuildTool.UnrealBuildTool.RootDirectory, "Engine\\Binaries\\ThirdParty\\PhysX");
//private static UnrealBuildTool.DirectoryReference PhysX34EngineBinaryRootDirectory = UnrealBuildTool.DirectoryReference.Combine(PhysXEngineBinaryRootDirectory, "PhysX-3.4");
//private static UnrealBuildTool.DirectoryReference APEX14EngineBinaryRootDirectory = UnrealBuildTool.DirectoryReference.Combine(PhysXEngineBinaryRootDirectory, "APEX-1.4");
//private static UnrealBuildTool.DirectoryReference SharedEngineBinaryRootDirectory = UnrealBuildTool.DirectoryReference.Combine(PhysXEngineBinaryRootDirectory, "PxShared-1.0");
private static string GetCMakeNameAndSetupEnv(TargetPlatformData TargetData)
{
DirectoryReference CMakeRootDirectory = DirectoryReference.Combine(CommandUtils.RootDirectory, "Engine", "Extras", "ThirdPartyNotUE", "CMake");
if(BuildHostPlatform.Current.Platform == UnrealTargetPlatform.Linux)
{
return "cmake";
}
Environment.SetEnvironmentVariable("CMAKE_ROOT", DirectoryReference.Combine(CMakeRootDirectory, "share").ToString());
Log("set {0}={1}", "CMAKE_ROOT", Environment.GetEnvironmentVariable("CMAKE_ROOT"));
switch (TargetData.Platform)
{
case UnrealTargetPlatform.HTML5:
return "cmake";
case UnrealTargetPlatform.Mac:
case UnrealTargetPlatform.IOS:
case UnrealTargetPlatform.TVOS:
return FileReference.Combine(CMakeRootDirectory, "bin", "cmake").ToString();
default:
return FileReference.Combine(CMakeRootDirectory, "bin", "cmake.exe").ToString();
}
}
private static string GetCMakeTargetDirectoryName(TargetPlatformData TargetData, WindowsCompiler TargetWindowsCompiler)
{
string VisualStudioDirectoryName;
switch (TargetWindowsCompiler)
{
case WindowsCompiler.VisualStudio2013:
VisualStudioDirectoryName = "VS2013";
break;
case WindowsCompiler.VisualStudio2015:
VisualStudioDirectoryName = "VS2015";
break;
default:
throw new AutomationException(String.Format("Non-CMake or unsupported windows compiler '{0}' supplied to GetCMakeTargetDirectoryName", TargetWindowsCompiler));
}
switch (TargetData.Platform)
{
// Note slashes need to be '/' as this gets string-composed in the CMake script with other paths
case UnrealTargetPlatform.Win32:
return "Win32/" + VisualStudioDirectoryName;
case UnrealTargetPlatform.Win64:
return "Win64/" + VisualStudioDirectoryName;
case UnrealTargetPlatform.Android:
switch (TargetData.Architecture)
{
default:
case "armv7": return "Android/ARMv7";
case "arm64": return "Android/ARM64";
case "x86": return "Android/x86";
case "x64": return "Android/x64";
}
case UnrealTargetPlatform.HTML5:
default:
return TargetData.Platform.ToString();
}
}
private static UnrealBuildTool.DirectoryReference GetProjectDirectory(PhysXTargetLib TargetLib, TargetPlatformData TargetData, WindowsCompiler TargetWindowsCompiler = WindowsCompiler.VisualStudio2015)
{
UnrealBuildTool.DirectoryReference Directory = new UnrealBuildTool.DirectoryReference(GetTargetLibRootDirectory(TargetLib).ToString());
switch(TargetLib)
{
case PhysXTargetLib.PhysX:
Directory = UnrealBuildTool.DirectoryReference.Combine(Directory, "Source");
break;
case PhysXTargetLib.APEX:
// APEX has its 'compiler' directory in a different location off the root of APEX
break;
}
return UnrealBuildTool.DirectoryReference.Combine(Directory, "compiler", GetCMakeTargetDirectoryName(TargetData, TargetWindowsCompiler));
}
private static string GetLinuxToolchainSettings(TargetPlatformData TargetData)
{
if (BuildHostPlatform.Current.Platform == UnrealTargetPlatform.Linux)
{
// in native builds we don't really use a crosstoolchain description, just use system compiler
return " -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++";
}
// otherwise, use a per-architecture file.
return " -DCMAKE_TOOLCHAIN_FILE=\"" + PhysXSourceRootDirectory + "\\Externals\\CMakeModules\\Linux\\LinuxCrossToolchain.multiarch.cmake\"" + " -DARCHITECTURE_TRIPLE=" + TargetData.Architecture;
}
private static string GetCMakeArguments(PhysXTargetLib TargetLib, TargetPlatformData TargetData, string BuildConfig = "", WindowsCompiler TargetWindowsCompiler = WindowsCompiler.VisualStudio2015)
{
string VisualStudioName;
switch(TargetWindowsCompiler)
{
case WindowsCompiler.VisualStudio2013:
VisualStudioName = "Visual Studio 12 2013";
break;
case WindowsCompiler.VisualStudio2015:
VisualStudioName = "Visual Studio 14 2015";
break;
default:
throw new AutomationException(String.Format("Non-CMake or unsupported platform '{0}' supplied to GetCMakeArguments", TargetData.ToString()));
}
string OutputFlags = " -DPX_OUTPUT_LIB_DIR=" + GetPlatformLibDirectory(TargetData, TargetWindowsCompiler);
if(PlatformHasBinaries(TargetData))
{
OutputFlags += " -DPX_OUTPUT_DLL_DIR=" + GetPlatformBinaryDirectory(TargetData, TargetWindowsCompiler) + " -DPX_OUTPUT_EXE_DIR=" + GetPlatformBinaryDirectory(TargetData, TargetWindowsCompiler);
}
// Enable response files for platforms that require them.
// Response files are used for include paths etc, to fix max command line length issues.
switch (TargetData.Platform)
{
case UnrealTargetPlatform.PS4:
case UnrealTargetPlatform.Linux:
OutputFlags += " -DUSE_RESPONSE_FILES=1";
break;
}
string ApexFlags = " -DAPEX_ENABLE_UE4=1";
switch (TargetLib)
{
case PhysXTargetLib.PhysX:
DirectoryReference PhysXCMakeFiles = DirectoryReference.Combine(PhysX34SourceRootDirectory, "Source", "compiler", "cmake");
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
return DirectoryReference.Combine(PhysXCMakeFiles, "Windows").ToString() + " -G \"" + VisualStudioName + "\" -AWin32 -DTARGET_BUILD_PLATFORM=Windows" + OutputFlags;
case UnrealTargetPlatform.Win64:
return DirectoryReference.Combine(PhysXCMakeFiles, "Windows").ToString() + " -G \"" + VisualStudioName + "\" -Ax64 -DTARGET_BUILD_PLATFORM=Windows" + OutputFlags;
case UnrealTargetPlatform.PS4:
return DirectoryReference.Combine(PhysXCMakeFiles, "PS4").ToString() + " -G \"Unix Makefiles\" -DTARGET_BUILD_PLATFORM=PS4 -DCMAKE_BUILD_TYPE=" + BuildConfig + " -DCMAKE_TOOLCHAIN_FILE=\"" + PhysXSourceRootDirectory + "\\Externals\\CMakeModules\\PS4\\PS4Toolchain.txt\"" + OutputFlags;
case UnrealTargetPlatform.XboxOne:
return DirectoryReference.Combine(PhysXCMakeFiles, "XboxOne").ToString() + " -G \"Visual Studio 14 2015\" -DTARGET_BUILD_PLATFORM=XboxOne -DCMAKE_TOOLCHAIN_FILE=\"" + PhysXSourceRootDirectory + "\\Externals\\CMakeModules\\XboxOne\\XboxOneToolchain.txt\" -DCMAKE_GENERATOR_PLATFORM=DURANGO" + OutputFlags;
case UnrealTargetPlatform.Android:
string NDKDirectory = Environment.GetEnvironmentVariable("NDKROOT");
// don't register if we don't have an NDKROOT specified
if (String.IsNullOrEmpty(NDKDirectory))
{
throw new BuildException("NDKROOT is not specified; cannot build Android.");
}
NDKDirectory = NDKDirectory.Replace("\"", "");
string AndroidAPILevel = "android-19";
string AndroidABI = "armeabi-v7a";
switch (TargetData.Architecture)
{
case "armv7": AndroidAPILevel = "android-19"; AndroidABI = "armeabi-v7a"; break;
case "arm64": AndroidAPILevel = "android-21"; AndroidABI = "arm64-v8a"; break;
case "x86": AndroidAPILevel = "android-19"; AndroidABI = "x86"; break;
case "x64": AndroidAPILevel = "android-21"; AndroidABI = "x86_64"; break;
}
return DirectoryReference.Combine(PhysXCMakeFiles, "Android").ToString() + " -G \"MinGW Makefiles\" -DTARGET_BUILD_PLATFORM=Android -DCMAKE_BUILD_TYPE=" + BuildConfig + " -DCMAKE_TOOLCHAIN_FILE=\"" + PhysXSourceRootDirectory + "\\Externals\\CMakeModules\\Android\\android.toolchain.cmake\" -DANDROID_NDK=\"" + NDKDirectory + "\" -DCMAKE_MAKE_PROGRAM=\"" + NDKDirectory + "\\prebuilt\\windows-x86_64\\bin\\make.exe\" -DANDROID_NATIVE_API_LEVEL=\"" + AndroidAPILevel + "\" -DANDROID_ABI=\"" + AndroidABI + "\" -DANDROID_STL=gnustl_shared" + OutputFlags;
case UnrealTargetPlatform.Linux:
return DirectoryReference.Combine(PhysXCMakeFiles, "Linux").ToString() + " --no-warn-unused-cli -G \"Unix Makefiles\" -DTARGET_BUILD_PLATFORM=Linux -DPX_STATIC_LIBRARIES=1 -DCMAKE_BUILD_TYPE=" + BuildConfig + GetLinuxToolchainSettings(TargetData) + OutputFlags;
case UnrealTargetPlatform.Mac:
return DirectoryReference.Combine(PhysXCMakeFiles, "Mac").ToString() + " -G \"Xcode\" -DTARGET_BUILD_PLATFORM=Mac" + OutputFlags;
case UnrealTargetPlatform.IOS:
return DirectoryReference.Combine(PhysXCMakeFiles, "IOS").ToString() + " -G \"Xcode\" -DTARGET_BUILD_PLATFORM=IOS" + OutputFlags;
case UnrealTargetPlatform.TVOS:
return DirectoryReference.Combine(PhysXCMakeFiles, "TVOS").ToString() + " -G \"Xcode\" -DTARGET_BUILD_PLATFORM=TVOS" + OutputFlags;
case UnrealTargetPlatform.Switch:
return DirectoryReference.Combine(PhysXCMakeFiles, "Switch").ToString() + " -G \"Unix Makefiles\" -DTARGET_BUILD_PLATFORM=Switch -DCMAKE_BUILD_TYPE=" + BuildConfig + " -DCMAKE_TOOLCHAIN_FILE=\"" + PhysXSourceRootDirectory + "\\Externals\\CMakeModules\\Switch\\SwitchToolchain.cmake\"" + OutputFlags;
case UnrealTargetPlatform.HTML5:
string CmakeToolchainFile = FileReference.Combine(PhysXSourceRootDirectory, "Externals", "CMakeModules", "HTML5", "Emscripten." + BuildConfig + ".cmake").ToString();
return DirectoryReference.Combine(PhysXCMakeFiles, "HTML5").ToString() +
" -G \"Unix Makefiles\" -DTARGET_BUILD_PLATFORM=HTML5" +
" -DPXSHARED_ROOT_DIR=\"" + SharedSourceRootDirectory.ToString() + "\"" +
" -DNVSIMD_INCLUDE_DIR=\"" + SharedSourceRootDirectory.ToString() + "/src/NvSimd\"" +
" -DNVTOOLSEXT_INCLUDE_DIRS=\"" + PhysX34SourceRootDirectory + "/externals/nvToolsExt/include\"" +
" -DEMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES=ON " +
" -DCMAKE_BUILD_TYPE=\"Release\" -DCMAKE_TOOLCHAIN_FILE=\"" + CmakeToolchainFile + "\"" +
OutputFlags;
default:
throw new AutomationException(String.Format("Non-CMake or unsupported platform '{0}' supplied to GetCMakeArguments", TargetData.ToString()));
}
case PhysXTargetLib.APEX:
DirectoryReference ApexCMakeFiles = DirectoryReference.Combine(APEX14SourceRootDirectory, "compiler", "cmake");
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
return DirectoryReference.Combine(ApexCMakeFiles, "Windows").ToString() + " -G \"" + VisualStudioName + "\" -AWin32 -DTARGET_BUILD_PLATFORM=Windows" + OutputFlags + ApexFlags;
case UnrealTargetPlatform.Win64:
return DirectoryReference.Combine(ApexCMakeFiles, "Windows").ToString() + " -G \"" + VisualStudioName + "\" -Ax64 -DTARGET_BUILD_PLATFORM=Windows" + OutputFlags + ApexFlags;
case UnrealTargetPlatform.PS4:
return DirectoryReference.Combine(ApexCMakeFiles, "PS4").ToString() + " -G \"Unix Makefiles\" -DTARGET_BUILD_PLATFORM=PS4 -DCMAKE_BUILD_TYPE=" + BuildConfig + " -DCMAKE_TOOLCHAIN_FILE=\"" + PhysXSourceRootDirectory + "\\Externals\\CMakeModules\\PS4\\PS4Toolchain.txt\"" + OutputFlags + ApexFlags;
case UnrealTargetPlatform.XboxOne:
return DirectoryReference.Combine(ApexCMakeFiles, "XboxOne").ToString() + " -G \"Visual Studio 14 2015\" -DTARGET_BUILD_PLATFORM=XboxOne -DCMAKE_TOOLCHAIN_FILE=\"" + PhysXSourceRootDirectory + "\\Externals\\CMakeModules\\XboxOne\\XboxOneToolchain.txt\" -DCMAKE_GENERATOR_PLATFORM=DURANGO" + OutputFlags + ApexFlags;
case UnrealTargetPlatform.Switch:
return DirectoryReference.Combine(ApexCMakeFiles, "Switch").ToString() + " -G \"Unix Makefiles\" -DTARGET_BUILD_PLATFORM=Switch -DCMAKE_BUILD_TYPE=" + BuildConfig + " -DCMAKE_TOOLCHAIN_FILE=\"" + PhysXSourceRootDirectory + "\\Externals\\CMakeModules\\Switch\\SwitchToolchain.cmake\"" + OutputFlags + ApexFlags;
case UnrealTargetPlatform.Linux:
return DirectoryReference.Combine(ApexCMakeFiles, "Linux").ToString() + " --no-warn-unused-cli -G \"Unix Makefiles\" -DTARGET_BUILD_PLATFORM=Linux -DPX_STATIC_LIBRARIES=1 -DCMAKE_BUILD_TYPE=" + BuildConfig + GetLinuxToolchainSettings(TargetData) + OutputFlags + ApexFlags;
case UnrealTargetPlatform.Mac:
return DirectoryReference.Combine(ApexCMakeFiles, "Mac").ToString() + " -G \"Xcode\" -DTARGET_BUILD_PLATFORM=Mac" + OutputFlags + ApexFlags;
default:
throw new AutomationException(String.Format("Non-CMake or unsupported platform '{0}' supplied to GetCMakeArguments", TargetData.ToString()));
}
case PhysXTargetLib.NvCloth:
DirectoryReference NvClothCMakeFiles = DirectoryReference.Combine(NvClothSourceRootDirectory, "compiler", "cmake");
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
return DirectoryReference.Combine(NvClothCMakeFiles, "Windows").ToString() + " -G \"" + VisualStudioName + "\" -AWin32 -DTARGET_BUILD_PLATFORM=Windows" + OutputFlags;
case UnrealTargetPlatform.Win64:
return DirectoryReference.Combine(NvClothCMakeFiles, "Windows").ToString() + " -G \"" + VisualStudioName + "\" -Ax64 -DTARGET_BUILD_PLATFORM=Windows" + OutputFlags;
case UnrealTargetPlatform.PS4:
return DirectoryReference.Combine(NvClothCMakeFiles, "PS4").ToString() + " -G \"Unix Makefiles\" -DTARGET_BUILD_PLATFORM=PS4 -DCMAKE_BUILD_TYPE=" + BuildConfig + " -DCMAKE_TOOLCHAIN_FILE=\"" + PhysXSourceRootDirectory + "\\Externals\\CMakeModules\\PS4\\PS4Toolchain.txt\"" + OutputFlags;
case UnrealTargetPlatform.XboxOne:
return DirectoryReference.Combine(NvClothCMakeFiles, "XboxOne").ToString() + " -G \"Visual Studio 14 2015\" -DTARGET_BUILD_PLATFORM=XboxOne -DCMAKE_TOOLCHAIN_FILE=\"" + PhysXSourceRootDirectory + "\\Externals\\CMakeModules\\XboxOne\\XboxOneToolchain.txt\" -DCMAKE_GENERATOR_PLATFORM=DURANGO" + OutputFlags;
case UnrealTargetPlatform.Linux:
return DirectoryReference.Combine(NvClothCMakeFiles, "Linux").ToString() + " --no-warn-unused-cli -G \"Unix Makefiles\" -DTARGET_BUILD_PLATFORM=Linux -DPX_STATIC_LIBRARIES=1 -DCMAKE_BUILD_TYPE=" + BuildConfig + GetLinuxToolchainSettings(TargetData) + OutputFlags;
case UnrealTargetPlatform.Mac:
return DirectoryReference.Combine(NvClothCMakeFiles, "Mac").ToString() + " -G \"Xcode\" -DTARGET_BUILD_PLATFORM=Mac" + OutputFlags;
default:
throw new AutomationException(String.Format("Non-CMake or unsupported platform '{0}' supplied to GetCMakeArguments", TargetData.ToString()));
}
default:
throw new AutomationException(String.Format("Non-CMake or unsupported lib '{0}' supplied to GetCMakeArguments", TargetLib));
}
}
private static string GetMsDevExe(TargetPlatformData TargetData)
{
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
return MsDev14Exe.ToString();
case UnrealTargetPlatform.Win64:
return MsDev14Exe.ToString();
case UnrealTargetPlatform.XboxOne:
return MsDev14Exe.ToString();
default:
throw new AutomationException(String.Format("Non-MSBuild or unsupported platform '{0}' supplied to GetMsDevExe", TargetData.ToString()));
}
}
private static string GetMsBuildExe(TargetPlatformData TargetData)
{
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
case UnrealTargetPlatform.Win64:
case UnrealTargetPlatform.XboxOne:
return MsBuildExe.ToString();
default:
throw new AutomationException(String.Format("Non-MSBuild or unsupported platform '{0}' supplied to GetMsBuildExe", TargetData.ToString()));
}
}
private static string GetTargetLibSolutionName(PhysXTargetLib TargetLib)
{
switch (TargetLib)
{
case PhysXTargetLib.PhysX:
return "PhysX.sln";
case PhysXTargetLib.APEX:
return "APEX.sln";
case PhysXTargetLib.NvCloth:
return "NvCloth.sln";
default:
throw new AutomationException(String.Format("Unknown target lib '{0}' specified to GetTargetLibSolutionName", TargetLib));
}
}
private static UnrealBuildTool.FileReference GetTargetLibSolutionFileName(PhysXTargetLib TargetLib, TargetPlatformData TargetData, WindowsCompiler TargetWindowsCompiler)
{
UnrealBuildTool.DirectoryReference Directory = GetProjectDirectory(TargetLib, TargetData, TargetWindowsCompiler);
return UnrealBuildTool.FileReference.Combine(Directory, GetTargetLibSolutionName(TargetLib));
}
private static bool DoesPlatformUseMSBuild(TargetPlatformData TargetData)
{
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
case UnrealTargetPlatform.Win64:
case UnrealTargetPlatform.XboxOne:
return true;
default:
return false;
}
}
private static bool DoesPlatformUseMakefiles(TargetPlatformData TargetData)
{
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Android:
case UnrealTargetPlatform.Linux:
case UnrealTargetPlatform.HTML5:
case UnrealTargetPlatform.PS4:
case UnrealTargetPlatform.Switch:
return true;
default:
return false;
}
}
private static bool DoesPlatformUseXcode(TargetPlatformData TargetData)
{
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Mac:
case UnrealTargetPlatform.IOS:
case UnrealTargetPlatform.TVOS:
return true;
default:
return false;
}
}
private static DirectoryReference GetTargetLibRootDirectory(PhysXTargetLib TargetLib)
{
switch (TargetLib)
{
case PhysXTargetLib.PhysX:
return PhysX34SourceRootDirectory;
case PhysXTargetLib.APEX:
return APEX14SourceRootDirectory;
case PhysXTargetLib.NvCloth:
return NvClothSourceRootDirectory;
default:
throw new AutomationException(String.Format("Unknown target lib '{0}' specified to GetTargetLibRootDirectory", TargetLib));
}
}
private List<TargetPlatformData> GetTargetPlatforms()
{
List<TargetPlatformData> TargetPlatforms = new List<TargetPlatformData>();
// Remove any platforms that aren't enabled on the command line
string TargetPlatformFilter = ParseParamValue("TargetPlatforms", "Win32+Win64+PS4");
if (TargetPlatformFilter != null)
{
foreach (string TargetPlatformName in TargetPlatformFilter.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries))
{
string[] TargetPlatformAndArch = TargetPlatformName.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
UnrealTargetPlatform TargetPlatform;
if (!Enum.TryParse(TargetPlatformAndArch[0], out TargetPlatform))
{
throw new AutomationException(String.Format("Unknown target platform '{0}' specified on command line", TargetPlatformName));
}
else
{
if (TargetPlatformAndArch.Count() == 2)
{
TargetPlatforms.Add(new TargetPlatformData(TargetPlatform, TargetPlatformAndArch[1]));
}
else if (TargetPlatformAndArch.Count() > 2)
{
// Linux archs are OS triplets, so have multiple dashes
string DashedArch = TargetPlatformAndArch[1];
for(int Idx = 2; Idx < TargetPlatformAndArch.Count(); ++Idx)
{
DashedArch += "-" + TargetPlatformAndArch[Idx];
}
TargetPlatforms.Add(new TargetPlatformData(TargetPlatform, DashedArch));
}
else
{
TargetPlatforms.Add(new TargetPlatformData(TargetPlatform));
}
}
}
}
return TargetPlatforms;
}
public List<string> GetTargetConfigurations()
{
List<string> TargetConfigs = new List<string>();
// Remove any configs that aren't enabled on the command line
string TargetConfigFilter = ParseParamValue("TargetConfigs", "profile+release+checked");
if (TargetConfigFilter != null)
{
foreach(string TargetConfig in TargetConfigFilter.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries))
{
TargetConfigs.Add(TargetConfig);
}
}
return TargetConfigs;
}
private List<PhysXTargetLib> GetTargetLibs()
{
List<PhysXTargetLib> TargetLibs = new List<PhysXTargetLib>();
string TargetLibsFilter = ParseParamValue("TargetLibs", "PhysX+APEX+NvCloth");
if (TargetLibsFilter != null)
{
foreach (string TargetLibName in TargetLibsFilter.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries))
{
PhysXTargetLib TargetLib;
if (!Enum.TryParse(TargetLibName, out TargetLib))
{
throw new AutomationException(String.Format("Unknown target lib '{0}' specified on command line", TargetLibName));
}
else
{
TargetLibs.Add(TargetLib);
}
}
}
return TargetLibs;
}
private List<WindowsCompiler> GetTargetWindowsCompilers()
{
List<WindowsCompiler> TargetWindowsCompilers = new List<WindowsCompiler>();
string TargetWindowsCompilersFilter = ParseParamValue("TargetWindowsCompilers", "VisualStudio2015+VisualStudio2013");
if (TargetWindowsCompilersFilter != null)
{
foreach (string TargetWindowsCompilerName in TargetWindowsCompilersFilter.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries))
{
WindowsCompiler TargetWindowsCompiler;
if (!Enum.TryParse(TargetWindowsCompilerName, out TargetWindowsCompiler))
{
throw new AutomationException(String.Format("Unknown target windows compiler '{0}' specified on command line", TargetWindowsCompilerName));
}
else
{
TargetWindowsCompilers.Add(TargetWindowsCompiler);
}
}
}
return TargetWindowsCompilers;
}
private static void MakeFreshDirectoryIfRequired(UnrealBuildTool.DirectoryReference Directory)
{
if (!DirectoryReference.Exists(Directory))
{
DirectoryReference.CreateDirectory(Directory);
}
else
{
InternalUtils.SafeDeleteDirectory(Directory.FullName);
DirectoryReference.CreateDirectory(Directory);
}
}
public static int RunLocalProcess(Process LocalProcess)
{
int ExitCode = -1;
// release all process resources
using (LocalProcess)
{
LocalProcess.StartInfo.UseShellExecute = false;
LocalProcess.StartInfo.RedirectStandardOutput = true;
try
{
// Start the process up and then wait for it to finish
LocalProcess.Start();
LocalProcess.BeginOutputReadLine();
LocalProcess.WaitForExit();
ExitCode = LocalProcess.ExitCode;
}
catch (Exception ex)
{
throw new BuildException(ex, "Failed to start local process for action (\"{0}\"): {1} {2}", ex.Message, LocalProcess.StartInfo.FileName, LocalProcess.StartInfo.Arguments);
}
}
return ExitCode;
}
public static int RunLocalProcessAndLogOutput(ProcessStartInfo StartInfo)
{
Process LocalProcess = new Process();
LocalProcess.StartInfo = StartInfo;
LocalProcess.OutputDataReceived += (Sender, Line) => { if (Line != null && Line.Data != null) UnrealBuildTool.Log.TraceInformation(Line.Data); };
return RunLocalProcess(LocalProcess);
}
private static void SetupBuildForTargetLibAndPlatform(PhysXTargetLib TargetLib, TargetPlatformData TargetData, List<string> TargetConfigurations, List<WindowsCompiler> TargetWindowsCompilers, bool bCleanOnly)
{
// make sure we set up the environment variable specifying where the root of the PhysX SDK is
Environment.SetEnvironmentVariable("GW_DEPS_ROOT", PhysXSourceRootDirectory.ToString());
Log("set {0}={1}", "GW_DEPS_ROOT", Environment.GetEnvironmentVariable("GW_DEPS_ROOT"));
Environment.SetEnvironmentVariable("CMAKE_MODULE_PATH", DirectoryReference.Combine(PhysXSourceRootDirectory, "Externals", "CMakeModules").ToString());
Log("set {0}={1}", "CMAKE_MODULE_PATH", Environment.GetEnvironmentVariable("CMAKE_MODULE_PATH"));
string CMakeName = GetCMakeNameAndSetupEnv(TargetData);
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
case UnrealTargetPlatform.Win64:
// for windows platforms we support building against multiple compilers
foreach(WindowsCompiler TargetWindowsCompiler in TargetWindowsCompilers)
{
UnrealBuildTool.DirectoryReference CMakeTargetDirectory = GetProjectDirectory(TargetLib, TargetData, TargetWindowsCompiler);
MakeFreshDirectoryIfRequired(CMakeTargetDirectory);
if(!bCleanOnly)
{
Log("Generating projects for lib " + TargetLib.ToString() + ", " + TargetData.ToString());
ProcessStartInfo StartInfo = new ProcessStartInfo();
StartInfo.FileName = CMakeName;
StartInfo.WorkingDirectory = CMakeTargetDirectory.ToString();
StartInfo.Arguments = GetCMakeArguments(TargetLib, TargetData, "", TargetWindowsCompiler);
RunLocalProcessAndLogOutput(StartInfo);
}
}
break;
case UnrealTargetPlatform.PS4:
case UnrealTargetPlatform.Android:
case UnrealTargetPlatform.Linux:
case UnrealTargetPlatform.Switch:
foreach (string BuildConfig in TargetConfigurations)
{
UnrealBuildTool.DirectoryReference CMakeTargetDirectory = GetProjectDirectory(TargetLib, TargetData);
CMakeTargetDirectory = UnrealBuildTool.DirectoryReference.Combine(CMakeTargetDirectory, BuildConfig);
MakeFreshDirectoryIfRequired(CMakeTargetDirectory);
if (!bCleanOnly)
{
Log("Generating projects for lib " + TargetLib.ToString() + ", " + TargetData.ToString());
ProcessStartInfo StartInfo = new ProcessStartInfo();
StartInfo.FileName = CMakeName;
StartInfo.WorkingDirectory = CMakeTargetDirectory.ToString();
StartInfo.Arguments = GetCMakeArguments(TargetLib, TargetData, BuildConfig);
System.Console.WriteLine("Working in '{0}'", StartInfo.WorkingDirectory);
Log("Working in '{0}'", StartInfo.WorkingDirectory);
System.Console.WriteLine("{0} {1}", StartInfo.FileName, StartInfo.Arguments);
Log("{0} {1}", StartInfo.FileName, StartInfo.Arguments);
if (RunLocalProcessAndLogOutput(StartInfo) != 0)
{
throw new AutomationException(String.Format("Unable to generate projects for {0}.", TargetLib.ToString() + ", " + TargetData.ToString()));
}
}
}
break;
case UnrealTargetPlatform.Mac:
case UnrealTargetPlatform.IOS:
case UnrealTargetPlatform.TVOS:
{
UnrealBuildTool.DirectoryReference CMakeTargetDirectory = GetProjectDirectory(TargetLib, TargetData);
MakeFreshDirectoryIfRequired(CMakeTargetDirectory);
if (!bCleanOnly)
{
Log("Generating projects for lib " + TargetLib.ToString() + ", " + TargetData.ToString());
ProcessStartInfo StartInfo = new ProcessStartInfo();
StartInfo.FileName = CMakeName;
StartInfo.WorkingDirectory = CMakeTargetDirectory.ToString();
StartInfo.Arguments = GetCMakeArguments(TargetLib, TargetData);
RunLocalProcessAndLogOutput(StartInfo);
}
}
break;
case UnrealTargetPlatform.HTML5:
// NOTE: HTML5 does not do "debug" - the full text blows out memory
// instead, HTML5 builds have 4 levels of optimizations
// so, MAP BuildConfig to HTML5 optimization levels
Dictionary<string, string> BuildMap = new Dictionary<string, string>()
{
{"debug", "-O0"},
{"checked", "-O2"},
{"profile", "-Oz"},
{"release", "-O3"}
};
UnrealBuildTool.DirectoryReference HTML5CMakeModules = DirectoryReference.Combine(PhysXSourceRootDirectory, "Externals", "CMakeModules", "HTML5");
MakeFreshDirectoryIfRequired(HTML5CMakeModules);
foreach(string BuildConfig in TargetConfigurations)
{
UnrealBuildTool.DirectoryReference CMakeTargetDirectory = GetProjectDirectory(TargetLib, TargetData);
CMakeTargetDirectory = UnrealBuildTool.DirectoryReference.Combine(CMakeTargetDirectory, "BUILD" + BuildMap[BuildConfig]);
MakeFreshDirectoryIfRequired(CMakeTargetDirectory);
if (!bCleanOnly)
{
Log("Generating projects for lib " + TargetLib.ToString() + ", " + TargetData.ToString());
// CMAKE_TOOLCHAIN_FILE
Environment.SetEnvironmentVariable("LIB_SUFFIX", GetConfigurationSuffix(BuildConfig, TargetData)); // only used in HTML5's CMakefiles
string orig = File.ReadAllText(HTML5SDKInfo.EmscriptenCMakeToolChainFile);
string txt = Regex.Replace(orig, "(EPIC_BUILD_FLAGS}) .*-O2" , "$1 " + BuildMap[BuildConfig] );
string CmakeToolchainFile = FileReference.Combine(HTML5CMakeModules, "Emscripten." + BuildConfig + ".cmake").ToString();
File.WriteAllText(CmakeToolchainFile, txt);
// ----------------------------------------
// CMAKE
ProcessStartInfo StartInfo = new ProcessStartInfo();
StartInfo.FileName = "cmake";
StartInfo.WorkingDirectory = CMakeTargetDirectory.ToString();
StartInfo.Arguments = GetCMakeArguments(TargetLib, TargetData, BuildConfig);
Log("Working in: {0}", StartInfo.WorkingDirectory);
Log("{0} {1}", StartInfo.FileName, StartInfo.Arguments);
if (RunLocalProcessAndLogOutput(StartInfo) != 0)
{
throw new AutomationException(String.Format("Unabled to generate projects for {0}.", TargetLib.ToString() + ", " + TargetData.ToString()));
}
}
}
break;
default:
{
UnrealBuildTool.DirectoryReference CMakeTargetDirectory = GetProjectDirectory(TargetLib, TargetData);
MakeFreshDirectoryIfRequired(CMakeTargetDirectory);
if (!bCleanOnly)
{
Log("Generating projects for lib " + TargetLib.ToString() + ", " + TargetData.ToString());
ProcessStartInfo StartInfo = new ProcessStartInfo();
StartInfo.FileName = CMakeName;
StartInfo.WorkingDirectory = CMakeTargetDirectory.ToString();
StartInfo.Arguments = GetCMakeArguments(TargetLib, TargetData);
RunLocalProcessAndLogOutput(StartInfo);
}
}
break;
}
}
private static string GetMsDevExe(WindowsCompiler Version)
{
DirectoryReference VSPath;
// It's not fatal if VS2013 isn't installed for VS2015 builds (for example, so don't crash here)
if(WindowsExports.TryGetVSInstallDir(Version, out VSPath))
{
return FileReference.Combine(VSPath, "Common7", "IDE", "Devenv.com").FullName;
}
return null;
}
private static string GetMsBuildExe(WindowsCompiler Version)
{
string VisualStudioToolchainVersion = "";
switch (Version)
{
case WindowsCompiler.VisualStudio2013:
VisualStudioToolchainVersion = "12.0";
break;
case WindowsCompiler.VisualStudio2015:
VisualStudioToolchainVersion = "14.0";
break;
}
string ProgramFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
string MSBuildPath = Path.Combine(ProgramFilesPath, "MSBuild", VisualStudioToolchainVersion, "Bin", "MSBuild.exe");
if (File.Exists(MSBuildPath))
{
return MSBuildPath;
}
return null;
}
private static string RemoveOtherMakeFromPath(string WindowsPath)
{
string[] PathComponents = WindowsPath.Split(';');
string NewPath = "";
foreach(string PathComponent in PathComponents)
{
// everything what contains /bin or /sbin is suspicious, check if it has make in it
if (PathComponent.Contains("\\bin") || PathComponent.Contains("/bin") || PathComponent.Contains("\\sbin") || PathComponent.Contains("/sbin"))
{
if (File.Exists(PathComponent + "/make.exe") || File.Exists(PathComponent + "make.exe"))
{
// gotcha!
Log("Removing {0} from PATH since it contains possibly colliding make.exe", PathComponent);
continue;
}
}
NewPath = NewPath + ';' + PathComponent + ';';
}
return NewPath;
}
private static void SetupBuildEnvironment()
{
if (!Utils.IsRunningOnMono)
{
string VS2015Path = GetMsDevExe(WindowsCompiler.VisualStudio2015);
if (VS2015Path != null)
{
MsDev14Exe = new UnrealBuildTool.FileReference(GetMsDevExe(WindowsCompiler.VisualStudio2015));
MsBuildExe = new UnrealBuildTool.FileReference(GetMsBuildExe(WindowsCompiler.VisualStudio2015));
}
// ================================================================================
// ThirdPartyNotUE
// NOTE: these are Windows executables
if (BuildHostPlatform.Current.Platform == UnrealTargetPlatform.Win64)
{
DirectoryReference ThirdPartyNotUERootDirectory = DirectoryReference.Combine(CommandUtils.RootDirectory, "Engine", "Extras", "ThirdPartyNotUE");
string CMakePath = DirectoryReference.Combine(ThirdPartyNotUERootDirectory, "CMake", "bin").ToString();
string MakePath = DirectoryReference.Combine(ThirdPartyNotUERootDirectory, "GNU_Make", "make-3.81", "bin").ToString();
string PrevPath = Environment.GetEnvironmentVariable("PATH");
// mixing bundled make and cygwin make is no good. Try to detect and remove cygwin paths.
string PathWithoutCygwin = RemoveOtherMakeFromPath(PrevPath);
Environment.SetEnvironmentVariable("PATH", CMakePath + ";" + MakePath + ";" + PathWithoutCygwin);
Environment.SetEnvironmentVariable("PATH", CMakePath + ";" + MakePath + ";" + Environment.GetEnvironmentVariable("PATH"));
Log("set {0}={1}", "PATH", Environment.GetEnvironmentVariable("PATH"));
}
// ================================================================================
// HTML5
// FIXME: only run this if GetTargetPlatforms() contains HTML5
// override BuildConfiguration defaults - so we can use HTML5SDKInfo
string EngineSourceDir = GetProjectDirectory(PhysXTargetLib.PhysX, new TargetPlatformData(UnrealTargetPlatform.HTML5)).ToString();
EngineSourceDir = Regex.Replace(EngineSourceDir, @"\\" , "/");
EngineSourceDir = Regex.Replace(EngineSourceDir, ".*Engine/" , "");
if (!HTML5SDKInfo.IsSDKInstalled())
{
throw new AutomationException("EMSCRIPTEN SDK TOOLCHAIN NOT FOUND...");
}
// warm up emscripten config file
HTML5SDKInfo.SetUpEmscriptenConfigFile();
Environment.SetEnvironmentVariable("PATH",
Environment.GetEnvironmentVariable("EMSCRIPTEN") + ";" +
Environment.GetEnvironmentVariable("NODEPATH") + ";" +
Environment.GetEnvironmentVariable("LLVM") + ";" +
Path.GetDirectoryName(HTML5SDKInfo.Python()) + ";" +
Environment.GetEnvironmentVariable("PATH"));
//Log("set {0}={1}", "PATH", Environment.GetEnvironmentVariable("PATH"));
}
}
private static void BuildMSBuildTarget(PhysXTargetLib TargetLib, TargetPlatformData TargetData, List<string> TargetConfigurations, WindowsCompiler TargetWindowsCompiler = WindowsCompiler.VisualStudio2015)
{
string SolutionFile = GetTargetLibSolutionFileName(TargetLib, TargetData, TargetWindowsCompiler).ToString();
string MSDevExe = GetMsDevExe(TargetData);
if (!FileExists(SolutionFile))
{
throw new AutomationException(String.Format("Unabled to build Solution {0}. Solution file not found.", SolutionFile));
}
if (String.IsNullOrEmpty(MSDevExe))
{
throw new AutomationException(String.Format("Unabled to build Solution {0}. devenv.com not found.", SolutionFile));
}
foreach (string BuildConfig in TargetConfigurations)
{
string CmdLine = String.Format("\"{0}\" /build \"{1}\"", SolutionFile, BuildConfig);
RunAndLog(BuildCommand.CmdEnv, MSDevExe, CmdLine);
}
}
private static void BuildXboxTarget(PhysXTargetLib TargetLib, TargetPlatformData TargetData, List<string> TargetConfigurations, WindowsCompiler TargetWindowsCompiler = WindowsCompiler.VisualStudio2015)
{
if (TargetData.Platform != UnrealTargetPlatform.XboxOne)
{
return;
}
string SolutionFile = GetTargetLibSolutionFileName(TargetLib, TargetData, TargetWindowsCompiler).ToString();
string MSBuildExe = GetMsBuildExe(TargetData);
if (!FileExists(SolutionFile))
{
throw new AutomationException(String.Format("Unabled to build Solution {0}. Solution file not found.", SolutionFile));
}
if (String.IsNullOrEmpty(MSBuildExe))
{
throw new AutomationException(String.Format("Unabled to build Solution {0}. msbuild.exe not found.", SolutionFile));
}
string AdditionalProperties = "";
string AutoSDKPropsPath = Environment.GetEnvironmentVariable("XboxOneAutoSDKProp");
if (AutoSDKPropsPath != null && AutoSDKPropsPath.Length > 0)
{
AdditionalProperties += String.Format(";CustomBeforeMicrosoftCommonProps={0}", AutoSDKPropsPath);
}
string XboxCMakeModulesPath = Path.Combine(PhysXSourceRootDirectory.FullName, "Externals", "CMakeModules", "XboxOne", "Microsoft.Cpp.Durango.user.props");
if (File.Exists(XboxCMakeModulesPath))
{
AdditionalProperties += String.Format(";ForceImportBeforeCppTargets={0}", XboxCMakeModulesPath);
}
foreach (string BuildConfig in TargetConfigurations)
{
string CmdLine = String.Format("\"{0}\" /t:build /p:Configuration={1};Platform=Durango{2}", SolutionFile, BuildConfig, AdditionalProperties);
RunAndLog(BuildCommand.CmdEnv, MSBuildExe, CmdLine);
}
}
private static void BuildMakefileTarget(PhysXTargetLib TargetLib, TargetPlatformData TargetData, List<string> TargetConfigurations)
{
// FIXME: use absolute path
string MakeCommand = "make";
// FIXME: "j -16" should be tweakable
//string MakeOptions = "-j 1";
string MakeOptions = "-j 16";
// Bundled GNU make does not pass job number to subprocesses on Windows, work around that...
if (BuildHostPlatform.Current.Platform == UnrealTargetPlatform.Win64)
{
// Redefining the MAKE variable will cause the -j flag to be passed to child make instances.
MakeOptions = string.Format("{1} \"MAKE={0} {1}\"", MakeCommand, MakeOptions);
}
// this will be replaced for HTML5 - see SetupBuildForTargetLibAndPlatform() for details
Dictionary<string, string> BuildMap = new Dictionary<string, string>()
{
{"debug", "debug"},
{"checked", "checked"},
{"profile", "profile"},
{"release", "release"}
};
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Android:
{
// Use make from Android toolchain
string NDKDirectory = Environment.GetEnvironmentVariable("NDKROOT");
// don't register if we don't have an NDKROOT specified
if (String.IsNullOrEmpty(NDKDirectory))
{
throw new BuildException("NDKROOT is not specified; cannot build Android.");
}
NDKDirectory = NDKDirectory.Replace("\"", "");
MakeCommand = NDKDirectory + "\\prebuilt\\windows-x86_64\\bin\\make.exe";
}
break;
case UnrealTargetPlatform.HTML5:
{
// Use emscripten toolchain
MakeCommand = "python";
MakeOptions = HTML5SDKInfo.EMSCRIPTEN_ROOT + "\\emmake make";
BuildMap = new Dictionary<string, string>()
{
{"debug", "Build-O0"},
{"checked", "Build-O2"},
{"profile", "Build-Oz"},
{"release", "Build-O3"}
};
}
break;
default:
break;
}
// makefile build has "projects" for every configuration. However, we abstract away from that by assuming GetProjectDirectory points to the "meta-project"
foreach (string BuildConfig in TargetConfigurations)
{
UnrealBuildTool.DirectoryReference MetaProjectDirectory = GetProjectDirectory(TargetLib, TargetData);
UnrealBuildTool.DirectoryReference ConfigDirectory = UnrealBuildTool.DirectoryReference.Combine(MetaProjectDirectory, BuildMap[BuildConfig]);
Environment.SetEnvironmentVariable("LIB_SUFFIX", GetConfigurationSuffix(BuildConfig, TargetData)); // only used in HTML5's CMakefiles
string Makefile = UnrealBuildTool.FileReference.Combine(ConfigDirectory, "Makefile").ToString();
if (!FileExists(Makefile))
{
throw new AutomationException(String.Format("Unabled to build {0} - file not found.", Makefile));
}
ProcessStartInfo StartInfo = new ProcessStartInfo();
StartInfo.FileName = MakeCommand;
StartInfo.WorkingDirectory = ConfigDirectory.ToString();
StartInfo.Arguments = MakeOptions;
Log("Working in: {0}", StartInfo.WorkingDirectory);
Log("{0} {1}", StartInfo.FileName, StartInfo.Arguments);
if (RunLocalProcessAndLogOutput(StartInfo) != 0)
{
throw new AutomationException(String.Format("Unabled to build {0}. Build process failed.", Makefile));
}
}
}
private static void BuildXcodeTarget(PhysXTargetLib TargetLib, TargetPlatformData TargetData, List<string> TargetConfigurations)
{
UnrealBuildTool.DirectoryReference Directory = GetProjectDirectory(TargetLib, TargetData);
string ProjectName = "";
switch(TargetLib)
{
case PhysXTargetLib.APEX:
ProjectName = "APEX";
break;
case PhysXTargetLib.NvCloth:
ProjectName = "NvCloth";
break;
case PhysXTargetLib.PhysX:
ProjectName = "PhysX";
break;
default:
throw new AutomationException(String.Format("Unabled to build XCode target, Unsupported library {0}.", TargetLib.ToString()));
}
string ProjectFile = UnrealBuildTool.FileReference.Combine(Directory, ProjectName + ".xcodeproj").ToString();
if (!DirectoryExists(ProjectFile))
{
throw new AutomationException(String.Format("Unabled to build project {0}. Project file not found.", ProjectFile));
}
foreach (string BuildConfig in TargetConfigurations)
{
string CmdLine = String.Format("-project \"{0}\" -target=\"ALL_BUILD\" -configuration {1}", ProjectFile, BuildConfig);
RunAndLog(BuildCommand.CmdEnv, "/usr/bin/xcodebuild", CmdLine);
}
}
private static void BuildTargetLibForPlatform(PhysXTargetLib TargetLib, TargetPlatformData TargetData, List<string> TargetConfigurations, List<WindowsCompiler> TargetWindowsCompilers)
{
if (DoesPlatformUseMSBuild(TargetData))
{
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
case UnrealTargetPlatform.Win64:
// for windows platforms we support building against multiple compilers
foreach (WindowsCompiler TargetWindowsCompiler in TargetWindowsCompilers)
{
BuildMSBuildTarget(TargetLib, TargetData, TargetConfigurations, TargetWindowsCompiler);
}
break;
case UnrealTargetPlatform.XboxOne:
BuildXboxTarget(TargetLib, TargetData, TargetConfigurations);
break;
default:
BuildMSBuildTarget(TargetLib, TargetData, TargetConfigurations);
break;
}
}
else if (DoesPlatformUseXcode(TargetData))
{
BuildXcodeTarget(TargetLib, TargetData, TargetConfigurations);
}
else if (DoesPlatformUseMakefiles(TargetData))
{
BuildMakefileTarget(TargetLib, TargetData, TargetConfigurations);
}
else
{
throw new AutomationException(String.Format("Unsupported target platform '{0}' passed to BuildTargetLibForPlatform", TargetData));
}
}
private static DirectoryReference GetPlatformBinaryDirectory(TargetPlatformData TargetData, WindowsCompiler TargetWindowsCompiler)
{
string VisualStudioName = string.Empty;
string ArchName = string.Empty;
if (DoesPlatformUseMSBuild(TargetData))
{
switch (TargetWindowsCompiler)
{
case WindowsCompiler.VisualStudio2013:
VisualStudioName = "VS2013";
break;
case WindowsCompiler.VisualStudio2015:
VisualStudioName = "VS2015";
break;
default:
throw new AutomationException(String.Format("Unsupported visual studio compiler '{0}' supplied to GetOutputBinaryDirectory", TargetWindowsCompiler));
}
}
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
ArchName = "Win32";
break;
case UnrealTargetPlatform.Win64:
ArchName = "Win64";
break;
case UnrealTargetPlatform.Mac:
ArchName = "Mac";
break;
default:
throw new AutomationException(String.Format("Unsupported platform '{0}' supplied to GetOutputBinaryDirectory", TargetData.ToString()));
}
return UnrealBuildTool.DirectoryReference.Combine(RootOutputBinaryDirectory, ArchName, VisualStudioName);
}
private static DirectoryReference GetPlatformLibDirectory(TargetPlatformData TargetData, WindowsCompiler TargetWindowsCompiler)
{
string VisualStudioName = string.Empty;
string ArchName = string.Empty;
if (DoesPlatformUseMSBuild(TargetData))
{
switch (TargetWindowsCompiler)
{
case WindowsCompiler.VisualStudio2013:
VisualStudioName = "VS2013";
break;
case WindowsCompiler.VisualStudio2015:
VisualStudioName = "VS2015";
break;
default:
throw new AutomationException(String.Format("Unsupported visual studio compiler '{0}' supplied to GetOutputLibDirectory", TargetWindowsCompiler));
}
}
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
ArchName = "Win32";
break;
case UnrealTargetPlatform.Win64:
ArchName = "Win64";
break;
case UnrealTargetPlatform.XboxOne:
ArchName = "XboxOne";
break;
case UnrealTargetPlatform.PS4:
ArchName = "PS4";
break;
case UnrealTargetPlatform.Switch:
ArchName = "Switch";
break;
case UnrealTargetPlatform.Android:
switch (TargetData.Architecture)
{
default:
case "arm7": ArchName = "Android/ARMv7"; break;
case "arm64": ArchName = "Android/ARM64"; break;
case "x86": ArchName = "Android/x86"; break;
case "x64": ArchName = "Android/x64"; break;
}
break;
case UnrealTargetPlatform.Linux:
ArchName = "Linux/" + TargetData.Architecture;
break;
case UnrealTargetPlatform.Mac:
ArchName = "Mac";
break;
case UnrealTargetPlatform.HTML5:
ArchName = "HTML5";
break;
case UnrealTargetPlatform.IOS:
ArchName = "IOS";
break;
case UnrealTargetPlatform.TVOS:
ArchName = "TVOS";
break;
default:
throw new AutomationException(String.Format("Unsupported platform '{0}' supplied to GetOutputLibDirectory", TargetData.ToString()));
}
return UnrealBuildTool.DirectoryReference.Combine(RootOutputLibDirectory, ArchName, VisualStudioName);
}
private static bool PlatformHasBinaries(TargetPlatformData TargetData)
{
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
case UnrealTargetPlatform.Win64:
case UnrealTargetPlatform.Mac:
return true;
}
return false;
}
private static bool PlatformUsesDebugDatabase(TargetPlatformData TargetData)
{
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
case UnrealTargetPlatform.Win64:
// case UnrealTargetPlatform.Mac:
case UnrealTargetPlatform.XboxOne:
return true;
}
return false;
}
private static string GetPlatformDebugDatabaseExtension(TargetPlatformData TargetData)
{
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
case UnrealTargetPlatform.Win64:
case UnrealTargetPlatform.XboxOne:
return "pdb";
case UnrealTargetPlatform.Mac:
return "dSYM";
}
throw new AutomationException(String.Format("No debug database extension for platform '{0}'", TargetData.Platform.ToString()));
}
private static string GetPlatformBinaryExtension(TargetPlatformData TargetData)
{
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
case UnrealTargetPlatform.Win64:
return "dll";
case UnrealTargetPlatform.Mac:
return "dylib";
}
throw new AutomationException(String.Format("No binary extension for platform '{0}'", TargetData.Platform.ToString()));
}
private static string GetPlatformLibExtension(TargetPlatformData TargetData)
{
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
case UnrealTargetPlatform.Win64:
case UnrealTargetPlatform.XboxOne:
return "lib";
case UnrealTargetPlatform.PS4:
case UnrealTargetPlatform.Android:
case UnrealTargetPlatform.Linux:
case UnrealTargetPlatform.Mac:
case UnrealTargetPlatform.IOS:
case UnrealTargetPlatform.TVOS:
case UnrealTargetPlatform.Switch:
return "a";
case UnrealTargetPlatform.HTML5:
return "bc";
}
throw new AutomationException(String.Format("No lib extension for platform '{0}'", TargetData.Platform.ToString()));
}
private static bool FileGeneratedByLib(string FileNameUpper, PhysXTargetLib TargetLib)
{
switch(TargetLib)
{
case PhysXTargetLib.APEX:
return FileGeneratedByAPEX(FileNameUpper);
case PhysXTargetLib.NvCloth:
return FileGeneratedByNvCloth(FileNameUpper);
default:
break;
}
// Must have been PhysX if we got here, if it wasn't generated by other libs, then it's PhysX
return !FileGeneratedByAPEX(FileNameUpper) && !FileGeneratedByNvCloth(FileNameUpper);
}
private static bool FileGeneratedByNvCloth(string FileNameUpper)
{
if(FileNameUpper.StartsWith("NVCLOTH"))
{
return true;
}
return false;
}
private static bool FileGeneratedByAPEX(string FileNameUpper)
{
if (FileNameUpper.StartsWith("APEX"))
{
return true;
}
else
{
foreach (string SpecialApexLib in APEXSpecialLibs)
{
if (FileNameUpper.StartsWith(SpecialApexLib.ToUpper())) //There are some APEX libs that don't use the APEX prefix so make sure to test against it
{
return true;
}
}
}
return false;
}
private static void FindOutputFilesHelper(HashSet<FileReference> OutputFiles, DirectoryReference BaseDir, string SearchPrefix, PhysXTargetLib TargetLib)
{
if(!DirectoryReference.Exists(BaseDir))
{
return;
}
foreach (FileReference FoundFile in DirectoryReference.EnumerateFiles(BaseDir, SearchPrefix))
{
string FileNameUpper = FoundFile.GetFileName().ToString().ToUpper();
if(FileGeneratedByLib(FileNameUpper, TargetLib))
{
OutputFiles.Add(FoundFile);
}
}
}
private static string GetConfigurationSuffix(string TargetConfiguration, TargetPlatformData TargetData)
{
// default
Dictionary<string, string> BuildSuffix = new Dictionary<string, string>()
{
{"debug", "debug"},
{"checked", "checked"},
{"profile", "profile"},
{"release", ""}
};
if (TargetData.Platform == UnrealTargetPlatform.HTML5)
{
// HTML5 - see SetupBuildForTargetLibAndPlatform() for details
BuildSuffix = new Dictionary<string, string>()
{
{"debug", ""},
{"checked", "_O2"},
{"profile", "_Oz"},
{"release", "_O3"}
};
}
return BuildSuffix[TargetConfiguration];
}
private static void FindOutputFiles(HashSet<FileReference> OutputFiles, PhysXTargetLib TargetLib, TargetPlatformData TargetData, string TargetConfiguration, WindowsCompiler TargetWindowsCompiler = WindowsCompiler.VisualStudio2015)
{
string SearchSuffix = GetConfigurationSuffix(TargetConfiguration, TargetData).ToUpper();
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
SearchSuffix += "_x86";
break;
case UnrealTargetPlatform.Win64:
SearchSuffix += "_x64";
break;
}
string SearchPrefix = "*" + SearchSuffix + ".";
string DebugExtension = PlatformUsesDebugDatabase(TargetData) ? GetPlatformDebugDatabaseExtension(TargetData) : "";
if (PlatformHasBinaries(TargetData))
{
DirectoryReference BinaryDir = GetPlatformBinaryDirectory(TargetData, TargetWindowsCompiler);
FindOutputFilesHelper(OutputFiles, BinaryDir, SearchPrefix + GetPlatformBinaryExtension(TargetData), TargetLib);
if (PlatformUsesDebugDatabase(TargetData))
{
FindOutputFilesHelper(OutputFiles, BinaryDir, SearchPrefix + DebugExtension, TargetLib);
}
}
DirectoryReference LibDir = GetPlatformLibDirectory(TargetData, TargetWindowsCompiler);
FindOutputFilesHelper(OutputFiles, LibDir, SearchPrefix + GetPlatformLibExtension(TargetData), TargetLib);
if (PlatformUsesDebugDatabase(TargetData))
{
FindOutputFilesHelper(OutputFiles, LibDir, SearchPrefix + DebugExtension, TargetLib);
}
}
private static bool PlatformSupportsTargetLib(PhysXTargetLib TargetLib, TargetPlatformData TargetData)
{
if(TargetLib == PhysXTargetLib.APEX)
{
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
case UnrealTargetPlatform.Win64:
case UnrealTargetPlatform.PS4:
case UnrealTargetPlatform.XboxOne:
case UnrealTargetPlatform.Mac:
case UnrealTargetPlatform.Switch:
return true;
case UnrealTargetPlatform.Linux:
// only x86_64 Linux supports it.
return TargetData.Architecture.StartsWith("x86_64");
default:
return false;
}
}
if(TargetLib == PhysXTargetLib.NvCloth)
{
switch(TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
case UnrealTargetPlatform.Win64:
case UnrealTargetPlatform.PS4:
case UnrealTargetPlatform.XboxOne:
case UnrealTargetPlatform.Mac:
return true;
case UnrealTargetPlatform.Linux:
// only x86_64 Linux supports it.
return TargetData.Architecture.StartsWith("x86_64");
default:
return false;
}
}
return true;
}
public override void ExecuteBuild()
{
SetupBuildEnvironment();
bool bBuildSolutions = true;
if (ParseParam("SkipBuildSolutions"))
{
bBuildSolutions = false;
}
bool bBuildLibraries = true;
if (ParseParam("SkipBuild"))
{
bBuildLibraries = false;
}
bool bAutoCreateChangelist = true;
if (ParseParam("SkipCreateChangelist"))
{
bAutoCreateChangelist = false;
}
bool bAutoSubmit = bAutoCreateChangelist;
if (ParseParam("SkipSubmit"))
{
bAutoSubmit = false;
}
// Parse out the libs we want to build
List<PhysXTargetLib> TargetLibs = GetTargetLibs();
// get the platforms we want to build for
List<TargetPlatformData> TargetPlatforms = GetTargetPlatforms();
// get the platforms we want to build for
List<WindowsCompiler> TargetWindowsCompilers = GetTargetWindowsCompilers();
// get the configurations we want to build for
List<string> TargetConfigurations = GetTargetConfigurations();
if (bBuildSolutions)
{
foreach (PhysXTargetLib TargetLib in TargetLibs)
{
// build target lib for all platforms
foreach (TargetPlatformData TargetData in TargetPlatforms)
{
if (!PlatformSupportsTargetLib(TargetLib, TargetData))
{
continue;
}
SetupBuildForTargetLibAndPlatform(TargetLib, TargetData, TargetConfigurations, TargetWindowsCompilers, false);
}
}
}
HashSet<FileReference> FilesToReconcile = new HashSet<FileReference>();
if (bBuildLibraries)
{
foreach (PhysXTargetLib TargetLib in TargetLibs)
{
// build target lib for all platforms
foreach (TargetPlatformData TargetData in TargetPlatforms)
{
if(!PlatformSupportsTargetLib(TargetLib, TargetData))
{
continue;
}
HashSet<FileReference> FilesToDelete = new HashSet<FileReference>();
foreach (string TargetConfiguration in TargetConfigurations)
{
// Delete output files before building them
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
case UnrealTargetPlatform.Win64:
foreach (WindowsCompiler TargetCompiler in TargetWindowsCompilers)
{
FindOutputFiles(FilesToDelete, TargetLib, TargetData, TargetConfiguration, TargetCompiler);
}
break;
default:
FindOutputFiles(FilesToDelete, TargetLib, TargetData, TargetConfiguration);
break;
}
}
foreach(FileReference FileToDelete in FilesToDelete)
{
FilesToReconcile.Add(FileToDelete);
InternalUtils.SafeDeleteFile(FileToDelete.ToString());
}
BuildTargetLibForPlatform(TargetLib, TargetData, TargetConfigurations, TargetWindowsCompilers);
}
}
}
int P4ChangeList = InvalidChangeList;
if (bAutoCreateChangelist)
{
string LibDeploymentDesc = "";
foreach(PhysXTargetLib Lib in TargetLibs)
{
if(LibDeploymentDesc.Length != 0)
{
LibDeploymentDesc += " & ";
}
LibDeploymentDesc += Lib.ToString();
}
foreach (TargetPlatformData TargetData in TargetPlatforms)
{
LibDeploymentDesc += " " + TargetData.ToString();
}
P4ChangeList = P4.CreateChange(P4Env.Client, String.Format("BuildPhysX.Automation: Deploying {0} libs.", LibDeploymentDesc) + Environment.NewLine + "#rb none" + Environment.NewLine + "#lockdown Nick.Penwarden" + Environment.NewLine + "#tests none");
}
if (P4ChangeList != InvalidChangeList)
{
foreach (PhysXTargetLib TargetLib in TargetLibs)
{
foreach (string TargetConfiguration in TargetConfigurations)
{
//Add any new files that p4 is not yet tracking.
foreach (TargetPlatformData TargetData in TargetPlatforms)
{
if (!PlatformSupportsTargetLib(TargetLib, TargetData))
{
continue;
}
switch (TargetData.Platform)
{
case UnrealTargetPlatform.Win32:
case UnrealTargetPlatform.Win64:
foreach (WindowsCompiler TargetCompiler in TargetWindowsCompilers)
{
FindOutputFiles(FilesToReconcile, TargetLib, TargetData, TargetConfiguration, TargetCompiler);
}
break;
default:
FindOutputFiles(FilesToReconcile, TargetLib, TargetData, TargetConfiguration);
break;
}
}
}
}
foreach(FileReference FileToReconcile in FilesToReconcile)
{
P4.Reconcile(P4ChangeList, FileToReconcile.ToString());
}
}
if(bAutoSubmit && (P4ChangeList != InvalidChangeList))
{
if (!P4.TryDeleteEmptyChange(P4ChangeList))
{
Log("Submitting changelist " + P4ChangeList.ToString());
int SubmittedChangeList = InvalidChangeList;
P4.Submit(P4ChangeList, out SubmittedChangeList);
}
else
{
Log("Nothing to submit!");
}
}
}
}