Skip to content

Commit d885e0c

Browse files
committed
since Unreal never actually links with MDd on its own, we can configure libraries to use MD in debug builds as well. override is possible when necessary
1 parent 6745c28 commit d885e0c

File tree

7 files changed

+29
-28
lines changed

7 files changed

+29
-28
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,7 @@ public partial class TpModule : ModuleRules
623623
var VisionOS = target.Platform == UnrealTargetPlatform.VisionOS;
624624
var Independent = true;
625625

626-
var Debug = target is
627-
{
628-
Configuration: UnrealTargetConfiguration.Debug,
629-
bDebugBuildsActuallyUseDebugCRT: true
630-
};
626+
var Debug = Target.Configuration <= UnrealTargetConfiguration.DebugGame;
631627
var Release = !Debug;
632628
var All = true;
633629

docs/Manual/RuntimeDeps.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,7 @@ public partial class TpModule : ModuleRules
164164
var VisionOS = target.Platform == UnrealTargetPlatform.VisionOS;
165165
var Independent = true;
166166

167-
var Debug = target is
168-
{
169-
Configuration: UnrealTargetConfiguration.Debug,
170-
bDebugBuildsActuallyUseDebugCRT: true
171-
};
167+
var Debug = Target.Configuration <= UnrealTargetConfiguration.DebugGame;
172168
var Release = !Debug;
173169
var All = true;
174170

src/Nuke.Unreal/BoilerplateGenerators/LibraryGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class LibraryType : Enumeration
4141
public Func<string, LibrarySpec> ParseSpec { get; private set; } = s => new LibrarySpec(s, s);
4242
}
4343

