xmake.lua 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package("libhv")
  2. set_homepage("https://github.com/ithewei/libhv")
  3. set_description("Like libevent, libev, and libuv, libhv provides event-loop with non-blocking IO and timer, but simpler api and richer protocols.")
  4. add_urls("https://github.com/ithewei/libhv/archive/v$(version).zip", {excludes = {"*/html/*"}})
  5. add_versions("1.0.0", "39adb77cc7addaba82b69fa9a433041c8288f3d9c773fa360162e3391dcf6a7b")
  6. add_versions("1.1.0", "a753c268976d9c4f85dcc10be2377bebc36d4cb822ac30345cf13f2a7285dbe3")
  7. add_versions("1.1.1", "e012d9752fe8fb3f788cb6360cd9abe61d4ccdc1d2085501d85f1068eba8603e")
  8. add_versions("1.2.1", "d658a8e7f1a3b2f3b0ddcabe3b13595b70246c94d57f2c27bf9a9946431b2e63")
  9. add_versions("1.2.2", "a15ec12cd77d1fb745a74465b8bdee5a45247e854371db9d0863573beca08466")
  10. add_versions("1.2.3", "c30ace04597a0558ce957451d64acc7cd3260d991dc21628e048c8dec3028f34")
  11. add_versions("1.2.4", "389fa60f0d6697b5267ddc69de00e4844f1d8ac8ee4d2ad3742850589c20d46e")
  12. add_versions("1.2.6", "dd5ed854f5cdc0bdd3a3310a9f0452ec194e2907006551aebbb603825a989ed1")
  13. add_versions("1.3.0", "e7a129dcabb541baeb8599e419380df6aa98afc6e04874ac88a6d2bdb5a973a5")
  14. add_versions("1.3.1", "66fb17738bc51bee424b6ddb1e3b648091fafa80c8da6d75626d12b4188e0bdc")
  15. add_configs("protocol", {description = "compile protocol", default = false, type = "boolean"})
  16. add_configs("http", {description = "compile http", default = true, type = "boolean"})
  17. add_configs("http_server", {description = "compile http/server", default = true, type = "boolean"})
  18. add_configs("http_client", {description = "compile http/client", default = true, type = "boolean"})
  19. add_configs("consul", {description = "compile consul", default = false, type = "boolean"})
  20. add_configs("ipv6", {description = "enable ipv6", default = false, type = "boolean"})
  21. add_configs("uds", {description = "enable Unix Domain Socket", default = false, type = "boolean"})
  22. add_configs("windump", {description = "enable Windows MiniDumpWriteDump", default = false, type = "boolean"})
  23. add_configs("multimap", {description = "use MultiMap", default = false, type = "boolean"})
  24. add_configs("curl", {description = "with curl library", default = false, type = "boolean"})
  25. add_configs("nghttp2", {description = "with nghttp2 library", default = false, type = "boolean"})
  26. add_configs("openssl", {description = "with openssl library", default = false, type = "boolean"})
  27. add_configs("mbedtls", {description = "with mbedtls library", default = false, type = "boolean"})
  28. add_configs("GNUTLS", {description="with gnutls library",default=false,type="boolean"})
  29. if is_plat("linux") then
  30. add_syslinks("pthread")
  31. elseif is_plat("macosx", "iphoneos") then
  32. add_frameworks("CoreFoundation", "Security")
  33. elseif is_plat("windows") then
  34. add_syslinks("advapi32")
  35. elseif is_plat("mingw") then
  36. add_syslinks("ws2_32")
  37. add_syslinks("pthread")
  38. end
  39. add_deps("cmake")
  40. on_load(function (package)
  41. if package:config("openssl") then
  42. package:add("deps", "openssl")
  43. elseif package:config("mbedtls") then
  44. package:add("deps", "mbedtls")
  45. elseif package:config("curl") then
  46. package:add("deps", "libcurl")
  47. elseif package:config("nghttp2") then
  48. -- TODO
  49. end
  50. if package:is_plat("windows") and not package:config("shared") then
  51. package:add("defines", "HV_STATICLIB")
  52. end
  53. end)
  54. on_install("windows", "linux", "macosx", "android", "iphoneos", "mingw", function(package)
  55. local configs = {"-DBUILD_EXAMPLES=OFF", "-DBUILD_UNITTEST=OFF"}
  56. table.insert(configs, "-DBUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
  57. table.insert(configs, "-DBUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
  58. for _, name in ipairs({"with_protocol",
  59. "with_http",
  60. "with_http_server",
  61. "with_http_client",
  62. "with_consul",
  63. "with_curl",
  64. "with_nghttp2",
  65. "with_openssl",
  66. "with_mbedtls",
  67. "enable_ipv6",
  68. "enable_uds",
  69. "enable_windump",
  70. "use_multimap",
  71. "WITH_GNUTLS"}) do
  72. local config_name = name:gsub("with_", ""):gsub("use_", ""):gsub("enable_", "")
  73. table.insert(configs, "-D" .. name:upper() .. "=" .. (package:config(config_name) and "ON" or "OFF"))
  74. end
  75. local packagedeps = {}
  76. if package:config("openssl") then
  77. table.insert(packagedeps, "openssl")
  78. elseif package:config("mbedtls") then
  79. table.insert(packagedeps, "mbedtls")
  80. end
  81. if package:is_plat("iphoneos") then
  82. io.replace("ssl/appletls.c", "ret = SSLSetProtocolVersionEnabled(appletls->session, kSSLProtocolAll, true);",
  83. "ret = SSLSetProtocolVersionMin(appletls->session, kTLSProtocol12);", {plain = true})
  84. elseif package:is_plat("windows") and package:is_arch("arm.*") then
  85. io.replace("base/hplatform.h", "defined(__arm__)", "defined(__arm__) || defined(_M_ARM)", {plain = true})
  86. io.replace("base/hplatform.h", "defined(__aarch64__) || defined(__ARM64__)", "defined(__aarch64__) || defined(__ARM64__) || defined(_M_ARM64)", {plain = true})
  87. end
  88. import("package.tools.cmake").install(package, configs, {packagedeps = packagedeps})
  89. end)
  90. on_test(function(package)
  91. assert(package:has_cfuncs("hloop_new", {includes = "hv/hloop.h"}))
  92. end)