xmake.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package("ixwebsocket")
  2. set_homepage("https://github.com/machinezone/IXWebSocket")
  3. set_description("websocket and http client and server library, with TLS support and very few dependencies")
  4. set_license("BSD-3-Clause")
  5. add_urls("https://github.com/machinezone/IXWebSocket/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/machinezone/IXWebSocket.git")
  7. add_versions("v11.4.6", "c024334f8e45980836c67008979a884d6dcc5ef067dd2eb1fa7241f4c17ddc32")
  8. add_versions("v11.4.5", "c5fc225edec32bf7d583e55347ef2c9c4940d005c13ef5e848354a85602f5fd6")
  9. add_versions("v11.4.4", "9ef7fba86a91ce18693451466ddc54b1e0c4a7dc4466c3028d888d6d55dde539")
  10. local default_ssl = nil
  11. if not is_plat("windows") then
  12. if is_plat("android", "iphoneos", "wasm") then
  13. default_ssl = "mbedtls"
  14. else
  15. default_ssl = "openssl"
  16. end
  17. end
  18. add_configs("ssl", {description = "Enable SSL", default = default_ssl, type = "string", values = {"openssl", "mbedtls"}})
  19. add_configs("use_tls", {description = "Use TLS", default = false, type = "boolean"})
  20. if is_plat("wasm") then
  21. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  22. end
  23. add_deps("zlib")
  24. if is_plat("windows") then
  25. add_syslinks("ws2_32", "crypt32")
  26. elseif is_plat("macosx") then
  27. add_frameworks("Foundation", "Security")
  28. elseif is_plat("linux", "bsd") then
  29. add_syslinks("pthread")
  30. end
  31. add_deps("cmake")
  32. on_load(function (package)
  33. if package:config("ssl") == "openssl" then
  34. package:add("deps", "openssl")
  35. elseif package:config("ssl") == "mbedtls" then
  36. package:add("deps", "mbedtls")
  37. end
  38. if package:config("use_tls") then
  39. if is_plat("windows") then
  40. if not package:dep("openssl") then
  41. package:add("deps", "mbedtls")
  42. end
  43. elseif not package:dep("mbedtls") then
  44. package:add("deps", "openssl")
  45. end
  46. end
  47. end)
  48. on_install(function (package)
  49. local configs = {"-DCMAKE_CXX_STANDARD=11"}
  50. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  51. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  52. table.insert(configs, "-DUSE_TLS=" .. (package:config("use_tls") and "ON" or "OFF"))
  53. if package:dep("openssl") then
  54. table.insert(configs, "-DUSE_OPEN_SSL=1")
  55. elseif package:dep("mbedtls") then
  56. table.insert(configs, "-DUSE_MBED_TLS=1")
  57. end
  58. local zlib = package:dep("zlib")
  59. if zlib and not zlib:is_system() then
  60. local fetchinfo = zlib:fetch({external = false})
  61. if fetchinfo then
  62. local includedirs = fetchinfo.includedirs or fetchinfo.sysincludedirs
  63. if includedirs and #includedirs > 0 then
  64. table.insert(configs, "-DZLIB_INCLUDE_DIR=" .. table.concat(includedirs, " "))
  65. end
  66. local libfiles = fetchinfo.libfiles
  67. if libfiles then
  68. table.insert(configs, "-DZLIB_LIBRARY=" .. table.concat(libfiles, " "))
  69. end
  70. end
  71. end
  72. if is_plat("wasm") then
  73. io.replace("ixwebsocket/IXUserAgent.cpp", [[ss << " " << PLATFORM_NAME]], [[ss << " " << "unknown platform"]], {plain = true})
  74. end
  75. io.replace("ixwebsocket/IXSocketMbedTLS.cpp", [[/* errorMsg */]], [[errorMsg]], {plain = true})
  76. import("package.tools.cmake").install(package, configs)
  77. end)
  78. on_test(function (package)
  79. assert(package:check_cxxsnippets({test = [[
  80. #include <ixwebsocket/IXNetSystem.h>
  81. #include <ixwebsocket/IXWebSocket.h>
  82. void test() {
  83. ix::initNetSystem();
  84. ix::WebSocket webSocket;
  85. std::string url("wss://echo.websocket.org");
  86. webSocket.setUrl(url);
  87. webSocket.start();
  88. webSocket.send("Hello world");
  89. }
  90. ]]}, {configs = {languages = "cxx11"}}))
  91. end)