xmake.lua 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package("gtk4")
  2. set_homepage("https://gtk.org/")
  3. set_description("Toolkit for creating graphical user interfaces")
  4. set_license("LGPL-2.0-or-later")
  5. add_urls("https://download.gnome.org/sources/gtk/$(version).tar.xz", {version = function (version)
  6. return format("%d.%d/gtk-%s", version:major(), version:minor(), version)
  7. end})
  8. add_versions("4.13.3", "4f04a43e7c287360473f34fc27b629f64875795f3bc7ec2781df449c5e72f312")
  9. add_configs("shared", {description = "Build shared library.", default = true, type = "boolean", readonly = true})
  10. add_configs("x11", {description = "Enable the X11 gdk backend.", default = is_plat("linux"), type = "boolean"})
  11. add_configs("wayland", {description = "Enable the wayland gdk backend.", default = false, type = "boolean"})
  12. on_fetch("windows", "macosx", "linux", function (package, opt)
  13. if opt.system then
  14. return package:find_package("pkgconfig::gtk4")
  15. end
  16. end)
  17. if is_plat("linux") then
  18. add_extsources("apt::libgtk-4-dev")
  19. end
  20. add_deps("meson", "ninja")
  21. add_deps("glib", "pango", "gdk-pixbuf", "libepoxy", "graphene", "fribidi", "pcre2")
  22. add_deps("harfbuzz", "cairo", {configs = {glib = true}})
  23. if is_plat("linux") then
  24. add_deps("libdrm")
  25. add_deps("libiconv")
  26. elseif is_plat("macosx") then
  27. add_deps("libiconv", {system = true})
  28. add_deps("libintl")
  29. elseif is_plat("windows") then
  30. add_deps("libintl")
  31. end
  32. add_includedirs("include/gtk-4.0")
  33. on_load("windows|x64", "windows|x86", "macosx", "linux", function (package)
  34. if package:config("x11") then
  35. package:add("deps", "libx11", "libxrandr", "libxi", "libxcursor", "libxext", "libxdamage", "libxfixes", "libxinerama")
  36. end
  37. if package:config("wayland") then
  38. package:add("deps", "wayland", "libxkbcommon")
  39. end
  40. end)
  41. on_install("windows|x64", "windows|x86", "macosx", "linux", function (package)
  42. local mesondir = package:dep("meson"):installdir()
  43. local gnomemod = path.join(mesondir, "mesonbuild", "modules", "gnome.py")
  44. if package:is_plat("windows") then
  45. -- workaround https://github.com/mesonbuild/meson/issues/6710
  46. io.replace(gnomemod, "absolute_paths=True,", "absolute_paths=False,#x", {plain = true})
  47. end
  48. io.replace("meson.build", "xext_dep,", "[x11_dep, xext_dep],", {plain = true})
  49. io.replace("meson.build", "xi_dep)", "[x11_dep, xext_dep, xi_dep])", {plain = true})
  50. local configs = {"-Dintrospection=disabled",
  51. "-Dbuild-tests=false",
  52. "-Dbuild-testsuite=false",
  53. "-Dbuild-examples=false",
  54. "-Dbuild-demos=false",
  55. "-Dmedia-gstreamer=disabled",
  56. "-Dmedia-ffmpeg=disabled"}
  57. table.insert(configs, "-Dx11-backend=" .. (package:config("x11") and "true" or "false"))
  58. table.insert(configs, "-Dwayland-backend=" .. (package:config("wayland") and "true" or "false"))
  59. import("package.tools.meson").install(package, configs, {packagedeps = {"libintl", "libiconv", "pcre2"}})
  60. if package:is_plat("windows") then
  61. io.replace(gnomemod, "absolute_paths=False,#x", "absolute_paths=True,", {plain = true})
  62. end
  63. package:addenv("PATH", "bin")
  64. end)
  65. on_test(function (package)
  66. assert(package:check_csnippets({test = [[
  67. int test(int argc, char *argv[]) {
  68. GtkApplication *app =
  69. gtk_application_new("xmake.app", G_APPLICATION_DEFAULT_FLAGS);
  70. return g_application_run(G_APPLICATION(app), argc, argv);
  71. }
  72. ]]}, {includes = "gtk/gtk.h"}))
  73. end)