xmake.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package("glfw3webgpu")
  2. set_description("An extension for the GLFW library for using WebGPU native.")
  3. set_homepage("https://github.com/eliemichel/glfw3webgpu")
  4. set_license("MIT")
  5. add_urls("https://github.com/eliemichel/glfw3webgpu/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/eliemichel/glfw3webgpu.git")
  7. add_versions("v1.3.0-alpha", "608386a158a22636756dd44932f25675a68f190552481f48d45d63573edd5f2b")
  8. add_versions("v1.2.0", "28387b960aff573728bde2bf0fa876c33608cdadaca8d23f4a46cd31920ab633")
  9. add_versions("v1.1.0", "307ba86a724adc84a875e8bd2374baad0fabc77797f20f9a1779eef8d9ffe95a")
  10. add_versions("v1.0.1", "b98c63f1905f0e4cf99229de8b7e5c2693fdf3b8d684b5a43d60f21f67d33e6b")
  11. add_deps("wgpu-native", "glfw")
  12. if is_plat("macosx", "iphoneos") then
  13. add_frameworks("Metal", "Foundation", "QuartzCore")
  14. end
  15. on_load(function (package)
  16. if package:is_plat("windows") then
  17. package:add("defines", "GLFW_EXPOSE_NATIVE_WIN32")
  18. elseif package:is_plat("macosx", "iphoneos") then
  19. package:add("defines", "GLFW_EXPOSE_NATIVE_COCOA")
  20. end
  21. if package:config("x11") then
  22. package:add("defines", "GLFW_EXPOSE_NATIVE_X11")
  23. elseif package:config("wayland") then
  24. package:add("defines", "GLFW_EXPOSE_NATIVE_WAYLAND")
  25. end
  26. end)
  27. on_install("windows|x64", "windows|x86", "linux|x86_64", "macosx|x86_64", "macosx|arm64", function (package)
  28. if package:is_plat("macosx", "iphoneos") then
  29. os.mv("glfw3webgpu.c", "glfw3webgpu.m")
  30. end
  31. local configs = {}
  32. local glfw = package:dep("glfw")
  33. if glfw then
  34. if glfw:config("x11") then
  35. configs.x11 = true
  36. end
  37. if glfw:config("wayland") then
  38. configs.wayland = true
  39. end
  40. end
  41. io.writefile("xmake.lua", [[
  42. add_rules("mode.debug", "mode.release")
  43. option("x11", {default = false})
  44. option("wayland", {default = false})
  45. add_requires("wgpu-native", "glfw")
  46. target("glfw3webgpu")
  47. set_kind("$(kind)")
  48. set_languages("c11")
  49. add_headerfiles("glfw3webgpu.h")
  50. add_mxflags("-fno-objc-arc")
  51. add_packages("wgpu-native")
  52. add_packages("glfw")
  53. if is_plat("iphoneos", "macosx") then
  54. add_frameworks("Metal", "Foundation", "QuartzCore")
  55. add_files("glfw3webgpu.m")
  56. else
  57. add_files("glfw3webgpu.c")
  58. end
  59. if is_plat("windows") and is_kind("shared") then
  60. add_rules("utils.symbols.export_all")
  61. end
  62. if is_plat("windows") then
  63. add_defines("GLFW_EXPOSE_NATIVE_WIN32")
  64. elseif is_plat("macosx", "iphoneos") then
  65. add_defines("GLFW_EXPOSE_NATIVE_COCOA")
  66. end
  67. if has_config("x11") then
  68. add_defines("GLFW_EXPOSE_NATIVE_X11")
  69. elseif has_config("wayland") then
  70. add_defines("GLFW_EXPOSE_NATIVE_WAYLAND")
  71. end
  72. ]])
  73. import("package.tools.xmake").install(package, configs)
  74. end)
  75. on_test(function (package)
  76. if package:version() and package:version():minor() >= 3 then
  77. assert(package:has_cfuncs("glfwCreateWindowWGPUSurface", {includes = "glfw3webgpu.h"}))
  78. else
  79. assert(package:has_cfuncs("glfwGetWGPUSurface", {includes = "glfw3webgpu.h"}))
  80. end
  81. end)