How to add custom command line flags to UBT

First, try seeing if your flag is working correctly by invoking UBT directly (e.g. through Engine/Build/BatchFiles/Build.bat or even Engine/Binaries/DotNET/UnrealBuildTool.exe). After that, examine and amend the specific UAT command (I’m guessing it’s BuildCookRun) to make sure the flag (that you’re passing to UAT, not UBT, since RunUAT.bat runs that first) is passed through to UBT from there.

How do you add custom flags when using UBT via RunUAT.bat?
I’m doing this specifically for Linux builds and trying to follow the pattern used by EnableAddressSanitizer.

UEBuildLinux.cs

/// <summary>
/// Enables my custom flag
// </summary>
[CommandLine("-MyCustomFlag")]
[XmlConfigFile(Category = "BuildConfiguration", Name = "bMyCustomFlag")]
public bool bMyCustomFlag = false;

LinuxToolchain.cs

enum LinuxToolChainOptions
{
...
	/// <summary>
	/// Enable some compiler flag
	/// </summary>
	MyCustomFlag = 0x8,
}

protected virtual string GetCLArguments_Global(CppCompileEnvironment CompileEnvironment)

// MyCustomFlag
if (Options.HasFlag(LinuxToolChainOptions.MyCustomFlag))
{
	Result += " -f-some-linux-compiler-flag";
}

When I call RunUAT.bat with -MyCustomFlag=true or -MyCustomFlag that flag is never set, it’s always false.

What am I doing wrong?

Running the Build.bat file directly helped track down the problem.
When using RunUAT.bat if you add

  -ubtargs=-MyCustomFlag

The argument gets passed to UBT and everything works correctly.

Thanks so much for the help!

Hi

Can explain more where to put this flag ?