xmake.lua 3.5 KB

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