44-
public record LibrarySpec(
44+
public record class LibrarySpec(
4545
string Spec,
4646
string Name,
4747
string? Version = null,
@@ -55,12 +55,12 @@ public record LibrarySpec(
5555
.Pascalize();
5656
}
5757

58-
public record SuffixRecord(string? Text, string? Us, string? Dot)
58+
public record class SuffixRecord(string? Text, string? Us, string? Dot)
5959
{
6060
public SuffixRecord(string? suffix) : this(suffix, suffix.PrependNonEmpty("_"), suffix.PrependNonEmpty(".")) {}
6161
}
6262

63-
public record LibraryModel(
63+
public record class LibraryModel(
6464
LibrarySpec Spec,
6565
string? Copyright,
6666
SuffixRecord Suffix,

src/Nuke.Unreal/BoilerplateGenerators/XRepo/XRepoLibrary.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
namespace Nuke.Unreal.BoilerplateGenerators.XRepo;
1414

15+
/// <summary>
16+
/// Utility classes for working with XRepo (or XMake) packages
17+
/// </summary>
1518
public static partial class XRepoLibrary
1619
{
1720
[GeneratedRegex(
@@ -34,6 +37,9 @@ public static partial class XRepoLibrary
3437
)]
3538
private static partial Regex SpecRegex();
3639

40+
/// <summary>
41+
/// Parses an input library spec string as a record
42+
/// </summary>
3743
public static LibrarySpec ParseSpec(string spec)
3844
{
3945
var matches = spec.Parse(SpecRegex(), forceNullOnWhitespce: true);
@@ -47,13 +53,10 @@ public static LibrarySpec ParseSpec(string spec)
4753
);
4854
}
4955

50-
internal static IEnumerable<XRepoLibraryRecord> InstallXRepoLibrary(UnrealBuild self, LibrarySpec spec, string options, AbsolutePath targetPath, bool debug)
56+
internal static IEnumerable<XRepoLibraryRecord> InstallXRepoLibrary(UnrealBuild self, LibrarySpec spec, string options, AbsolutePath targetPath, bool debug, string runtime = "MD")
5157
{
5258
var libraryFiles = targetPath / "LibraryFiles";
53-
options = options.AppendNonEmpty(",") + (debug
54-
? "runtimes='MDd'"
55-
: "runtimes='MD'"
56-
);
59+
options = options.AppendNonEmpty(",") + $"runtimes='{runtime}'";
5760
var xrepoPlatArch = self.Platform.GetXRepoPlatformArch();
5861

5962
var extraArgs =
@@ -136,7 +139,17 @@ string[] ProcessPaths(string? paths, AbsolutePath dstDir)
136139
.ToArray();
137140
}
138141

139-
public static void InstallXRepoLibrary(this UnrealBuild self, string specIn, string options, AbsolutePath targetPath, string? suffix = null)
142+
/// <summary>
143+
/// Prepare a third-party library from an XRepo library spec for Unreal engine's consumption
144+
/// </summary>
145+
/// <param name="self">The build context</param>
146+
/// <param name="specIn">The library spec specified here (without the options) https://mcro.de/Nuke.Unreal/d2/d84/CppLibraries.html</param>
147+
/// <param name="options">Comma separated '=' delimited key-value pairs. Space is not allowed around commas</param>
148+
/// <param name="targetPath">Where library files should be organized</param>
149+
/// <param name="suffix">Optional addition to the name of library name exposed to Unreal</param>
150+
/// <param name="releaseRuntime">Windows CRT linkage for release versions (default is MD)</param>
151+
/// <param name="debugRuntime">Windows CRT linkage for debug versions (default is MD)</param>
152+
public static void InstallXRepoLibrary(this UnrealBuild self, string specIn, string options, AbsolutePath targetPath, string? suffix = null, string releaseRuntime = "MD", string debugRuntime = "MD")
140153
{
141154
Log.Information("Installing library {0} via xrepo", specIn);
142155
var spec = ParseSpec(specIn) with { Options = options };
@@ -147,10 +160,10 @@ public static void InstallXRepoLibrary(this UnrealBuild self, string specIn, str
147160
Log.Information(" Features: {0}", spec.Features);
148161

149162
Log.Information("Installing debug build");
150-
var debugLibs = InstallXRepoLibrary(self, spec, options, targetPath, true);
163+
var debugLibs = InstallXRepoLibrary(self, spec, options, targetPath, true, debugRuntime);
151164

152165
Log.Information("Installing release build (metadata will be used from release build)");
153-
var releaseLibs = InstallXRepoLibrary(self, spec, options, targetPath, false);
166+
var releaseLibs = InstallXRepoLibrary(self, spec, options, targetPath, false, releaseRuntime);
154167

155168
Log.Information("Generating partial module rule class for {0}", self.Platform);
156169
new XRepoLibraryModuleGenerator().Generate(

src/Nuke.Unreal/templates/AutoRuntimeDependency/{{ module_name }}.Rtd.Build.sbncs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ public partial class {{ module_name }} : ModuleRules
2929
var VisionOS = target.Platform == UnrealTargetPlatform.VisionOS;
3030
var Independent = true;
3131

32-
var Debug = target is
33-
{
34-
Configuration: UnrealTargetConfiguration.Debug,
35-
bDebugBuildsActuallyUseDebugCRT: true
36-
};
32+
var Debug = Target.Configuration <= UnrealTargetConfiguration.DebugGame;
3733
var Release = !Debug;
3834
var All = true;
3935

src/Nuke.Unreal/templates/CMakeLibrary/{{ spec.unreal_name }}{{ suffix.us }}/{{ spec.unreal_name }}{{ suffix.us }}.Build.sbncs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class {{ cap_name }}{{ suffix.us }} : ModuleRules
1010
Type = ModuleType.External;
1111
PublicIncludePaths.Add($"{ModuleDirectory}/Include");
1212

13-
var isDebug = target.Configuration == UnrealTargetConfiguration.Debug && target.bDebugBuildsActuallyUseDebugCRT;
13+
var isDebug = Target.Configuration <= UnrealTargetConfiguration.DebugGame;
1414
var config = isDebug ? "Debug" : "Release";
1515

1616
PublicAdditionalLibraries.AddRange(new []

src/Nuke.Unreal/templates/XRepoLibrary/{{ spec.unreal_name }}{{ suffix.us }}/{{ spec.unreal_name }}{{ suffix.us }}.Build.sbncs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public partial class {{ cap_name }}{{ suffix.us }} : ModuleRules
2020
// auto generated when the library is prepared on/for a specific platform.
2121

2222
Type = ModuleType.External;
23-
IsDebug = target.Configuration == UnrealTargetConfiguration.Debug && target.bDebugBuildsActuallyUseDebugCRT;
23+
IsDebug = Target.Configuration <= UnrealTargetConfiguration.DebugGame;
2424
LibraryConfig = IsDebug ? "Debug" : "Release";
2525
LibraryPlatform = target.Platform.ToString();
2626

0 commit comments

Comments
 (0)