xmake.lua 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package("enet")
  2. set_homepage("http://enet.bespin.org")
  3. set_description("Reliable UDP networking library.")
  4. set_license("MIT")
  5. add_urls("https://github.com/lsalzman/enet/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/lsalzman/enet.git")
  7. add_versions("v1.3.17", "1e0b4bc0b7127a2d779dd7928f0b31830f5b3dcb7ec9588c5de70033e8d2434a")
  8. add_patches("v1.3.17", path.join(os.scriptdir(), "patches", "cmake.patch"), "e77d2d129952443d67c1ec432de81843d72b854d25bbd6fb244b0f85804d21d1")
  9. if is_plat("mingw") and is_subhost("msys") then
  10. add_extsources("pacman::enet")
  11. elseif is_plat("linux") then
  12. add_extsources("pacman::enet", "apt::libenet-dev")
  13. elseif is_plat("macosx") then
  14. add_extsources("brew::enet")
  15. end
  16. add_deps("cmake")
  17. if is_plat("windows", "mingw") then
  18. add_syslinks("winmm", "ws2_32")
  19. end
  20. on_load("windows", "mingw", function (package)
  21. if package:config("shared") then
  22. package:add("defines", "ENET_DLL")
  23. end
  24. end)
  25. on_install(function (package)
  26. local configs = {}
  27. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  28. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  29. import("package.tools.cmake").install(package, configs)
  30. end)
  31. on_test(function (package)
  32. assert(package:check_cxxsnippets({test = [[
  33. void test()
  34. {
  35. if (enet_initialize () != 0)
  36. return;
  37. ENetAddress address;
  38. ENetHost* server;
  39. address.host = ENET_HOST_ANY;
  40. address.port = 1234;
  41. server = enet_host_create (&address, 32, 2, 0, 0);
  42. if (server == NULL)
  43. return;
  44. ENetEvent event;
  45. while (enet_host_service (server, &event, 1000) > 0);
  46. enet_host_destroy(server);
  47. enet_deinitialize();
  48. }
  49. ]]}, {includes = {"enet/enet.h"}}))
  50. end)