-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.sharpmake.cs
More file actions
497 lines (402 loc) · 17.6 KB
/
Copy pathmain.sharpmake.cs
File metadata and controls
497 lines (402 loc) · 17.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
using Sharpmake;
using System;
using System.Collections.Generic;
namespace Spectrum
{
[Fragment, Flags]
public enum Mode
{
Debug = 1,
Profile = 2,
Retail = 4
}
[Fragment, Flags]
public enum Backend
{
D3D12 = 1,
Vulkan = 2
}
public class CustomTarget : ITarget
{
public Platform Platform;
public DevEnv DevEnv;
public Optimization Optimization;
public Mode Mode;
public Backend Backend;
}
public static class Vcpkg
{
public const string Triplet = "x64-windows";
public const string InstalledRoot = @"[project.SharpmakeCsPath]\vcpkg_installed\" + Triplet;
public const string Bin = InstalledRoot + @"\" + Triplet + @"\bin";
public const string DebugBin = InstalledRoot + @"\" + Triplet + @"\debug\bin";
public const string Include = InstalledRoot + @"\" + Triplet + @"\include";
}
[Sharpmake.Generate]
public class Common : Project
{
public Common() : base(typeof(CustomTarget))
{
SourceFilesExtensions.Add(".sig");
SourceFilesExtensions.Add(".hlsl");
SourceFilesExtensions.Add(".ixx");
SourceFilesExtensions.Add(".g4");
SourceFilesExtensions.Add(".jinja");
SourceFilesCompileExtensions.Add(".ixx");
RootPath = @"[project.SharpmakeCsPath]\projects\[project.Name]";
AddTargets(new CustomTarget
{
Platform = Platform.win64,
DevEnv = DevEnv.vs2026,
Optimization = Optimization.Release,
Mode = Mode.Debug | Mode.Profile | Mode.Retail,
Backend = Backend.D3D12 | Backend.Vulkan
});
CustomProperties.Add("VcpkgEnabled", "true");
CustomProperties.Add("VcpkgEnableManifest", "true");
CustomProperties.Add("VcpkgTriplet", Vcpkg.Triplet);
CustomProperties.Add("VcpkgConfiguration", "Release");
CustomProperties.Add("VcpkgApplocalDeps", "true");
CustomProperties.Add("ScanSourceForModuleDependencies", "true");
// BlobWorkFileCount = 8;
// GeneratableBlobCount = 8;
}
[Configure]
public virtual void ConfigureAll(Configuration conf, CustomTarget target)
{
conf.Output = Configuration.OutputType.Utility;
conf.ProjectFileName = "[project.Name]";
conf.ProjectPath = @"[project.RootPath]";
conf.IncludePaths.Add(SourceRootPath);
// Repository sources root — allows cross-project Defines.h chains
// (e.g. HAL/Defines.h can #include "Core/Defines.h").
conf.IncludePaths.Add(@"[project.SharpmakeCsPath]\sources");
// Each subproject has a Defines.h at its root that chains upward
// through the dependency graph. We use the full SourceRootPath so
// the forced include is always resolved correctly regardless of
// include-path ordering — especially for files in subdirectories
// (e.g. HAL/D3D12/*.cpp which couldn't find a plain "Defines.h").
conf.ForcedIncludes.Add(@"[project.SourceRootPath]\Defines.h");
//conf.ExportAdditionalLibrariesEvenForStaticLib = true;
conf.PrecompSourceExcludeExtension.Add(".ixx");
conf.Options.Add(Options.Vc.Compiler.CppLanguageStandard.Latest);
conf.Options.Add(Options.Vc.Compiler.Exceptions.Enable);
conf.Options.Add(Options.Vc.Compiler.RTTI.Enable);
conf.Options.Add(Options.Vc.Linker.SubSystem.Windows);
conf.Options.Add(Options.Vc.General.WindowsTargetPlatformVersion.Latest);
conf.Options.Add(Options.Vc.Compiler.FunctionLevelLinking.Disable);
conf.Options.Add(Options.Vc.Compiler.RuntimeLibrary.MultiThreadedDLL);
conf.Options.Add(Options.Vc.Compiler.Inline.OnlyInline);
conf.Options.Add(Options.Vc.General.WarningLevel.Level3); // hate warnings, love errors
conf.AdditionalCompilerOptions.Add("/bigobj");
// conf.AdditionalCompilerOptions.Add("/dxifcInlineFunctions-");
conf.Defines.Add("_MBCS");
conf.Defines.Add("BOOST_NO_USER_CONFIG");
conf.Defines.Add("BOOST_ENDIAN_DEPRECATED_NAMES");
conf.Defines.Add("BOOST_ALL_NO_LIB");
conf.Defines.Add("BOOST_NO_CXX11_NOEXCEPT");
conf.Defines.Add("_SCL_SECURE_NO_WARNINGS");
conf.Defines.Add("_CRT_SECURE_NO_WARNINGS");
conf.Defines.Add("NOMINMAX");
conf.Defines.Add("_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING");
conf.Defines.Add("_SILENCE_CXX23_ALIGNED_STORAGE_DEPRECATION_WARNING");
conf.Defines.Add("SPECTRUM_ENABLE_EXCEPTIONS"); // fixed: was "EXEPTIONS"
// CEREAL_THREAD_SAFE removed: it makes cereal include <mutex> which in MSVC 14.51+
// transitively pulls <stop_token> into _cereal.h's header unit IFC.
// That causes C1116 when any TU imports both cereal and a threading header unit.
// cereal's internal polymorphic registry (what this flag protects) is populated
// during single-threaded static init, so removing it is safe.
conf.Defines.Add("USE_PIX");
conf.Defines.Add("WIN32_LEAN_AND_MEAN");
conf.Options.Add(new Sharpmake.Options.Vc.Compiler.DisableSpecificWarnings("4005", "5104", "5105", "5106", "4494")); //module reference issues
if (target.Mode == Mode.Debug)
{
conf.Options.Add(Options.Vc.Compiler.Optimization.Disable);
conf.Options.Add(Options.Vc.Compiler.Inline.Disable);
conf.Defines.Add("DEV");
conf.Defines.Add("PROFILING");
}
else
{
conf.Options.Add(Options.Vc.Compiler.Optimization.FullOptimization);
conf.Defines.Add("RETAIL");
conf.Defines.Remove("NDEBUG");
}
if (target.Mode == Mode.Profile)
{
conf.Defines.Add("PROFILING");
}
}
}
[Sharpmake.Generate]
public class Library : Common
{
public Library()
{
}
public override void ConfigureAll(Configuration conf, CustomTarget target)
{
base.ConfigureAll(conf, target);
conf.Output = Configuration.OutputType.Lib;
}
}
[Sharpmake.Generate]
public class Application : Common
{
public Application()
{
RootPath = @"[project.SharpmakeCsPath]\projects\[project.Name]";
}
public override void ConfigureAll(Configuration conf, CustomTarget target)
{
base.ConfigureAll(conf, target);
conf.Output = Configuration.OutputType.Exe;
conf.TargetPath = @"[project.SharpmakeCsPath]\bin\" + target.Mode.ToString();
}
}
/*
[Sharpmake.Generate]
public class Aftermath : Library
{
public Aftermath()
{
SourceRootPath = @"[project.SharpmakeCsPath]\sources\3rdparty\Aftermath";
AssemblyName = "Aftermath";
}
public override void ConfigureAll(Configuration conf, CustomTarget target)
{
base.ConfigureAll(conf, target);
// Aftermath is third-party NVIDIA code with no custom Defines.h.
// Replace the base forced include with the bottom of the chain.
conf.ForcedIncludes.Remove(@"[project.SourceRootPath]\Defines.h");
conf.ForcedIncludes.Add(@"[project.SharpmakeCsPath]\sources\Modules\Defines.h");
conf.LibraryFiles.Add(@"[project.SourceRootPath]\lib\x64\GFSDK_Aftermath_Lib.x64.lib");
conf.TargetCopyFiles.Add(@"[project.SourceRootPath]\lib\x64\GFSDK_Aftermath_Lib.x64.dll");
conf.IncludePaths.Add(@"[project.SourceRootPath]/include");
}
}
*/
[Sharpmake.Generate]
public class Modules : Library
{
public Modules()
{
SourceRootPath = @"[project.SharpmakeCsPath]\sources\Modules";
AssemblyName = "Modules";
}
public override void ConfigureAll(Configuration conf, CustomTarget target)
{
base.ConfigureAll(conf, target);
conf.IncludePaths.Add(@"[project.SourceRootPath]/include");
conf.ExportAdditionalLibrariesEvenForStaticLib = false;
{ // PIX
// conf.IncludePaths.Add(@"[project.SharpmakeCsPath]\PIX\Include\WinPixEventRuntime", 66);
// conf.TargetCopyFiles.Add(@"[project.SharpmakeCsPath]\PIX\bin\x64\WinPixEventRuntime.dll");
// conf.LibraryFiles.Add("WinPixEventRuntime.lib");
// conf.LibraryPaths.Add(@"[project.SharpmakeCsPath]\PIX\bin\x64", 66);
}
// runtime-loaded DLLs not detected by VcpkgApplocalDeps
conf.TargetCopyFiles.Add(Vcpkg.Bin + @"\dstoragecore.dll");
conf.TargetCopyFiles.Add(Vcpkg.Bin + @"\dxcompiler.dll");
conf.TargetCopyFiles.Add(Vcpkg.Bin + @"\dxil.dll");
conf.TargetCopyFilesToSubDirectory.Add(new KeyValuePair<string, string>(Vcpkg.DebugBin + @"\D3D12Core.dll", "D3D12"));
conf.TargetCopyFilesToSubDirectory.Add(new KeyValuePair<string, string>(Vcpkg.DebugBin + @"\d3d12SDKLayers.dll", "D3D12"));
// Per-backend module wrappers: compile only the active backend's wrapper.
if (target.Backend == Backend.D3D12)
conf.SourceFilesBuildExcludeRegex.Add(@".*\\Modules\\vulkan\\.*");
else // Vulkan
conf.SourceFilesBuildExcludeRegex.Add(@".*\\Modules\\d3d12\\.*");
conf.Options.Add(new Sharpmake.Options.Vc.Compiler.DisableSpecificWarnings("5260")); // adding inline to header units
}
}
[Sharpmake.Generate]
public class Core : Library
{
public Core()
{
SourceRootPath = @"[project.SharpmakeCsPath]\sources\Core";
AssemblyName = "Core";
}
public override void ConfigureAll(Configuration conf, CustomTarget target)
{
base.ConfigureAll(conf, target);
conf.AddPublicDependency<Modules>(target);
conf.Defines.Add("LEAK_TEST_ENABLE");
}
}
[Sharpmake.Generate]
public class HAL : Library
{
public HAL()
{
SourceRootPath = @"[project.SharpmakeCsPath]\sources\HAL";
AssemblyName = "HAL";
}
public override void ConfigureAll(Configuration conf, CustomTarget target)
{
base.ConfigureAll(conf, target);
if (target.Backend == Backend.D3D12)
{
// D3D12 backend: include D3D12/ and DXGI/ folders, exclude Vulkan/
conf.LibraryFiles.Add("dxgi.lib");
conf.LibraryFiles.Add("d3d12.lib");
conf.LibraryFiles.Add("dxguid.lib");
conf.LibraryFiles.Add("volatileaccessu.lib");
conf.SourceFilesBuildExcludeRegex.Add(@".*\\HAL\\API\\Vulkan\\.*");
conf.Defines.Add("HAL_BACKEND_D3D12");
}
else // Vulkan
{
// Vulkan backend: include Vulkan/ folder, exclude D3D12/ and DXGI/
conf.SourceFilesBuildExcludeRegex.Add(@".*\\HAL\\API\\D3D12\\.*");
conf.SourceFilesBuildExcludeRegex.Add(@".*\\HAL\\DXGI\\.*");
conf.Defines.Add("HAL_BACKEND_VULKAN");
// vulkan-1.lib is generated from C:\Windows\System32\vulkan-1.dll
// (the Vulkan loader shipped with GPU drivers). It lives next to
// the Vulkan module wrapper so the project is self-contained.
// If the Vulkan SDK is later installed, replace this with the SDK lib:
// %VULKAN_SDK%\Lib\vulkan-1.lib
// conf.LibraryFiles.Add(@"[project.SharpmakeCsPath]\sources\Modules\vulkan\vulkan-1.lib");
}
// DXC folder is always compiled — DXC emits SPIR-V for Vulkan too.
// (No exclusion needed for DXC.)
conf.AddPublicDependency<Core>(target);
}
}
[Sharpmake.Generate]
public class RenderSystem : Library
{
public RenderSystem()
{
SourceRootPath = @"[project.SharpmakeCsPath]\sources\RenderSystem";
AssemblyName = "RenderSystem";
}
public override void ConfigureAll(Configuration conf, CustomTarget target)
{
base.ConfigureAll(conf, target);
conf.AddPublicDependency<HAL>(target);
}
}
[Sharpmake.Generate]
public class SIGParser : Application
{
public SIGParser()
{
SourceRootPath = @"[project.SharpmakeCsPath]\sources\SIGParser";
AssemblyName = "SIGParser";
}
public override void ConfigureAll(Configuration conf, CustomTarget target)
{
base.ConfigureAll(conf, target);
conf.Options.Remove(Options.Vc.Linker.SubSystem.Windows);
conf.Options.Add(Options.Vc.General.CharacterSet.Unicode);
conf.Options.Remove(Options.Vc.General.WarningLevel.Level3); // hate warnings, love errors
conf.Options.Add(Options.Vc.General.WarningLevel.Level0); // hate warnings, love errors
// conf.Options.Remove(Options.Vc.Compiler.CppLanguageStandard.Latest);
// conf.Options.Add(Options.Vc.Compiler.CppLanguageStandard.CPP14);
conf.VcxprojUserFile = new Project.Configuration.VcxprojUserFileSettings();
conf.VcxprojUserFile.LocalDebuggerWorkingDirectory = @"[project.SharpmakeCsPath]\sources\SIGParser";
conf.AddPublicDependency<Core>(target);
}
}
[Sharpmake.Generate]
public class Spectrum : Application
{
public Spectrum()
{
SourceRootPath = @"[project.SharpmakeCsPath]\sources\Spectrum";
AssemblyName = "Spectrum";
}
public override void ConfigureAll(Configuration conf, CustomTarget target)
{
base.ConfigureAll(conf, target);
//conf.IsBlobbed = true;
conf.LibraryFiles.Add("Onecore.lib");
conf.VcxprojUserFile = new Project.Configuration.VcxprojUserFileSettings();
conf.VcxprojUserFile.LocalDebuggerWorkingDirectory = @"[project.SharpmakeCsPath]\workdir";
conf.AddPublicDependency<RenderSystem>(target);
}
}
[Sharpmake.Generate]
public class Resources : Common
{
public Resources()
{
SourceRootPath = @"[project.SharpmakeCsPath]\workdir";
AssemblyName = "Resources";
}
public override void ConfigureAll(Configuration conf, CustomTarget target)
{
base.ConfigureAll(conf, target);
// workdir has no Defines.h; redirect to the top of the chain.
conf.ForcedIncludes.Remove(@"[project.SourceRootPath]\Defines.h");
conf.ForcedIncludes.Add(@"[project.SharpmakeCsPath]\sources\Spectrum\Defines.h");
}
}
[Sharpmake.Generate]
public class Test : Application
{
public Test()
{
SourceRootPath = @"[project.SharpmakeCsPath]\sources\Test";
AssemblyName = "SpectrumTest";
}
public override void ConfigureAll(Configuration conf, CustomTarget target)
{
base.ConfigureAll(conf, target);
conf.Options.Remove(Options.Vc.Linker.SubSystem.Windows);
conf.VcxprojUserFile = new Project.Configuration.VcxprojUserFileSettings();
conf.VcxprojUserFile.LocalDebuggerWorkingDirectory = @"[project.SharpmakeCsPath]\workdir";
conf.AddPublicDependency<RenderSystem>(target);
}
}
[Sharpmake.Generate]
public class SpectrumSolution : Solution
{
public SpectrumSolution()
: base(typeof(CustomTarget))
{
AddTargets(new CustomTarget
{
Platform = Platform.win64,
DevEnv = DevEnv.vs2026,
Optimization = Optimization.Release,
Mode = Mode.Debug | Mode.Profile | Mode.Retail,
Backend = Backend.D3D12 | Backend.Vulkan
});
}
[Configure()]
public void ConfigureAll(Configuration conf, CustomTarget target)
{
conf.SolutionFileName = "Spectrum";
conf.SolutionPath = @"[solution.SharpmakeCsPath]\projects\";
string platformName = string.Empty;
switch (target.Mode)
{
case Mode.Debug: platformName += "Debug"; break;
case Mode.Retail: platformName += "Retail"; break;
case Mode.Profile: platformName += "Profile"; break;
default:
throw new NotImplementedException();
}
switch (target.Backend)
{
case Backend.D3D12: platformName += "-D3D12"; break;
case Backend.Vulkan: platformName += "-Vulkan"; break;
default:
throw new NotImplementedException();
}
conf.Name = platformName;
conf.AddProject<Spectrum>(target);
conf.AddProject<SIGParser>(target);
conf.AddProject<Test>(target);
conf.AddProject<Resources>(target);
}
[Sharpmake.Main]
public static void SharpmakeMain(Sharpmake.Arguments arguments)
{
FastBuildSettings.FastBuildMakeCommand = @"[project.SharpmakeCsPath]\tools\FastBuild\FBuild.exe";
arguments.Generate<SpectrumSolution>();
}
}
}