xmake.lua 3.2 KB

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