MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
McroBuild.Build.cs
Go to the documentation of this file.
1/** @noop License Comment
2 * @file
3 * @copyright
4 * This Source Code is subject to the terms of the Mozilla Public License, v2.0.
5 * If a copy of the MPL was not distributed with this file You can obtain one at
6 * https://mozilla.org/MPL/2.0/
7 *
8 * @author David Mórász
9 * @date 2025
10 */
11
12/**
13 * @file
14 * The UBT target and module rule scripts are handled as one big C# project with all the freedom that implies allowed.
15 * Any `*.Build.cs` file will be picked up but they not necessarily need to declare a module or a target, or multiple
16 * C# sources can declare one target (via partial classes of course)
17 * @file
18 * Realizing this MCRO provides some very handy utilities to make writing these rules much more convenient, especially
19 * for handling the intricacies of linking elaborate third-party libraries in Unreal.
20 */
21
22using System.Linq;
23using UnrealBuildTool;
24
25namespace McroBuild;
26
27/// <summary>
28/// Convenience utilities for module rules
29/// </summary>
30public static partial class ModuleRuleExtensions
31{
32 /// <returns>Path to the module folder</returns>
33 public static AbsolutePath ModulePath(this ModuleRules self) => self.ModuleDirectory.AsPath();
34
35 /// <returns>Path to the plugin folder to which this module belongs</returns>
36 public static AbsolutePath PluginPath(this ModuleRules self) => self.PluginDirectory.AsPath();
37
38 /// <returns>Path to the project folder to which this module belongs</returns>
39 public static AbsolutePath ProjectPath(this ModuleRules self) => self.Target.ProjectFile!.Directory.AsPath();
40
41 /// <returns>A consistent place for plugin binaries</returns>
42 public static AbsolutePath PluginBinaries(this ModuleRules self) => self.PluginPath() / "Binaries";
43
44 /// <param name="self"></param>
45 /// <param name="insert">A path segment between main plugin binaries folder and the platform specifier</param>
46 /// <returns>A consistent place for plugin binaries regarding current platform</returns>
47 public static AbsolutePath PluginBinariesPlatform(this ModuleRules self, string insert = "")
48 => self.PluginBinaries() / insert / self.Target.Platform.ToString();
49
50 /// <param name="self"></param>
51 /// <param name="insert">A path segment between main plugin binaries folder and the current module name</param>
52 /// <returns>A consistent place for module binaries in owning plugin.</returns>
53 public static AbsolutePath PluginModuleBinaries(this ModuleRules self, string insert = "")
54 => self.PluginBinaries() / insert / self.GetBaseModuleName();
55
56 /// <param name="self"></param>
57 /// <param name="insert">A path segment between main plugin binaries folder and the current module name</param>
58 /// <returns>A consistent place for module binaries in owning plugin and regarding current platform.</returns>
59 public static AbsolutePath PluginModuleBinariesPlatform(this ModuleRules self, string insert = "")
60 => self.PluginBinaries() / insert / self.GetBaseModuleName() / self.Target.Platform.ToString();
61
62 /// <summary>
63 /// Is the current build fully linked as debug build? This is usually only the case when building engine as Debug
64 /// from source (optionally via a project)
65 /// </summary>
66 public static bool IsReallyDebug(this ModuleRules self) =>
67 self.Target is { Configuration: UnrealTargetConfiguration.Debug, bDebugBuildsActuallyUseDebugCRT: true };
68
69 /// <summary>
70 /// Get the actual preferred linkage for a third-party library
71 /// </summary>
72 public static string GetLibraryConfig(this ModuleRules self, bool allowDebugLibraries = true)
73 => allowDebugLibraries && self.IsReallyDebug() ? "Debug" : "Release";
74
75 /// <summary>
76 /// Infer module name from its class name
77 /// </summary>
78 public static string GetBaseModuleName(this ModuleRules self)
79 {
80 if (!self.GetType().Name.Contains("_")) return self.GetType().Name;
81 var moduleNameComponents = self.GetType().Name
82 .Split('_')
83 .SkipLast(1);
84 return string.Join('_', moduleNameComponents);
85 }
86}
A simplified copy of NUKE's own AbsolutePath class https://github.com/nuke-build/nuke/blob/develop/so...
static AbsolutePath PluginModuleBinaries(this ModuleRules self, string insert="")
static AbsolutePath PluginModuleBinariesPlatform(this ModuleRules self, string insert="")
static AbsolutePath PluginPath(this ModuleRules self)
Path to the plugin folder to which this module belongs
static bool IsReallyDebug(this ModuleRules self)
Is the current build fully linked as debug build? This is usually only the case when building engine ...
static AbsolutePath ModulePath(this ModuleRules self)
Path to the module folder
static AbsolutePath PluginBinariesPlatform(this ModuleRules self, string insert="")
static AbsolutePath PluginBinaries(this ModuleRules self)
A consistent place for plugin binaries
static string GetBaseModuleName(this ModuleRules self)
Infer module name from its class name.
static AbsolutePath ProjectPath(this ModuleRules self)
Path to the project folder to which this module belongs
static string GetLibraryConfig(this ModuleRules self, bool allowDebugLibraries=true)
Get the actual preferred linkage for a third-party library.