Nuke.Unreal
Build Unreal apps in Style.
Loading...
Searching...
No Matches
UnrealBuild.Templating.cs
1using System;
2using Nuke.Common;
3using Nuke.Common.IO;
4using Nuke.Common.Utilities.Collections;
6using Serilog;
7
8// Maximum line length of long parameter description:
9// ------------------------------------------------------------
10
11namespace Nuke.Unreal
12{
13 public abstract partial class UnrealBuild : NukeBuild
14 {
15
16 [Parameter(
17 """
18
19 Specify a folder containing generator specific folders for
20 Scriban scaffolding and templates. If left empty the
21 templates coming with Nuke.Unreal will be used.
22
23 """
24 )]
25 public virtual AbsolutePath TemplatesPath { get; set; } = BoilerplateGenerator.DefaultTemplateFolder;
26
27 [Parameter("Name parameter for boilerplate generators.")]
28 public string[] Name { get; set; } = [];
29
30 [Parameter(
31 """
32
33 Specification(s) of the imported library(ies). This is used
34 slightly differently based on which library type is being
35 used:
36
37 Header / CMake: It's only the name of the library
38 (like --spec spdlog)
39
40 XRepo: specify the xrepo package reference and its config
41 separated by space. For example:
42 --spec "zlib"
43 --spec "zlib 1.2.x"
44 --spec "boost regex=true,thread=true"
45 --spec "imgui 1.91.1 freetype=true"
46
47 Use VCPKG via XRepo, note that specifying an explicit
48 version is not supported in VCPKG (bug in xrepo?)
49 --spec "vcpkg::spdlog"
50
51 VCPKG features are supported
52 --spec "vcpkg::spdlog[wchar]"
53
54 Use Conan via XRepo (note version is required and
55 delimited with /)
56 --spec "conan::zlib/1.2.11"
57
58 And of course multiple libraries can be used in one go
59 --spec
60 "imgui 1.91.1 freetype=true"
61 "conan::zlib/1.2.11"
62 "vcpkg::spdlog[wchar]"
63 <etc...>
64
65 More about xrepo: https://xrepo.xmake.io
66 NOTE: since Unreal uses MD runtime linkage
67 `runtimes='MD'` config is always appended by
68 Nuke.Unreal, and the user must not specify it.
69
70 """
71 )]
72 public virtual string[] Spec { get; set; } = [];
73
74 [Parameter(
75 """
76
77 Some boilerplate generators allows to define an extra
78 suffix for names depending on their use case. For example
79 `NewLibrary` can use the plain `Name` for library folder
80 structure and `Name_MySuffix` for module names
81 (when `Suffix` is set to `MySuffix`)
82
83 """
84 )]
85 public string? Suffix { get; set; }
86
87 [Parameter(
88 """
89
90 Specify the type of the third-party library being imported:
91 `Header`: header only C++ library which doesn't need
92 extra preparation
93 `CMake`: generates an extra nuke target which prepares
94 the CMake library to be used and distributed
95 in Unreal.
96 `XRepo`: generates an extra nuke target which then
97 installs the library on preparation via the
98 xrepo package manager. The library for a
99 specific platform will be available when
100 running Prepare<library>, Prepare or
101 Generate targets.
102
103 """
104 )]
105 public LibraryType? LibraryType { get; set; }
106
107 [Parameter("Explicitly add new module to project target")]
108 public bool AddToTarget { get; set; }
109
110 public Target NewModule => _ => _
111 .Description(
112 """
113
114 Create new module in the owning project or plugin
115 (depending on working directory)
116
117 """
118 )
119 .Before(Generate)
120 .Requires(() => Name)
121 .Executes(() =>
122 Name.ForEach(n =>
123 new ModuleGenerator()
124 .SetAddToTarget(AddToTarget)
125 .Generate(
126 TemplatesPath,
127 (AbsolutePath) Environment.CurrentDirectory,
128 n
129 )
130 )
131 );
132 public Target AddCode => _ => _
133 .Description("Add C++ code to a project which doesn't have one yet.")
134 .Before(Generate)
135 .Executes(() =>
136 new TargetGenerator().Generate(
137 TemplatesPath,
140 )
141 );
142
143 public Target NewPlugin => _ => _
144 .Description("Create a new project plugin.")
145 .Before(Generate)
146 .Requires(() => Name)
147 .Executes(() =>
148 Name.ForEach(n =>
149 new PluginGenerator().Generate(
150 TemplatesPath,
151 (AbsolutePath) Environment.CurrentDirectory,
152 n, Unreal.Version(this)
153 )
154 )
155 );
156
157 public Target NewActor => _ => _
158 .Description("Create new Unreal Actor in current directory")
159 .Before(Generate)
160 .Requires(() => Name)
161 .Executes(() =>
162 Name.ForEach(n =>
163 new ActorGenerator().Generate(
164 TemplatesPath,
165 (AbsolutePath) Environment.CurrentDirectory,
166 new(n)
167 )
168 )
169 );
170
171 public Target NewInterface => _ => _
172 .Description("Create new Unreal Interface in current directory")
173 .Before(Generate)
174 .Requires(() => Name)
175 .Executes(() =>
176 Name.ForEach(n =>
177 new InterfaceGenerator().Generate(
178 TemplatesPath,
179 (AbsolutePath) Environment.CurrentDirectory,
180 new(n)
181 )
182 )
183 );
184
185 public Target NewObject => _ => _
186 .Description("Create new Unreal Object in current directory")
187 .Before(Generate)
188 .Requires(() => Name)
189 .Executes(() =>
190 Name.ForEach(n =>
191 new ObjectGenerator().Generate(
192 TemplatesPath,
193 (AbsolutePath) Environment.CurrentDirectory,
194 new(n)
195 )
196 )
197 );
198
199 public Target NewStruct => _ => _
200 .Description("Create new Unreal Struct in current directory")
201 .Before(Generate)
202 .Requires(() => Name)
203 .Executes(() =>
204 Name.ForEach(n =>
205 new StructGenerator().Generate(
206 TemplatesPath,
207 (AbsolutePath) Environment.CurrentDirectory,
208 new(n)
209 )
210 )
211 );
212
213 public Target NewSpec => _ => _
214 .Description("Create new Unreal Automation Spec in current directory")
215 .Before(Generate)
216 .Requires(() => Name)
217 .Executes(() =>
218 Name.ForEach(n =>
219 new SpecGenerator().Generate(
220 TemplatesPath,
221 (AbsolutePath) Environment.CurrentDirectory,
222 new(n)
223 )
224 )
225 );
226
227 public Target UseLibrary => _ => _
228 .Description(
229 """
230
231 Create boilerplate module for third-party C++ libraries. Specify the kind of
232 library with `--library-type Header|CMake|XRepo` The latter two will generate
233 extra nuke targets preparing the library to be consumed by Unreal.
234 Fetching/storing the library is up to the developer
235 (except of course with XRepo).
236
237 Use type specific targets for more comfortable CLI experience, for example
238 nuke use-xrepo --spec tracy
239 instead of
240 nuke use-library --library-type xrepo --spec tracy
241
242 This only needs to be done once, you can check the results into source control.
243
244 """
245 )
246 .DependsOn(EnsureBuildPluginSupport)
247 .Before(Prepare, Generate)
248 .Executes(() =>
249 {
250 Assert.NotEmpty(Spec);
251 Assert.NotNull(LibraryType);
252
253 Spec.ForEach(n =>
254 {
255 Log.Information("Preparing library {0}", n);
256 new LibraryGenerator().Generate(
257 this,
258 TemplatesPath,
259 EnvironmentInfo.WorkingDirectory,
260 n, LibraryType!, Suffix
261 );
262 }
263 );
264 if (LibraryType == LibraryType.XRepo)
265 Log.Information("Run `Prepare` or `Generate` to install new libraries.");
266 Log.Information("This only needs to be done once, you can check the results into source control.");
267 });
268
269 public Target UseXRepo => _ => _
270 .Description(
271 """
272
273 Use libraries from the xrepo package manager. This target only configures
274 another target which will eventually fetch the input libraries. To make them
275 available to Unreal run `Prepare` or `Generate` targets.
276
277 Specify the xrepo package reference and its config separated by space.
278 For example:
279
280 nuke use-xrepo --spec "zlib"
281 nuke use-xrepo --spec "zlib 1.2.x"
282 nuke use-xrepo --spec "boost regex=true,thread=true"
283 nuke use-xrepo --spec "imgui 1.91.1 freetype=true"
284
285 Use VCPKG via XRepo, note that specifying an explicit version is
286 not supported in VCPKG (bug in xrepo?)
287 nuke use-xrepo --spec "vcpkg::spdlog"
288
289 VCPKG features are supported
290 nuke use-xrepo --spec "vcpkg::spdlog[wchar]"
291
292 Use Conan via XRepo (note version is required and delimited with /)
293 nuke use-xrepo --spec "conan::zlib/1.2.11"
294
295 And of course multiple libraries can be used in one go
296 nuke use-xrepo --spec
297 "imgui 1.91.1 freetype=true"
298 "conan::zlib/1.2.11"
299 "vcpkg::spdlog[wchar]"
300 <etc...>
301
302 More about xrepo: https://xrepo.xmake.io
303 NOTE: since Unreal uses MD runtime linkage `runtimes='MD'` config is always
304 appended by Nuke.Unreal, and the user must not specify it.
305
306 This only needs to be done once, you can check the results into source control.
307
308 """
309 )
310 .Triggers(UseLibrary)
311 .Requires(() => Spec)
312 .Executes(() => LibraryType = LibraryType.XRepo);
313
314 public Target UseCMake => _ => _
315 .Triggers(UseLibrary)
316 .Requires(() => Spec)
317 .Executes(() => LibraryType = LibraryType.CMake);
318
319 public Target UseHeaderOnly => _ => _
320 .Triggers(UseLibrary)
321 .Requires(() => Spec)
322 .Executes(() => LibraryType = LibraryType.Header);
323 }
324}
The main build class Unreal projects using Nuke.Unreal should inherit from. This class contains all b...
AbsolutePath ProjectFolder
Path to folder containing the .project file.
string ProjectName
Short name of the project.
A collection of utilities around basic functions regarding the environment of the Engine we're workin...
Definition Unreal.cs:24
static EngineVersion Version(UnrealBuild build)
Get high-level version of currently used Engine.