xmake.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package("hiredis")
  2. set_homepage("https://github.com/redis/hiredis")
  3. set_description("Minimalistic C client for Redis >= 1.2")
  4. set_license("BSD-3-Clause")
  5. add_urls("https://github.com/redis/hiredis/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/redis/hiredis.git")
  7. add_versions("v1.3.0", "25cee4500f359cf5cad3b51ed62059aadfc0939b05150c1f19c7e2829123631c")
  8. add_versions("v1.0.2", "e0ab696e2f07deb4252dda45b703d09854e53b9703c7d52182ce5a22616c3819")
  9. add_versions("v1.1.0", "fe6d21741ec7f3fc9df409d921f47dfc73a4d8ff64f4ac6f1d95f951bf7f53d6")
  10. add_versions("v1.2.0", "82ad632d31ee05da13b537c124f819eb88e18851d9cb0c30ae0552084811588c")
  11. if is_plat("windows", "mingw") then
  12. add_configs("shared", {description = "Build shared library.", default = true, type = "boolean", readonly = true})
  13. add_configs("vs_runtime", {description = "Set vs compiler runtime.", default = "MD", readonly = true})
  14. end
  15. add_configs("openssl", {description = "with openssl library", default = false, type = "boolean"})
  16. add_deps("cmake")
  17. on_load(function (package)
  18. if package:config("openssl") then
  19. package:add("deps", "openssl")
  20. end
  21. end)
  22. on_install(function (package)
  23. if package:version() and package:version():lt("1.2.0") then
  24. io.replace("CMakeLists.txt",
  25. "TARGET_INCLUDE_DIRECTORIES(hiredis PUBLIC $<INSTALL_INTERFACE:.>",
  26. "TARGET_INCLUDE_DIRECTORIES(hiredis PUBLIC $<INSTALL_INTERFACE:include>",
  27. {plain = true})
  28. if not package:config("shared") then
  29. -- Following change is required for package user to call `find_package(hiredis)` to work.
  30. io.replace("CMakeLists.txt", "ADD_LIBRARY(hiredis SHARED", "ADD_LIBRARY(hiredis", {plain = true})
  31. io.replace("CMakeLists.txt", "ADD_LIBRARY(hiredis_ssl SHARED", "ADD_LIBRARY(hiredis_ssl", {plain = true})
  32. end
  33. end
  34. local configs = {
  35. "-DDISABLE_TESTS=ON",
  36. "-DENABLE_SSL_TESTS=OFF",
  37. }
  38. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  39. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  40. table.insert(configs, "-DENABLE_SSL=" .. (package:config("openssl") and "ON" or "OFF"))
  41. import("package.tools.cmake").install(package, configs, {buildir = "build"})
  42. if package:version() and package:version():lt("1.2.0") then
  43. -- hiredis cmake builds static and shared library at the same time.
  44. -- Remove unneeded one after install.
  45. if package:config("shared") then
  46. -- maybe is import library, libhiredis.dll.a
  47. if not package:is_plat("mingw") then
  48. os.tryrm(path.join(package:installdir("lib"), "*.a"))
  49. end
  50. else
  51. os.tryrm(path.join(package:installdir("lib"), "*.so"))
  52. os.tryrm(path.join(package:installdir("lib"), "*.so.*"))
  53. os.tryrm(path.join(package:installdir("lib"), "*.dylib"))
  54. end
  55. end
  56. end)
  57. on_test(function (package)
  58. assert(package:has_cfuncs("redisCommand", {includes = "hiredis/hiredis.h"}))
  59. end)