Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 62 additions & 41 deletions packages/g/glslang/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,45 @@ package("glslang")

add_patches("1.3.246+1", "https://github.com/KhronosGroup/glslang/commit/1e4955adbcd9b3f5eaf2129e918ca057baed6520.patch", "47893def550f1684304ef7c49da38f0a8fe35c190a3452d3bf58370b3ee7165d")

add_configs("binaryonly", {description = "Only use binary program.", default = false, type = "boolean"})
add_configs("exceptions", {description = "Build with exception support.", default = false, type = "boolean"})
add_configs("rtti", {description = "Build with RTTI support.", default = false, type = "boolean"})
add_configs("default_resource_limits", {description = "Build with default resource limits.", default = false, type = "boolean"})
add_configs("binaryonly", {description = "Only use binary program.", default = false, type = "boolean"})
add_configs("exceptions", {description = "Build with exception support.", default = false, type = "boolean"})
add_configs("spirv_tools", {description = "Enable SPIRV-Tools integration (Optimizer).", default = false, type = "boolean"})
add_configs("hlsl", {description = "Enable HLSL support.", default = true, type = "boolean"})
add_configs("rtti", {description = "Build with RTTI support.", default = false, type = "boolean"})
add_configs("tools", {description = "Build the glslangValidator tool.", default = false, type = "boolean"})
add_configs("default_resource_limits", {description = "Build with default resource limits.", default = false, type = "boolean"})
if is_plat("wasm") then
add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
end

add_deps("cmake", "python 3.x", {kind = "binary"})
add_deps("spirv-tools")
if is_plat("linux") then
add_deps("cmake")
if is_plat("linux", "bsd") then
add_syslinks("pthread")
end

add_defines("ENABLE_HLSL")

on_load(function (package)
if package:config("binaryonly") then
if package:is_binary() or package:config("binaryonly") then
package:config_set("tools", true)
package:set("kind", "binary")
end
if package:config("spirv_tools") or package:config("tools") then
package:add("deps", "python 3.x", {kind = "binary"})
end
if package:config("spirv_tools") then
package:add("deps", "spirv-tools")
end

if package:config("tools") or package:is_binary() then
package:addenv("PATH", "bin")
end

package:add("links", "glslang", "MachineIndependent", "GenericCodeGen", "OGLCompiler", "OSDependent", "SPIRV", "SPVRemapper")
if package:config("hlsl") then
package:add("links", "HLSL")
end
if package:config("default_resource_limits") then
package:add("links", "glslang-default-resource-limits")
end
end)

on_fetch(function (package, opt)
Expand All @@ -54,57 +73,59 @@ package("glslang")
end)

on_install(function (package)
package:addenv("PATH", "bin")
io.replace("CMakeLists.txt", "ENABLE_OPT OFF", "ENABLE_OPT ON")
io.replace("StandAlone/CMakeLists.txt", "target_link_libraries(glslangValidator ${LIBRARIES})", [[
target_link_libraries(glslangValidator ${LIBRARIES} SPIRV-Tools-opt SPIRV-Tools-link SPIRV-Tools-reduce SPIRV-Tools)
]], {plain = true})
io.replace("SPIRV/CMakeLists.txt", "target_link_libraries(SPIRV PRIVATE MachineIndependent SPIRV-Tools-opt)", [[
target_link_libraries(SPIRV PRIVATE MachineIndependent SPIRV-Tools-opt SPIRV-Tools-link SPIRV-Tools-reduce SPIRV-Tools)
]], {plain = true})
if package:config("spirv_tools") then
io.replace("StandAlone/CMakeLists.txt", "target_link_libraries(glslangValidator ${LIBRARIES})", [[
target_link_libraries(glslangValidator ${LIBRARIES} SPIRV-Tools-opt SPIRV-Tools-link SPIRV-Tools-reduce SPIRV-Tools)
]], {plain = true})
io.replace("SPIRV/CMakeLists.txt", "target_link_libraries(SPIRV PRIVATE MachineIndependent SPIRV-Tools-opt)", [[
target_link_libraries(SPIRV PRIVATE MachineIndependent SPIRV-Tools-opt SPIRV-Tools-link SPIRV-Tools-reduce SPIRV-Tools)
]], {plain = true})
end

-- glslang will add a debug lib postfix for win32 platform, disable this to fix compilation issues under windows
io.replace("CMakeLists.txt", 'set(CMAKE_DEBUG_POSTFIX "d")', [[
message(WARNING "Disabled CMake Debug Postfix for xmake package generation")
]], {plain = true})

if package:is_plat("wasm") then
-- wasm-ld doesn't support --no-undefined
io.replace("CMakeLists.txt", [[add_link_options("-Wl,--no-undefined")]], "", {plain = true})
end
local configs = {"-DENABLE_CTEST=OFF", "-DBUILD_EXTERNAL=OFF"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
if package:is_plat("windows") then
table.insert(configs, "-DBUILD_SHARED_LIBS=OFF")
if package:debug() then
table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''")
end
else
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
end

local configs = {"-DENABLE_CTEST=OFF", "-DGLSLANG_TESTS=OFF", "-DBUILD_EXTERNAL=OFF", "-DENABLE_PCH=OFF"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_EXCEPTIONS=" .. (package:config("exceptions") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_HLSL=" .. (package:config("hlsl") and "ON" or "OFF"))
table.insert(configs, "-DENABLE_RTTI=" .. (package:config("rtti") and "ON" or "OFF"))
table.insert(configs, "-DALLOW_EXTERNAL_SPIRV_TOOLS=ON")
import("package.tools.cmake").install(package, configs, {packagedeps = {"spirv-tools"}})
if not package:config("binaryonly") then
package:add("links", "glslang", "MachineIndependent", "GenericCodeGen", "OGLCompiler", "OSDependent", "HLSL", "SPIRV", "SPVRemapper")
end
if package:config("default_resource_limits") then
package:add("links", "glslang", "glslang-default-resource-limits")
table.insert(configs, "-DENABLE_GLSLANG_BINARIES=" .. (package:config("tools") and "ON" or "OFF"))

local packagedeps = {}
if package:config("spirv_tools") then
table.insert(configs, "-DENABLE_OPT=ON")
table.insert(configs, "-DALLOW_EXTERNAL_SPIRV_TOOLS=ON")
table.insert(packagedeps, "spirv-tools")
else
table.insert(configs, "-DENABLE_OPT=OFF")
end
import("package.tools.cmake").install(package, configs, {packagedeps = packagedeps})

os.cp("glslang/MachineIndependent/**.h", package:installdir("include", "glslang", "MachineIndependent"))
os.cp("glslang/Include/**.h", package:installdir("include", "glslang", "Include"))

-- https://github.com/KhronosGroup/glslang/releases/tag/12.3.0
local bindir = package:installdir("bin")
local glslangValidator = path.join(bindir, "glslangValidator" .. (is_host("windows") and ".exe" or ""))
if not os.isfile(glslangValidator) then
local glslang = path.join(bindir, "glslang" .. (is_host("windows") and ".exe" or ""))
os.trycp(glslang, glslangValidator)
if package:config("tools") then
local bindir = package:installdir("bin")
local glslangValidator = path.join(bindir, "glslangValidator" .. (is_host("windows") and ".exe" or ""))
if not os.isfile(glslangValidator) then
local glslang = path.join(bindir, "glslang" .. (is_host("windows") and ".exe" or ""))
os.trycp(glslang, glslangValidator)
end
end
end)

on_test(function (package)
if not package:is_cross() then
if not package:is_cross() and package:config("tools") then
os.vrun("glslangValidator --version")
end

Expand Down
Loading