forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
premake5.lua
1962 lines (1618 loc) · 65.5 KB
/
premake5.lua
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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- premake5.lua
-- This file describes the build configuration for Slang so
-- that premake can generate platform-specific build files
-- using Premake 5 (https://premake.github.io/).
--
-- To update the build files that are checked in to the Slang repository,
-- run a `premake5` binary and specify the appropriate action, e.g.:
--
-- premake5.exe --os=windows vs2015
--
-- If you are trying to build Slang on another platform, then you
-- can try invoking `premake5` for your desired OS and build format
-- and see what happens.
--
-- If you are going to modify this file to change/customize the Slang
-- build, then you may need to read up on Premake's approach and
-- how it uses/abuses Lua syntax. A few important things to note:
--
-- * Everything that *looks* like a declarative (e.g., `kind "SharedLib"`)
-- is actually a Lua function call (e.g., `kind("SharedLib")`) that
-- modifies the behind-the-scenes state that describes the build.
--
-- * Many of these function calls are "sticky" and affect subsequent
-- calls, so ordering matters a *lot*. This file uses indentation to
-- represent some of the flow of state, but it is important to recognize
-- that the indentation is not semantically significant.
--
-- * Because the configuration logic is just executable Lua code, we
-- can capture and re-use bits of configuration logic in ordinary
-- Lua subroutines.
--
-- Now let's move on to the actual build:
-- The "workspace" represents the overall build (the "solution" in
-- Visual Studio terms). It sets up basic build settings that will
-- apply across all projects.
--
-- To output linux will output to linux
-- % premake5 --os=linux gmake2 --build-location="build.linux"
--
-- % cd build.linux
-- % make config=release_x64
-- or
-- % make config=debug_x64
--
-- From in the build directory you can use
-- % premake5 --file=../premake5.lua --os=linux gmake2
-- Fail if we try to use the deprecated 'gmake' generator
if _ACTION == "gmake" then
premake.error "Please use the 'gmake2' generator instead of 'gmake'"
end
--
-- Add the package path for slang-pack/slang-util
-- The question mark is there the name of the module is inserted.
---
local modulePath = "external/slang-binaries/lua-modules/?.lua"
package.path = package.path .. ";" .. modulePath
-- Load the slack package manager module
slangPack = require("slang-pack")
slangUtil = require("slang-util")
-- Load the dependencies from the json file
deps = slangPack.loadDependencies("deps/target-deps.json")
newoption {
trigger = "override-module",
description = "(Optional) Specify a lua file that can override functions",
value = "path"
}
newoption {
trigger = "build-location",
description = "(Optional) Specifiy the location to place solution on root Makefile",
value = "path"
}
newoption {
trigger = "execute-binary",
description = "(Optional) If true binaries used in build will be executed (disable on cross compilation)",
value = "bool",
default = "true",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "build-glslang",
description = "(Optional) If true glslang and spirv-opt will be built",
value = "bool",
default = "false",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "enable-cuda",
description = "(Optional) If true will enable cuda tests, if CUDA is found via CUDA_PATH",
value = "bool",
default = "false",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "enable-nvapi",
description = "(Optional) If true will enable NVAPI, if NVAPI is found via external/nvapi",
value = "bool",
default = "false",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "cuda-sdk-path",
description = "(Optional) Path to the root of CUDA SDK. If set will enable CUDA in build (ie in effect sets enable-cuda=true too)",
value = "path"
}
newoption {
trigger = "enable-optix",
description = "(Optional) If true will enable OptiX build/ tests (also implicitly enables CUDA)",
value = "bool",
default = "false",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "optix-sdk-path",
description = "(Optional) Path to the root of OptiX SDK. (Implicitly enabled OptiX and CUDA)",
value = "path"
}
newoption {
trigger = "enable-profile",
description = "(Optional) If true will enable slang-profile tool - suitable for gprof usage on linux",
value = "bool",
default = "false",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "enable-embed-stdlib",
description = "(Optional) If true build slang with an embedded version of the stdlib",
value = "bool",
default = "false",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "enable-xlib",
description = "(Optional) If true build `gfx` and `platform` with xlib to support windowed apps on linux.",
value = "bool",
default = "true",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "enable-experimental-projects",
description = "(Optional) If true include experimental projects in build.",
value = "bool",
default = "false",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "disable-stdlib-source",
description = "(Optional) If true stdlib source will not be included in binary.",
value = "bool",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "skip-source-generation",
description = "(Optional) If true will skip source generation steps.",
value = "bool",
default = "false",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "deploy-slang-llvm",
description = "(Optional) If true will copy slang-llvm to output directory.",
value = "bool",
default = "true",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "deploy-slang-glslang",
description = "(Optional) If true will copy slang-glslang to output directory.",
value = "bool",
default = "true",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "full-debug-validation",
description = "(Optional) If true will enable full IR validation in debug build. (SLOW!)",
value = "bool",
default = "false",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "enable-asan",
description = "(Optional) If true will enable ASAN (address santizier).",
value = "bool",
default = "false",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "dx-on-vk",
description = "(Optional) If true will use dxvk and vkd3d-proton for DirectX support",
value = "bool",
default = "false",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "enable-aftermath",
description = "(Optional) Enable aftermath in GFX, and add aftermath crash example to project",
value = "bool",
default = "false",
allowed = { { "true", "True"}, { "false", "False" } }
}
newoption {
trigger = "default-spirv-direct",
description = "(Optional) Development flag to make the default SPIR-V path generate directly rather than via GLSL",
value = "bool",
default = "false",
allowed = { { "true", "True"}, { "false", "False" } }
}
buildLocation = _OPTIONS["build-location"]
executeBinary = (_OPTIONS["execute-binary"] == "true")
buildGlslang = (_OPTIONS["build-glslang"] == "true")
enableCuda = not not (_OPTIONS["enable-cuda"] == "true" or _OPTIONS["cuda-sdk-path"])
enableProfile = (_OPTIONS["enable-profile"] == "true")
optixPath = _OPTIONS["optix-sdk-path"]
enableOptix = not not (_OPTIONS["enable-optix"] == "true" or optixPath)
enableProfile = (_OPTIONS["enable-profile"] == "true")
enableEmbedStdLib = (_OPTIONS["enable-embed-stdlib"] == "true")
enableXlib = (_OPTIONS["enable-xlib"] == "true")
skipSourceGeneration = (_OPTIONS["skip-source-generation"] == "true")
deployLLVM = (_OPTIONS["deploy-slang-llvm"] == "true")
deployGLSLang = (_OPTIONS["deploy-slang-glslang"] == "true")
fullDebugValidation = (_OPTIONS["full-debug-validation"] == "true")
enableAsan = (_OPTIONS["enable-asan"] == "true")
dxOnVk = (_OPTIONS["dx-on-vk"] == "true")
enableAftermath = (_OPTIONS["enable-aftermath"] == "true")
defaultSPIRVDirect = (_OPTIONS["default-spirv-direct"] == "true")
-- If stdlib embedding is enabled, disable stdlib source embedding by default
disableStdlibSource = enableEmbedStdLib
-- If embedding is enabled, and the setting `disable-stdlib-source` setting is set, use it's value
if enableEmbedStdLib and _OPTIONS["disable-stdlib-source"] ~= nil then
disableStdlibSource = (_OPTIONS["disable-stdlib-source"] == "true")
end
if enableAftermath then
aftermathPath = "external/nv-aftermath"
if not os.isfile(path.join(aftermathPath, "nsight-aftermath-usage-guidelines.txt")) then
print("external/nv-aftermath directory must hold aftermath SDK")
os.exit(0)
end
printf("Enabled aftermath")
end
-- Determine the target info
targetInfo = slangUtil.getTargetInfo()
--
-- Update the dependencies for the target
--
deps:update(targetInfo.name)
-- Get the target name that can be used as paths that generate for different configurations (ie contains premake Tokens)
targetName = targetInfo.tokenName
-- This is the path where nvapi is expected to be found
nvapiPath = "external/nvapi"
if enableOptix then
optixPath = optixPath or "C:/ProgramData/NVIDIA Corporation/OptiX SDK 7.0.0/"
enableCuda = true
end
-- cudaPath is only set if cuda is enabled, and CUDA_PATH enviromental variable is set
cudaPath = nil
if enableCuda then
-- Get the CUDA path. Use the value set on cuda-sdk-path by default, if not set use the environment variable.
cudaPath = (_OPTIONS["cuda-sdk-path"] or os.getenv("CUDA_PATH"))
end
-- TODO(JS): What's the point in the enable-xlib command line option if it's just overridden here?
if targetInfo.isWindows or os.target() == "macosx" then
enableXlib = false
end
-- Even if we have the nvapi path, we only want to currently enable on windows targets
enableNvapi = not not (os.isdir(nvapiPath) and targetInfo.isWindows and _OPTIONS["enable-nvapi"] == "true")
if enableNvapi then
printf("Enabled NVAPI")
end
overrideModule = {}
local overrideModulePath = _OPTIONS["override-module"]
if overrideModulePath then
overrideModule = require(overrideModulePath)
end
-- This is needed for gcc, for the 'fileno' functions on cygwin
-- _GNU_SOURCE makes realpath available in gcc
if targetInfo.os == "cygwin" then
buildoptions { "-D_POSIX_SOURCE" }
filter { "toolset:gcc*" }
buildoptions { "-D_GNU_SOURCE" }
end
function getPlatforms(targetInfo)
return { "x86", "x64", "aarch64" }
end
workspace "slang"
-- We will support debug/release configuration and x86/x64 builds.
configurations { "Debug", "Release" }
platforms(getPlatforms(targetInfo))
if buildLocation then
location(buildLocation)
end
flags "MultiProcessorCompile"
--
-- Make slang-test the startup project.
--
-- https://premake.github.io/docs/startproject
startproject "slang-test"
-- The output binary directory will be derived from the OS
-- and configuration options, e.g. `bin/windows-x64/debug/`
targetdir("bin/" .. targetName .. "/%{cfg.buildcfg:lower()}")
cppdialect "C++17"
-- Statically link to the C/C++ runtime rather than create a DLL dependency.
staticruntime "On"
-- Turn off edit and continue for all projects. This is needed to avoid
-- linking warnings.
editandcontinue "Off"
-- Once we've set up the common settings, we will make some tweaks
-- that only apply in a subset of cases. Each call to `filter()`
-- changes the "active" filter for subsequent commands. In
-- effect, those commands iwll be ignored when the conditions of
-- the filter aren't satisfied.
-- Our `x64` platform should (obviously) target the x64
-- architecture and similarly for x86.
--
-- https://premake.github.io/docs/architecture/
--
filter { "platforms:x64" }
architecture "x64"
filter { "platforms:x86" }
architecture "x86"
filter { "platforms:aarch64" }
architecture "ARM64"
filter { "platforms:aarch64", "toolset:clang" }
buildoptions { "-arch arm64" }
linkoptions { "-arch arm64" }
filter { "toolset:clang or gcc*" }
-- Makes all symbols hidden by default unless explicitly 'exported'
buildoptions { "-fvisibility=hidden" }
filter { "toolset:clang or gcc*", "files:source/compiler-core/slang-dxc-compiler.cpp" }
-- For the DXC headers
buildoptions { "-fms-extensions" }
-- Disable some warnings
filter { "toolset:clang or gcc*" }
buildoptions {
"-Wno-switch",
"-Wno-parentheses",
"-Wno-unused-local-typedefs",
}
filter { "toolset:gcc*", "language:C++" }
buildoptions { "-Wno-class-memaccess" }
-- If a function returns an address/reference to a local, we want it to produce an error, because
-- it probably means something very bad.
buildoptions { "-Werror=return-local-addr" }
filter { "toolset:clang", "language:C++" }
buildoptions { "-Wno-assume" }
filter { "toolset:clang or gcc*", "language:C++" }
buildoptions { "-Wno-reorder", "-Wno-invalid-offsetof" }
-- Enable some warnings on clang/gcc which are on by default in MSVC
filter { "toolset:clang or gcc*", "language:C++" }
buildoptions { "-Wnarrowing" }
-- When compiling the debug configuration, we want to turn
-- optimization off, make sure debug symbols are output,
-- and add the same preprocessor definition that VS
-- would add by default.
filter { "configurations:debug" }
optimize "Off"
symbols "On"
defines { "_DEBUG" }
-- staticruntime "Off"
-- For the release configuration we will turn optimizations on
-- (we do not yet micro-manage the optimization settings)
-- and set the preprocessor definition that VS would add by default.
filter { "configurations:release" }
optimize "On"
defines { "NDEBUG" }
filter { "system:linux" }
links { "dl" }
--
-- `--no-undefined` - by default if a symbol is not found in a link it will assume it will be resolved at runtime (!)
-- this option ensures that all the referenced symbols exist
--
linkoptions{ "-Wl,-rpath,'$$ORIGIN',--no-as-needed,--no-undefined" }
-- allow libraries to be listed in any order (do not require dependency order)
linkgroups "On"
filter {}
-- For including windows.h in a way that minimized namespace pollution.
-- Although we define these here, we still set them manually in any header
-- files which may be included by another project
defines { "WIN32_LEAN_AND_MEAN", "VC_EXTRALEAN", "NOMINMAX", "_ITERATOR_DEBUG_LEVEL=0" }
if dxOnVk then
defines { "SLANG_CONFIG_DX_ON_VK" }
end
if defaultSPIRVDirect then
defines { "SLANG_CONFIG_DEFAULT_SPIRV_DIRECT" }
end
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
function dumpTable(o)
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. tostring(v) .. ',\n'
end
return s .. '} '
end
function getExecutableSuffix()
if(os.target() == "windows") then
return ".exe"
end
return ""
end
--
-- We are now going to start defining the projects, where
-- each project builds some binary artifact (an executable,
-- library, etc.).
--
-- All of our projects follow a common structure, so rather
-- than reiterate a bunch of build settings, we define
-- some subroutines that make the configuration as concise
-- as possible.
--
-- First, we will define a helper routine for adding all
-- the relevant files from a given directory path:
--
-- Note that this does not work recursively
-- so projects that spread their source over multiple
-- directories will need to take more steps.
function addSourceDir(path)
files
{
path .. "/*.cpp", -- C++ source files
path .. "/*.slang", -- Slang files (for our stdlib)
path .. "/*.h", -- Header files
path .. "/*.hpp", -- C++ style headers (for glslang)
path .. "/*.natvis", -- Visual Studio debugger visualization files
path .. "/*.natstepfilter", -- Visual Studio debugger step filter files
path .. "/*.natjmc", -- Visual Studio debugger step filter files
}
if os.target() == "macosx" then
files { path .. "/*.mm" } -- Objective-C++ files
filter { "files:**.mm" }
compileas "Objective-C++"
filter {}
end
removefiles
{
"**/*.meta.slang.h",
"**/slang-*generated*.h",
"**/gfx-unit-test/test-tmp*"
}
end
-- Adds CUDA dependency to a project
function addCUDAIfEnabled()
if type(cudaPath) == "string" and targetInfo.isWindows then
filter {}
includedirs { cudaPath .. "/include" }
includedirs { cudaPath .. "/include", cudaPath .. "/common/inc" }
links { "cuda", "cudart" }
if optixPath then
defines { "RENDER_TEST_OPTIX" }
includedirs { optixPath .. "include/" }
end
filter { "platforms:x86" }
libdirs { cudaPath .. "/lib/Win32/" }
filter { "platforms:x64" }
libdirs { cudaPath .. "/lib/x64/" }
filter {}
return true
elseif enableCuda then
filter {}
if type(cudaPath) == "string" then
includedirs { cudaPath .. "/include" }
includedirs { cudaPath .. "/include" }
if optixPath then
defines { "GFX_OPTIX" }
includedirs { optixPath .. "include/" }
end
filter { "platforms:x86" }
libdirs { cudaPath .. "/lib32/" }
filter { "platforms:x64" }
libdirs { cudaPath .. "/lib64/" }
filter {}
links { "cuda", "cudart" }
else
print "Error: CUDA is enabled but --cuda-sdk-path is not specified."
end
return true
end
return false
end
--
-- Next we will define a helper routine that all of our
-- projects will bottleneck through. Here `name` is
-- the name for the project (and the base name for
-- whatever output file it produces), while `sourceDir`
-- is the directory that holds the source.
--
-- E.g., for the `slangc` project, the source code
-- is nested in `source/`, so we'd (indirectly) call:
--
-- baseSlangProject("slangc", "source/slangc")
--
-- NOTE! This function will add any source from the sourceDir, *if* it's specified.
-- Pass nil if adding files is not wanted.
function baseSlangProject(name, sourceDir)
-- Start a new project in premake. This switches
-- the "current" project over to the newly created
-- one, so that subsequent commands affect this project.
--
project(name)
-- We need every project to have a stable UUID for
-- output formats (like Visual Studio and XCode projects)
-- that use UUIDs rather than names to uniquely identify
-- projects. If we don't have a stable UUID, then the
-- output files might have spurious diffs whenever we
-- re-run premake generation.
if sourceDir then
uuid(os.uuid(name .. '|' .. sourceDir))
else
-- If we don't have a sourceDir, the name will have to be enough
uuid(os.uuid(name))
end
-- Location could do with a better name than 'other' - but it seems as if %{cfg.buildcfg:lower()} and similar variables
-- is not available for location to expand.
location("build/" .. slangUtil.getBuildLocationName(targetInfo) .. "/" .. name)
-- The intermediate ("object") directory will use a similar
-- naming scheme to the output directory, but will also use
-- the project name to avoid cases where multiple projects
-- have source files with the same name.
--
objdir("intermediate/" .. targetName .. "/%{cfg.buildcfg:lower()}/%{prj.name}")
-- Treat C++ as the default language, projects in other languages can
-- override this later
--
language "C++"
-- By default, Premake generates VS project files that
-- reflect the directory structure of the source code.
-- While this is nice in principle, it creates messy
-- results in practice for our projects.
--
-- Instead, we will use the `vpaths` feature to imitate
-- the default VS behavior of grouping files into
-- virtual subdirectories (VS calls them "filters") for
-- header and source files respectively.
--
-- Note: We are setting `vpaths` using a list of key/value
-- tables instead of just a key/value table, since this
-- appears to be an (undocumented) way to fix the order
-- in which the filters are tested. Otherwise we have
-- issues where premake will nondeterministically decide
-- the check something against the `**.cpp` filter first,
-- and decide that a `foo.cpp.h` file should go into
-- the `"Source Files"` vpath. That behavior seems buggy,
-- but at least we appear to have a workaround.
--
vpaths {
{ ["Header Files"] = { "**.h", "**.hpp"} },
{ ["Source Files"] = { "**.cpp", "**.slang", "**.natvis", "**.natjmc" } },
}
-- Override default options for a project if necessary
if overrideModule.addBaseProjectOptions then
overrideModule.addBaseProjectOptions()
end
--
-- Add the files in the sourceDir
-- NOTE! This doesn't recursively add files in subdirectories
--
if not not sourceDir then
addSourceDir(sourceDir)
end
--
-- Enable ASAN (address sanitizer) if requested.
--
if enableAsan then
if (targetInfo.isWindows) then
buildoptions { "/fsanitize=address" }
flags { "NoIncrementalLink" }
end
end
end
-- We can now use the `baseSlangProject()` subroutine to
-- define helpers for the different categories of project
-- in our source tree.
--
-- For example, the Slang project has several tools that
-- are used during building/testing, but don't need to
-- be distributed. These always have their source code in
-- `tools/<project-name>/`.
--
function tool(name)
-- We use the `group` command here to specify that the
-- next project we create shold be placed into a group
-- named "tools" in a generated IDE solution/workspace.
--
-- This is used in the generated Visual Studio solution
-- to group all the tools projects together in a logical
-- sub-directory of the solution.
--
group "tools"
-- Now we invoke our shared project configuration logic,
-- specifying that the project lives under the `tools/` path.
--
baseSlangProject(name, "tools/" .. name)
-- Finally, we set the project "kind" to produce a console
-- application. This is a reasonable default for tools,
-- and it can be overriden because Premake is stateful,
-- and a subsequent call to `kind()` would overwrite this
-- default.
--
kind "ConsoleApp"
if not targetInfo.isWindows then
links { "pthread" }
end
end
-- "Standard" projects will be those that go to make the binary
-- packages for slang: the shared libraries and executables.
--
function standardProject(name, sourceDir)
-- Because Premake is stateful, any `group()` call by another
-- project would still be in effect when we create a project
-- here (e.g., if somebody had called `tool()` before
-- `standardProject()`), so we are careful here to set the
-- group to an emptry string, which Premake treats as "no group."
--
group ""
baseSlangProject(name, sourceDir)
end
function toolSharedLibrary(name)
group "test-tool"
-- specifying that the project lives under the `tools/` path.
--
baseSlangProject(name .. "-tool", "tools/" .. name)
defines { "SLANG_SHARED_LIBRARY_TOOL" }
kind "SharedLib"
if not targetInfo.isWindows then
links { "pthread" }
end
end
function exampleLibrary(name)
group "examples"
baseSlangProject(name, "examples/"..name)
kind "StaticLib"
includedirs { ".", "tools" }
links { "gfx", "slang", "platform", "gfx-util", "core"}
addCUDAIfEnabled();
end
exampleLibrary "example-base"
-- Finally we have the example programs that show how to use Slang.
--
function example(name)
-- Example programs go into an "example" group
group "examples"
-- They have their source code under `examples/<project-name>/`
baseSlangProject(name, "examples/" .. name)
-- Set up working directory to be the source directory
debugdir("examples/" .. name)
-- By default, all of our examples are GUI applications. One some
-- platforms there is no meaningful distinction between GUI and
-- command-line applications, but it is significant on Windows and MacOS
--
kind "WindowedApp"
-- Every example needs to be able to include the `slang.h` header
-- if it is going to use Slang, so we might as well set up a suitable
-- include path here rather than make each example do it.
--
-- Most of the examples also need the `gfx` library,
-- which lives under `tools/`, so we will add that to the path as well.
--
includedirs { ".", "tools" }
-- The examples also need to link against the slang library,
-- and the `gfx` abstraction layer (which in turn
-- depends on the `core` library). We specify all of that here,
-- rather than in each example.
links { "example-base", "slang", "gfx", "gfx-util", "platform", "core" }
if not targetInfo.isWindows then
links { "pthread" }
end
if targetInfo.isWindows then
else
if enableXlib then
defines { "SLANG_ENABLE_XLIB" }
libdirs { "/usr/X11/lib" }
links {"X11"}
end
end
addCUDAIfEnabled();
end
--
-- Create a project that is used as a build step, typically to
-- build items needed for other dependencies
---
function generatorProject(name, sourcePath, projectKind)
-- We use the `group` command here to specify that the
-- next project we create shold be placed into a group
-- named "generator" in a generated IDE solution/workspace.
--
-- This is used in the generated Visual Studio solution
-- to group all the tools projects together in a logical
-- sub-directory of the solution.
--
group "generator"
-- Set up the project, but do NOT add any source files.
baseSlangProject(name, sourcePath)
-- By default the generator projects run a custom tool and don't
-- require any premake machinery to compile a binary for them.
if projectKind == nil then
kind "Utility"
else
kind (projectKind)
end
if not targetInfo.isWindows then
links { "pthread" }
end
end
--
-- With all of these helper routines defined, we can now define the
-- actual projects quite simply. For example, here is the entire
-- declaration of the "Hello, World" example project:
--
example "hello-world"
kind "ConsoleApp"
includedirs {"external/vulkan/include"}
-- Note how we are calling our custom `example()` subroutine with
-- the same syntax sugar that Premake usually advocates for their
-- `project()` function. This allows us to treat `example` as
-- a kind of specialized "subclass" of `project`
--
-- Let's go ahead and set up the projects for our other example now.
example "platform-test"
example "triangle"
example "ray-tracing"
example "ray-tracing-pipeline"
example "autodiff-texture"
example "gpu-printing"
kind "ConsoleApp"
example "shader-toy"
example "model-viewer"
example "shader-object"
kind "ConsoleApp"
example "cpu-com-example"
kind "ConsoleApp"
example "cpu-hello-world"
kind "ConsoleApp"
if enableAftermath then
example "nv-aftermath-example"
filter {}
local aftermathIncludePath = path.join(aftermathPath, "include")
local aftermathLibPath = path.join(aftermathPath, "lib")
-- Add the aftermath includes
includedirs { aftermathIncludePath }
-- Add the libs directory.
-- Additionally we need to copy dlls that are needed for aftermath usage such that they
-- are available from the executable.
filter { "platforms:x86" }
local libPath = path.join(aftermathLibPath, "x86")
libdirs { libPath }
links { "GFSDK_Aftermath_Lib.x86" }
postbuildcommands {
'{COPY} "$(SolutionDir)"' .. libPath .. '/*.* "%{cfg.targetdir}"'
}
filter { "platforms:x64" }
local libPath = path.join(aftermathLibPath, "x64")
libdirs { libPath }
links { "GFSDK_Aftermath_Lib.x64" }
postbuildcommands {
'{COPY} "$(SolutionDir)"' .. libPath .. '/*.* "%{cfg.targetdir}"'
}
end
-- Most of the other projects have more interesting configuration going
-- on, so let's walk through them in order of increasing complexity.
--
-- The `core` project is a static library that has all the basic types
-- and routines that get shared across both the Slang compiler/runtime
-- and the various tool projects. It's build is pretty simple:
--
standardProject("core", "source/core")
uuid "F9BE7957-8399-899E-0C49-E714FDDD4B65"
kind "StaticLib"
-- We need the core library to be relocatable to be able to link with slang.so
pic "On"
-- For our core implementation, we want to use the most
-- aggressive warning level supported by the target, and
-- to treat every warning as an error to make sure we
-- keep our code free of warnings.
--
warnings "Extra"
includedirs { "external/miniz" }
if targetInfo.isWindows then
addSourceDir "source/core/windows"
else
addSourceDir "source/core/unix"
end
standardProject("compiler-core", "source/compiler-core")
uuid "12C1E89D-F5D0-41D3-8E8D-FB3F358F8126"
kind "StaticLib"
-- We need the compiler-core library to be relocatable to be able to link with slang.so
pic "On"
links { "core" }
-- For our core implementation, we want to use the most
-- aggressive warning level supported by the target, and
-- to treat every warning as an error to make sure we
-- keep our code free of warnings.
--
warnings "Extra"
if targetInfo.isWindows then
addSourceDir "source/compiler-core/windows"
else
addSourceDir "source/compiler-core/unix"
end
standardProject("slang-rt", "source/slang-rt")
uuid "DFC79D72-91DE-434C-871B-B3943B488BEB"
kind "SharedLib"
pic "On"
warnings "Extra"
links {"miniz", "lz4"}
includedirs { "external/miniz" }
defines { "SLANG_RT_DYNAMIC", "SLANG_RT_DYNAMIC_EXPORT" }
addSourceDir "source/core"
if targetInfo.isWindows then
addSourceDir "source/core/windows"
else
addSourceDir "source/core/unix"
links { "pthread" }
end
--
-- The cpp extractor is a tool that scans C++ header files to extract
-- reflection like information, and generate files to handle
-- RTTI fast/simply
---
tool "slang-cpp-extractor"
uuid "CA8A30D1-8FA9-4330-B7F7-84709246D8DC"
includedirs { "." }
links { "compiler-core", "core" }
tool "slang-spirv-embed-generator"
uuid "8da787cc-0e04-450f-8e29-88eac5ebe9bb"
includedirs { "." }
links { "compiler-core", "core" }
tool "slang-lookup-generator"
uuid "3242baa7-fc4c-4f76-83bc-e4403099dc1d"
includedirs { "." }
links { "compiler-core", "core" }