xmake.lua 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package("glib")
  2. set_homepage("https://docs.gtk.org/glib/")
  3. set_description("Low-level core library that forms the basis for projects such as GTK+ and GNOME.")
  4. set_license("LGPL-2.1")
  5. add_urls("https://download.gnome.org/sources/glib/$(version).tar.xz", {alias = "home", version = function (version)
  6. return format("%d.%d/glib-%s", version:major(), version:minor(), version)
  7. end, excludes = {"*/COPYING"}})
  8. add_urls("https://gitlab.gnome.org/GNOME/glib/-/archive/$(version)/glib-$(version).tar.gz", {alias = "gitlab"})
  9. add_urls("https://gitlab.gnome.org/GNOME/glib.git")
  10. add_versions("home:2.71.0", "926816526f6e4bba9af726970ff87be7dac0b70d5805050c6207b7bb17ea4fca")
  11. add_versions("home:2.78.1", "915bc3d0f8507d650ead3832e2f8fb670fce59aac4d7754a7dab6f1e6fed78b2")
  12. add_versions("home:2.85.0", "97cfb0466ae41fca4fa2a57a15440bee15b54ae76a12fb3cbff11df947240e48")
  13. add_patches("2.71.0", path.join(os.scriptdir(), "patches", "2.71.0", "macosx.patch"), "a0c928643e40f3a3dfdce52950486c7f5e6f6e9cfbd76b20c7c5b43de51d6399")
  14. if is_plat("mingw") and is_subhost("msys") then
  15. add_extsources("pacman::glib2")
  16. elseif is_plat("linux") then
  17. add_extsources("apt::libglib2.0-dev", "pacman::glib2")
  18. elseif is_plat("macosx") then
  19. add_extsources("brew::glib")
  20. end
  21. if not is_subhost("windows") then
  22. add_extsources("pkgconfig::glib-2.0")
  23. end
  24. if is_plat("windows", "mingw") then
  25. add_syslinks("user32", "shell32", "ole32", "ws2_32", "shlwapi", "iphlpapi", "dnsapi", "uuid")
  26. elseif is_plat("macosx") then
  27. add_syslinks("resolv")
  28. add_frameworks("AppKit", "Foundation", "CoreServices", "CoreFoundation")
  29. elseif is_plat("linux") then
  30. add_syslinks("pthread", "dl", "resolv")
  31. end
  32. add_deps("meson", "ninja")
  33. if is_subhost("windows") then
  34. add_deps("pkgconf")
  35. else
  36. add_deps("pkg-config")
  37. end
  38. add_deps("libffi", "zlib")
  39. if is_plat("linux") then
  40. add_deps("libiconv")
  41. elseif is_plat("macosx") then
  42. add_deps("libiconv", "libintl")
  43. elseif is_plat("windows", "mingw") then
  44. add_deps("libintl")
  45. end
  46. add_includedirs("include/glib-2.0", "lib/glib-2.0/include")
  47. add_links("gio-2.0", "gobject-2.0", "gthread-2.0", "gmodule-2.0", "glib-2.0")
  48. on_fetch("macosx", "linux", function (package, opt)
  49. if opt.system and package.find_package then
  50. local result
  51. for _, name in ipairs({"gio-2.0", "gobject-2.0", "gthread-2.0", "gmodule-2.0", "glib-2.0"}) do
  52. local pkginfo = package.find_package and package:find_package("pkgconfig::" .. name, opt)
  53. if pkginfo then
  54. if not result then
  55. result = table.copy(pkginfo)
  56. else
  57. local includedirs = pkginfo.sysincludedirs or pkginfo.includedirs
  58. result.links = table.wrap(result.links)
  59. result.linkdirs = table.wrap(result.linkdirs)
  60. result.includedirs = table.wrap(result.includedirs)
  61. table.join2(result.includedirs, includedirs)
  62. table.join2(result.linkdirs, pkginfo.linkdirs)
  63. table.join2(result.links, pkginfo.links)
  64. end
  65. end
  66. end
  67. return result
  68. end
  69. end)
  70. on_load(function (package)
  71. if package:gitref() or package:version():ge("2.74.0") then
  72. package:add("deps", "pcre2")
  73. else
  74. package:add("deps", "pcre")
  75. end
  76. package:addenv("PATH", "bin")
  77. end)
  78. on_install("windows", "macosx", "linux", "cross", "mingw", function (package)
  79. io.gsub("meson.build", "subdir%('tests'%)", "")
  80. io.gsub("meson.build", "subdir%('fuzzing'%)", "")
  81. io.gsub("gio/meson.build", "subdir%('tests'%)", "")
  82. io.replace("meson.build", "glib_conf.set('HAVE_SELINUX', selinux_dep.found())", "", {plain = true})
  83. if package:is_plat("windows") then
  84. io.gsub("meson.build", "dependency%('libffi',", "dependency('libffi', modules: ['libffi::ffi'],")
  85. end
  86. local configs = {
  87. "-Dbsymbolic_functions=false",
  88. "-Ddtrace=false",
  89. "-Dman=false",
  90. "-Dgtk_doc=false",
  91. "-Dtests=false",
  92. "-Dinstalled_tests=false",
  93. "-Dsystemtap=false",
  94. "-Dselinux=disabled",
  95. "-Dlibmount=disabled",
  96. "-Dsysprof=disabled",
  97. }
  98. if package:is_plat("macosx") and package:version():le("2.61.0") then
  99. table.insert(configs, "-Diconv=native")
  100. elseif package:is_plat("windows") and package:version():le("2.74.0") then
  101. table.insert(configs, "-Diconv=external")
  102. end
  103. table.insert(configs, "-Dglib_debug=" .. (package:is_debug() and "enabled" or "disabled"))
  104. table.insert(configs, "-Ddefault_library=" .. (package:config("shared") and "shared" or "static"))
  105. table.insert(configs, "-Dgio_module_dir=" .. path.join(package:installdir(), "lib/gio/modules"))
  106. import("package.tools.meson").install(package, configs, {packagedeps = {"libintl", "libiconv", "libffi", "zlib"}})
  107. local deps = {}
  108. if package:dep("libiconv") and not package:dep("libiconv"):is_system() then
  109. table.insert(deps, "libiconv")
  110. end
  111. if package:dep("libintl") and not package:dep("libintl"):is_system() then
  112. table.insert(deps, "libintl")
  113. end
  114. if #deps > 0 then
  115. local glib_pc = package:installdir("lib/pkgconfig/glib-2.0.pc")
  116. io.replace(glib_pc, "Requires: ", format("Requires: %s ", table.concat(deps, " ")), {plain = true})
  117. end
  118. end)
  119. on_test(function (package)
  120. assert(package:has_cfuncs("g_list_append", {includes = "glib.h"}))
  121. end)