xmake.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package("socket-io-client")
  2. set_homepage("https://github.com/socketio/socket.io-client-cpp")
  3. set_description("C++11 implementation of Socket.IO client")
  4. set_license("MIT")
  5. add_urls("https://github.com/socketio/socket.io-client-cpp.git", {submodules = false})
  6. add_versions("2024.07.17", "da779141a7379cc30c870d48295033bc16a23c66")
  7. if is_plat("linux", "bsd") then
  8. add_syslinks("pthread")
  9. end
  10. add_deps("cmake")
  11. if is_subhost("windows") then
  12. add_deps("pkgconf")
  13. else
  14. add_deps("pkg-config")
  15. end
  16. add_deps("websocketpp", "rapidjson", "openssl", "asio <=1.32.0")
  17. on_install("!wasm", function (package)
  18. io.replace("CMakeLists.txt", "find_package(asio CONFIG REQUIRED)", "find_package(PkgConfig)\npkg_check_modules(asio REQUIRED IMPORTED_TARGET asio)", {plain = true})
  19. io.replace("CMakeLists.txt", "asio::asio", "PkgConfig::asio", {plain = true})
  20. io.replace("CMakeLists.txt", " asio ", " PkgConfig::asio ", {plain = true})
  21. if package:is_plat("windows", "mingw") then
  22. local syslinks = table.concat(package:dep("openssl"):get("syslinks"), " ")
  23. io.replace("CMakeLists.txt",
  24. "target_link_libraries(sioclient PRIVATE ",
  25. format("target_link_libraries(sioclient PRIVATE %s ", syslinks), {plain = true})
  26. io.replace("CMakeLists.txt",
  27. "target_link_libraries(sioclient_tls PRIVATE OpenSSL::SSL OpenSSL::Crypto)",
  28. format("target_link_libraries(sioclient_tls PRIVATE OpenSSL::SSL OpenSSL::Crypto %s)", syslinks), {plain = true})
  29. end
  30. local configs = {"-DUSE_SUBMODULES=OFF", "-DBUILD_TESTING=OFF"}
  31. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  32. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  33. if package:config("shared") and package:is_plat("windows") then
  34. table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
  35. end
  36. import("package.tools.cmake").install(package, configs)
  37. end)
  38. on_test(function (package)
  39. assert(package:check_cxxsnippets({test = [[
  40. #include <string>
  41. using namespace sio;
  42. using namespace std;
  43. void test() {
  44. socket::ptr current_socket;
  45. current_socket->on("new message", sio::socket::event_listener_aux(
  46. [&](string const& name, message::ptr const& data, bool isAck,message::list &ack_resp)
  47. {
  48. string user = data->get_map()["username"]->get_string();
  49. string message = data->get_map()["message"]->get_string();
  50. }));
  51. }
  52. ]]}, {configs = {languages = "c++11"}, includes = "sio_client.h"}))
  53. end)