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