xmake.lua 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package("brotli")
  2. set_homepage("https://github.com/google/brotli")
  3. set_description("Brotli compression format.")
  4. set_license("MIT")
  5. set_urls("https://github.com/google/brotli/archive/$(version).tar.gz",
  6. "https://github.com/google/brotli.git")
  7. add_versions("v1.1.0", "e720a6ca29428b803f4ad165371771f5398faba397edf6778837a18599ea13ff")
  8. add_versions("v1.0.9", "f9e8d81d0405ba66d181529af42a3354f838c939095ff99930da6aa9cdf6fe46")
  9. -- Fix VC C++ 12.0 BROTLI_MSVC_VERSION_CHECK calls
  10. -- VC <= 2012 build failed
  11. if is_plat("windows") then
  12. add_patches("v1.0.9", path.join(os.scriptdir(), "patches", "1.0.9", "common_platform.patch"),
  13. "5d7363a6ed1f9a504dc7af08920cd184f0d04d1ad12d25d657364cf0a2dae6bb")
  14. add_patches("v1.0.9", path.join(os.scriptdir(), "patches", "1.0.9", "tool_brotli.patch"),
  15. "333e2a0306cf33f2fac381aa6b81afd3d1237e7511e5cc8fe7fb760d16d01ca1")
  16. end
  17. add_links("brotlienc", "brotlidec", "brotlicommon")
  18. if is_plat("mingw") and is_subhost("msys") then
  19. add_extsources("pacman::brotli")
  20. elseif is_plat("linux") then
  21. add_extsources("pacman::brotli", "apt::libbrotli-dev")
  22. elseif is_plat("macosx") then
  23. add_extsources("brew::brotli")
  24. end
  25. on_load(function (package)
  26. package:addenv("PATH", "bin")
  27. end)
  28. if on_fetch then
  29. on_fetch("linux", "macosx", function (package, opt)
  30. if opt.system then
  31. local result
  32. for _, name in ipairs({"libbrotlidec", "libbrotlienc", "libbrotlicommon"}) do
  33. local pkginfo = package.find_package and package:find_package("pkgconfig::" .. name, opt)
  34. if pkginfo then
  35. if not result then
  36. result = table.copy(pkginfo)
  37. else
  38. local includedirs = pkginfo.sysincludedirs or pkginfo.includedirs
  39. result.links = table.wrap(result.links)
  40. result.linkdirs = table.wrap(result.linkdirs)
  41. result.includedirs = table.wrap(result.includedirs)
  42. table.join2(result.includedirs, includedirs)
  43. table.join2(result.linkdirs, pkginfo.linkdirs)
  44. table.join2(result.links, pkginfo.links)
  45. end
  46. end
  47. end
  48. return result
  49. end
  50. end)
  51. end
  52. on_install(function (package)
  53. os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
  54. local configs = {buildir = "xbuild", vers = package:version_str()}
  55. if package:config("shared") then
  56. configs.kind = "shared"
  57. end
  58. if package:is_plat("linux") and package:config("pic") ~= false then
  59. configs.cxflags = "-fPIC"
  60. end
  61. import("package.tools.xmake").install(package, configs)
  62. end)
  63. on_test(function(package)
  64. if not package:is_cross() then
  65. os.vrun("brotli --version")
  66. end
  67. assert(package:check_csnippets([[
  68. void test() {
  69. BrotliEncoderState* s = BrotliEncoderCreateInstance(NULL, NULL, NULL);
  70. BrotliEncoderDestroyInstance(s);
  71. }
  72. ]], {includes = "brotli/encode.h"}))
  73. end)