@@ -25,26 +25,45 @@ package("glslang")
2525
2626 add_patches (" 1.3.246+1" , " https://github.com/KhronosGroup/glslang/commit/1e4955adbcd9b3f5eaf2129e918ca057baed6520.patch" , " 47893def550f1684304ef7c49da38f0a8fe35c190a3452d3bf58370b3ee7165d" )
2727
28- add_configs (" binaryonly" , {description = " Only use binary program." , default = false , type = " boolean" })
29- add_configs (" exceptions" , {description = " Build with exception support." , default = false , type = " boolean" })
30- add_configs (" rtti" , {description = " Build with RTTI support." , default = false , type = " boolean" })
31- add_configs (" default_resource_limits" , {description = " Build with default resource limits." , default = false , type = " boolean" })
28+ add_configs (" binaryonly" , {description = " Only use binary program." , default = false , type = " boolean" })
29+ add_configs (" exceptions" , {description = " Build with exception support." , default = false , type = " boolean" })
30+ add_configs (" spirv_tools" , {description = " Enable SPIRV-Tools integration (Optimizer)." , default = false , type = " boolean" })
31+ add_configs (" hlsl" , {description = " Enable HLSL support." , default = true , type = " boolean" })
32+ add_configs (" rtti" , {description = " Build with RTTI support." , default = false , type = " boolean" })
33+ add_configs (" tools" , {description = " Build the glslangValidator tool." , default = false , type = " boolean" })
34+ add_configs (" default_resource_limits" , {description = " Build with default resource limits." , default = false , type = " boolean" })
3235 if is_plat (" wasm" ) then
3336 add_configs (" shared" , {description = " Build shared library." , default = false , type = " boolean" , readonly = true })
3437 end
3538
36- add_deps (" cmake" , " python 3.x" , {kind = " binary" })
37- add_deps (" spirv-tools" )
38- if is_plat (" linux" ) then
39+ add_deps (" cmake" )
40+ if is_plat (" linux" , " bsd" ) then
3941 add_syslinks (" pthread" )
4042 end
4143
42- add_defines (" ENABLE_HLSL" )
43-
4444 on_load (function (package )
45- if package :config (" binaryonly" ) then
45+ if package :is_binary () or package :config (" binaryonly" ) then
46+ package :config_set (" tools" , true )
4647 package :set (" kind" , " binary" )
4748 end
49+ if package :config (" spirv_tools" ) or package :config (" tools" ) then
50+ package :add (" deps" , " python 3.x" , {kind = " binary" })
51+ end
52+ if package :config (" spirv_tools" ) then
53+ package :add (" deps" , " spirv-tools" )
54+ end
55+
56+ if package :config (" tools" ) or package :is_binary () then
57+ package :addenv (" PATH" , " bin" )
58+ end
59+
60+ package :add (" links" , " glslang" , " MachineIndependent" , " GenericCodeGen" , " OGLCompiler" , " OSDependent" , " SPIRV" , " SPVRemapper" )
61+ if package :config (" hlsl" ) then
62+ package :add (" links" , " HLSL" )
63+ end
64+ if package :config (" default_resource_limits" ) then
65+ package :add (" links" , " glslang-default-resource-limits" )
66+ end
4867 end )
4968
5069 on_fetch (function (package , opt )
@@ -54,57 +73,59 @@ package("glslang")
5473 end )
5574
5675 on_install (function (package )
57- package :addenv (" PATH" , " bin" )
58- io .replace (" CMakeLists.txt" , " ENABLE_OPT OFF" , " ENABLE_OPT ON" )
59- io .replace (" StandAlone/CMakeLists.txt" , " target_link_libraries(glslangValidator ${LIBRARIES})" , [[
60- target_link_libraries(glslangValidator ${LIBRARIES} SPIRV-Tools-opt SPIRV-Tools-link SPIRV-Tools-reduce SPIRV-Tools)
61- ]] , {plain = true })
62- io .replace (" SPIRV/CMakeLists.txt" , " target_link_libraries(SPIRV PRIVATE MachineIndependent SPIRV-Tools-opt)" , [[
63- target_link_libraries(SPIRV PRIVATE MachineIndependent SPIRV-Tools-opt SPIRV-Tools-link SPIRV-Tools-reduce SPIRV-Tools)
64- ]] , {plain = true })
76+ if package :config (" spirv_tools" ) then
77+ io .replace (" StandAlone/CMakeLists.txt" , " target_link_libraries(glslangValidator ${LIBRARIES})" , [[
78+ target_link_libraries(glslangValidator ${LIBRARIES} SPIRV-Tools-opt SPIRV-Tools-link SPIRV-Tools-reduce SPIRV-Tools)
79+ ]] , {plain = true })
80+ io .replace (" SPIRV/CMakeLists.txt" , " target_link_libraries(SPIRV PRIVATE MachineIndependent SPIRV-Tools-opt)" , [[
81+ target_link_libraries(SPIRV PRIVATE MachineIndependent SPIRV-Tools-opt SPIRV-Tools-link SPIRV-Tools-reduce SPIRV-Tools)
82+ ]] , {plain = true })
83+ end
84+
6585 -- glslang will add a debug lib postfix for win32 platform, disable this to fix compilation issues under windows
6686 io .replace (" CMakeLists.txt" , ' set(CMAKE_DEBUG_POSTFIX "d")' , [[
6787 message(WARNING "Disabled CMake Debug Postfix for xmake package generation")
6888 ]] , {plain = true })
89+
6990 if package :is_plat (" wasm" ) then
7091 -- wasm-ld doesn't support --no-undefined
7192 io .replace (" CMakeLists.txt" , [[ add_link_options("-Wl,--no-undefined")]] , " " , {plain = true })
7293 end
73- local configs = {" -DENABLE_CTEST=OFF" , " -DBUILD_EXTERNAL=OFF" }
74- table.insert (configs , " -DCMAKE_BUILD_TYPE=" .. (package :debug () and " Debug" or " Release" ))
75- if package :is_plat (" windows" ) then
76- table.insert (configs , " -DBUILD_SHARED_LIBS=OFF" )
77- if package :debug () then
78- table.insert (configs , " -DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''" )
79- end
80- else
81- table.insert (configs , " -DBUILD_SHARED_LIBS=" .. (package :config (" shared" ) and " ON" or " OFF" ))
82- end
94+
95+ local configs = {" -DENABLE_CTEST=OFF" , " -DGLSLANG_TESTS=OFF" , " -DBUILD_EXTERNAL=OFF" , " -DENABLE_PCH=OFF" }
96+ table.insert (configs , " -DCMAKE_BUILD_TYPE=" .. (package :is_debug () and " Debug" or " Release" ))
97+ table.insert (configs , " -DBUILD_SHARED_LIBS=" .. (package :config (" shared" ) and " ON" or " OFF" ))
8398 table.insert (configs , " -DENABLE_EXCEPTIONS=" .. (package :config (" exceptions" ) and " ON" or " OFF" ))
99+ table.insert (configs , " -DENABLE_HLSL=" .. (package :config (" hlsl" ) and " ON" or " OFF" ))
84100 table.insert (configs , " -DENABLE_RTTI=" .. (package :config (" rtti" ) and " ON" or " OFF" ))
85- table.insert (configs , " -DALLOW_EXTERNAL_SPIRV_TOOLS=ON" )
86- import (" package.tools.cmake" ).install (package , configs , {packagedeps = {" spirv-tools" }})
87- if not package :config (" binaryonly" ) then
88- package :add (" links" , " glslang" , " MachineIndependent" , " GenericCodeGen" , " OGLCompiler" , " OSDependent" , " HLSL" , " SPIRV" , " SPVRemapper" )
89- end
90- if package :config (" default_resource_limits" ) then
91- package :add (" links" , " glslang" , " glslang-default-resource-limits" )
101+ table.insert (configs , " -DENABLE_GLSLANG_BINARIES=" .. (package :config (" tools" ) and " ON" or " OFF" ))
102+
103+ local packagedeps = {}
104+ if package :config (" spirv_tools" ) then
105+ table.insert (configs , " -DENABLE_OPT=ON" )
106+ table.insert (configs , " -DALLOW_EXTERNAL_SPIRV_TOOLS=ON" )
107+ table.insert (packagedeps , " spirv-tools" )
108+ else
109+ table.insert (configs , " -DENABLE_OPT=OFF" )
92110 end
111+ import (" package.tools.cmake" ).install (package , configs , {packagedeps = packagedeps })
93112
94113 os .cp (" glslang/MachineIndependent/**.h" , package :installdir (" include" , " glslang" , " MachineIndependent" ))
95114 os .cp (" glslang/Include/**.h" , package :installdir (" include" , " glslang" , " Include" ))
96115
97116 -- https://github.com/KhronosGroup/glslang/releases/tag/12.3.0
98- local bindir = package :installdir (" bin" )
99- local glslangValidator = path.join (bindir , " glslangValidator" .. (is_host (" windows" ) and " .exe" or " " ))
100- if not os.isfile (glslangValidator ) then
101- local glslang = path.join (bindir , " glslang" .. (is_host (" windows" ) and " .exe" or " " ))
102- os .trycp (glslang , glslangValidator )
117+ if package :config (" tools" ) then
118+ local bindir = package :installdir (" bin" )
119+ local glslangValidator = path.join (bindir , " glslangValidator" .. (is_host (" windows" ) and " .exe" or " " ))
120+ if not os.isfile (glslangValidator ) then
121+ local glslang = path.join (bindir , " glslang" .. (is_host (" windows" ) and " .exe" or " " ))
122+ os .trycp (glslang , glslangValidator )
123+ end
103124 end
104125 end )
105126
106127 on_test (function (package )
107- if not package :is_cross () then
128+ if not package :is_cross () and package : config ( " tools " ) then
108129 os .vrun (" glslangValidator --version" )
109130 end
110131
0 commit comments