xmake.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.4.5", "734d1f565c42f691f8420c8d06783ad818060fc390dee43ae0a89f86d0a4f8c2")
  8. add_versions("v1.5.0", "0d9ade222c64e912d6957b11c923e214e2e010a18f39bec102f572e693ba2867")
  9. add_versions("v1.5.2", "f7de13462f7a82c29ab865820149e778cbfe01087b3a55b5332707abf9db4a6e")
  10. add_versions("v1.5.5", "98e9c3d949d1b924e28e01eccb7deed865eefebf25c2f21c702e5cd5b63b85e1")
  11. add_versions("v1.5.6", "30f35f71c1203369dc979ecde0400ffea93c27391bfd2ac5a9715d2173d92ff7")
  12. add_patches("1.5.6", "patches/1.5.6/fix-rc-build.patch", "c898c652a4f48ce63b0b9da03406eb988de453f0c7b93f43f42f4e1e394eb17c")
  13. add_configs("cmake", {description = "Use cmake buildsystem", default = true, type = "boolean"})
  14. add_configs("tools", {description = "Build tools", default = false, type = "boolean"})
  15. add_configs("contrib", {description = "Build contrib", default = false, type = "boolean"})
  16. if is_plat("linux", "bsd") then
  17. add_syslinks("pthread")
  18. end
  19. on_load(function (package)
  20. -- Some downstream cmake package need patch: find_package(zstd CONFIG REQUIRED)
  21. -- https://github.com/facebook/zstd/issues/3271
  22. if package:config("cmake") then
  23. package:add("deps", "cmake")
  24. end
  25. if package:is_plat("windows") and package:config("shared") then
  26. package:add("defines", "ZSTD_DLL_IMPORT=1")
  27. end
  28. end)
  29. on_install(function (package)
  30. if not package:config("cmake") then
  31. os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
  32. import("package.tools.xmake").install(package, {ver = package:version_str()})
  33. return
  34. end
  35. os.cd("build/cmake")
  36. local configs = {"-DBUILD_TESTING=OFF"}
  37. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  38. table.insert(configs, "-DZSTD_BUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
  39. table.insert(configs, "-DZSTD_BUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
  40. table.insert(configs, "-DZSTD_BUILD_PROGRAMS=" .. (package:config("tools") and "ON" or "OFF"))
  41. table.insert(configs, "-DZSTD_BUILD_CONTRIB=" .. (package:config("contrib") and "ON" or "OFF"))
  42. import("package.tools.cmake").install(package, configs)
  43. if package:is_plat("windows") then
  44. -- Some custom Findzstd.cmake will match zstd.lib
  45. local lib = package:installdir("lib/zstd_static.lib")
  46. if os.isfile(lib) then
  47. os.cp(lib, path.join(package:installdir("lib"), "zstd.lib"))
  48. package:add("links", "zstd")
  49. end
  50. end
  51. end)
  52. on_test(function (package)
  53. assert(package:has_cfuncs("ZSTD_compress", {includes = {"zstd.h"}}))
  54. assert(package:has_cfuncs("ZSTD_decompress", {includes = {"zstd.h"}}))
  55. end)