xmake.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package("zstd")
  2. set_homepage("https://www.zstd.net/")
  3. set_description("Zstandard - Fast real-time compression algorithm")
  4. set_license("BSD-3-Clause")
  5. set_urls("https://github.com/facebook/zstd/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/facebook/zstd.git")
  7. add_versions("v1.5.7", "37d7284556b20954e56e1ca85b80226768902e2edabd3b649e9e72c0c9012ee3")
  8. add_versions("v1.4.5", "734d1f565c42f691f8420c8d06783ad818060fc390dee43ae0a89f86d0a4f8c2")
  9. add_versions("v1.5.0", "0d9ade222c64e912d6957b11c923e214e2e010a18f39bec102f572e693ba2867")
  10. add_versions("v1.5.2", "f7de13462f7a82c29ab865820149e778cbfe01087b3a55b5332707abf9db4a6e")
  11. add_versions("v1.5.5", "98e9c3d949d1b924e28e01eccb7deed865eefebf25c2f21c702e5cd5b63b85e1")
  12. add_versions("v1.5.6", "30f35f71c1203369dc979ecde0400ffea93c27391bfd2ac5a9715d2173d92ff7")
  13. add_patches("1.5.6", "patches/1.5.6/fix-rc-build.patch", "c898c652a4f48ce63b0b9da03406eb988de453f0c7b93f43f42f4e1e394eb17c")
  14. add_configs("cmake", {description = "Use cmake buildsystem", default = true, type = "boolean"})
  15. add_configs("tools", {description = "Build tools", default = false, type = "boolean"})
  16. add_configs("contrib", {description = "Build contrib", default = false, type = "boolean"})
  17. if is_plat("linux", "bsd") then
  18. add_syslinks("pthread")
  19. end
  20. on_load(function (package)
  21. -- Some downstream cmake package need patch: find_package(zstd CONFIG REQUIRED)
  22. -- https://github.com/facebook/zstd/issues/3271
  23. if package:config("cmake") then
  24. package:add("deps", "cmake")
  25. end
  26. if package:is_binary() then
  27. package:config_set("tools", true)
  28. end
  29. if package:is_plat("windows") and package:config("shared") then
  30. package:add("defines", "ZSTD_DLL_IMPORT=1")
  31. end
  32. end)
  33. on_install(function (package)
  34. if not package:config("cmake") then
  35. os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
  36. import("package.tools.xmake").install(package, {ver = package:version_str()})
  37. return
  38. end
  39. os.cd("build/cmake")
  40. local configs = {"-DBUILD_TESTING=OFF"}
  41. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  42. table.insert(configs, "-DZSTD_BUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
  43. table.insert(configs, "-DZSTD_BUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
  44. table.insert(configs, "-DZSTD_BUILD_PROGRAMS=" .. (package:config("tools") and "ON" or "OFF"))
  45. table.insert(configs, "-DZSTD_BUILD_CONTRIB=" .. (package:config("contrib") and "ON" or "OFF"))
  46. import("package.tools.cmake").install(package, configs)
  47. if package:is_plat("windows") then
  48. -- Some custom Findzstd.cmake will match zstd.lib
  49. local lib = package:installdir("lib/zstd_static.lib")
  50. if os.isfile(lib) then
  51. os.cp(lib, path.join(package:installdir("lib"), "zstd.lib"))
  52. package:add("links", "zstd")
  53. end
  54. end
  55. end)
  56. on_test(function (package)
  57. if package:is_library() then
  58. assert(package:has_cfuncs("ZSTD_compress", {includes = {"zstd.h"}}))
  59. assert(package:has_cfuncs("ZSTD_decompress", {includes = {"zstd.h"}}))
  60. end
  61. if not package:is_cross() and package:config("tools") then
  62. os.vrun("zstd --version")
  63. end
  64. end)