xmake.lua 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_plat("windows") and package:config("shared") then
  27. package:add("defines", "ZSTD_DLL_IMPORT=1")
  28. end
  29. end)
  30. on_install(function (package)
  31. if not package:config("cmake") then
  32. os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
  33. import("package.tools.xmake").install(package, {ver = package:version_str()})
  34. return
  35. end
  36. os.cd("build/cmake")
  37. local configs = {"-DBUILD_TESTING=OFF"}
  38. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  39. table.insert(configs, "-DZSTD_BUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
  40. table.insert(configs, "-DZSTD_BUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
  41. table.insert(configs, "-DZSTD_BUILD_PROGRAMS=" .. (package:config("tools") and "ON" or "OFF"))
  42. table.insert(configs, "-DZSTD_BUILD_CONTRIB=" .. (package:config("contrib") and "ON" or "OFF"))
  43. import("package.tools.cmake").install(package, configs)
  44. if package:is_plat("windows") then
  45. -- Some custom Findzstd.cmake will match zstd.lib
  46. local lib = package:installdir("lib/zstd_static.lib")
  47. if os.isfile(lib) then
  48. os.cp(lib, path.join(package:installdir("lib"), "zstd.lib"))
  49. package:add("links", "zstd")
  50. end
  51. end
  52. end)
  53. on_test(function (package)
  54. assert(package:has_cfuncs("ZSTD_compress", {includes = {"zstd.h"}}))
  55. assert(package:has_cfuncs("ZSTD_decompress", {includes = {"zstd.h"}}))
  56. end)