xmake.lua 4.0 KB

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