浏览代码

socket-io-client: add package (#6869)

* socket-io-client: add package

* websocketpp: add `standalone_asio` option, socket-io-client: use `asio::asio`

* follow fix

* Try pass `rapidjson` into packagedeps

* limit wasm, re-try find `rapidjson`

* try pass `asio` in `packagedeps`

* Update xmake.lua

* fix deps

---------

Co-authored-by: star9029 <[email protected]>
Saikari 5 月之前
父节点
当前提交
3290ee5743
共有 2 个文件被更改,包括 74 次插入4 次删除
  1. 60 0
      packages/s/socket-io-client/xmake.lua
  2. 14 4
      packages/w/websocketpp/xmake.lua

+ 60 - 0
packages/s/socket-io-client/xmake.lua

@@ -0,0 +1,60 @@
+package("socket-io-client")
+    set_homepage("https://github.com/socketio/socket.io-client-cpp")
+    set_description("C++11 implementation of Socket.IO client")
+    set_license("MIT")
+
+    add_urls("https://github.com/socketio/socket.io-client-cpp.git", {submodules = false})
+    add_versions("2024.07.17", "da779141a7379cc30c870d48295033bc16a23c66")
+
+    if is_plat("linux", "bsd") then
+        add_syslinks("pthread")
+    end
+
+    add_deps("cmake")
+    if is_subhost("windows") then
+        add_deps("pkgconf")
+    else
+        add_deps("pkg-config")
+    end
+    add_deps("websocketpp", "rapidjson", "openssl", "asio <=1.32.0")
+
+    on_install("!wasm", function (package)
+        io.replace("CMakeLists.txt", "find_package(asio CONFIG REQUIRED)", "find_package(PkgConfig)\npkg_check_modules(asio REQUIRED IMPORTED_TARGET asio)", {plain = true})
+        io.replace("CMakeLists.txt", "asio::asio", "PkgConfig::asio", {plain = true})
+        io.replace("CMakeLists.txt", " asio ", " PkgConfig::asio ", {plain = true})
+
+        if package:is_plat("windows", "mingw") then
+            local syslinks = table.concat(package:dep("openssl"):get("syslinks"), " ")
+            io.replace("CMakeLists.txt",
+                "target_link_libraries(sioclient PRIVATE ",
+                format("target_link_libraries(sioclient PRIVATE %s ", syslinks), {plain = true})
+            io.replace("CMakeLists.txt",
+                "target_link_libraries(sioclient_tls PRIVATE OpenSSL::SSL OpenSSL::Crypto)",
+                format("target_link_libraries(sioclient_tls PRIVATE OpenSSL::SSL OpenSSL::Crypto %s)", syslinks), {plain = true})
+        end
+
+        local configs = {"-DUSE_SUBMODULES=OFF", "-DBUILD_TESTING=OFF"}
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+        table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+        if package:config("shared") and package:is_plat("windows") then
+            table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
+        end
+        import("package.tools.cmake").install(package, configs)
+    end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            #include <string>
+            using namespace sio;
+            using namespace std;
+            void test() {
+            socket::ptr current_socket;
+            current_socket->on("new message", sio::socket::event_listener_aux(
+                [&](string const& name, message::ptr const& data, bool isAck,message::list &ack_resp)
+                {
+                    string user = data->get_map()["username"]->get_string();
+                    string message = data->get_map()["message"]->get_string();
+                }));
+            }
+        ]]}, {configs = {languages = "c++11"}, includes = "sio_client.h"}))
+    end)

+ 14 - 4
packages/w/websocketpp/xmake.lua

@@ -6,12 +6,22 @@ package("websocketpp")
     add_urls("https://github.com/zaphoyd/websocketpp/archive/refs/tags/$(version).tar.gz",
              "https://github.com/zaphoyd/websocketpp.git")
     add_versions("0.8.2", "6ce889d85ecdc2d8fa07408d6787e7352510750daa66b5ad44aacb47bea76755")
-
-    -- Compatibility fixes for Boost 1.87 Reference to PR https://github.com/zaphoyd/websocketpp/pull/1164
-    add_patches("0.8.2", [[https://github.com/zaphoyd/websocketpp/compare/0.8.2%2E%2E%2Eamini-allight%3Awebsocketpp%3Adevelop.diff]], "5396d10ebe593f031580b3c3683f205a8d4c57f2d0942d48c5a4b74e64365f97")
+    
+    add_configs("asio_standalone", {description = "Use standalone asio", default = true, type = "boolean"})
 
     add_deps("cmake")
-    add_deps("boost", {configs = {system = true, asio = true, regex = true, thread = true}})
+
+    on_load(function (package)
+        if package:config("asio_standalone") then
+            package:add("defines", "ASIO_STANDALONE", "_WEBSOCKETPP_CPP11_STL_")
+            package:add("deps", "asio 1.32.0")
+            package:add("deps", "boost", {configs = {system = true, regex = true, thread = true, type_traits = true}})
+        else
+            package:add("deps", "boost", {configs = {system = true, asio = true, regex = true, thread = true}})
+            -- Compatibility fixes for Boost 1.87 Reference to PR https://github.com/zaphoyd/websocketpp/pull/1164
+            package:add("patches", "0.8.2", [[https://github.com/zaphoyd/websocketpp/compare/0.8.2%2E%2E%2Eamini-allight%3Awebsocketpp%3Adevelop.diff]], "5396d10ebe593f031580b3c3683f205a8d4c57f2d0942d48c5a4b74e64365f97")
+        end
+    end)
 
     on_install("!wasm", function (package)
         local configs = {"-DCMAKE_POLICY_DEFAULT_CMP0057=NEW"}