xmake.lua 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package("libsdl_net")
  2. set_homepage("https://www.libsdl.org/projects/SDL_net/")
  3. set_description("Simple DirectMedia Layer networking library")
  4. set_license("zlib")
  5. add_urls("https://www.libsdl.org/projects/SDL_net/release/SDL2_net-$(version).zip",
  6. "https://github.com/libsdl-org/SDL_net/releases/download/release-$(version)/SDL2_net-$(version).zip")
  7. add_versions("2.2.0", "1eec3a9d43df019d7916a6ecce32f2a3ad5248c82c9c237948afc712399be36d")
  8. if is_plat("mingw") and is_subhost("msys") then
  9. add_extsources("pacman::SDL2_net")
  10. elseif is_plat("linux") then
  11. add_extsources("pacman::sdl2_net", "apt::libsdl2-net-dev")
  12. elseif is_plat("macosx") then
  13. add_extsources("brew::sdl2_net")
  14. end
  15. add_deps("cmake")
  16. if is_plat("windows", "mingw") then
  17. add_syslinks("iphlpapi", "ws2_32")
  18. end
  19. if is_plat("wasm") then
  20. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  21. end
  22. add_includedirs("include", "include/SDL2")
  23. on_load(function (package)
  24. if package:config("shared") then
  25. package:add("deps", "libsdl", { configs = { shared = true }})
  26. else
  27. package:add("deps", "libsdl")
  28. end
  29. end)
  30. on_install(function (package)
  31. local configs = {"-DSDL2NET_SAMPLES=OFF"}
  32. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  33. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  34. local libsdl = package:dep("libsdl")
  35. if libsdl and not libsdl:is_system() then
  36. table.insert(configs, "-DSDL2_DIR=" .. libsdl:installdir())
  37. local fetchinfo = libsdl:fetch()
  38. if fetchinfo then
  39. for _, dir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
  40. if os.isfile(path.join(dir, "SDL_version.h")) then
  41. table.insert(configs, "-DSDL2_INCLUDE_DIR=" .. dir)
  42. break
  43. end
  44. end
  45. for _, libfile in ipairs(fetchinfo.libfiles) do
  46. if libfile:match("SDL2%..+$") or libfile:match("SDL2-static%..+$") then
  47. table.insert(configs, "-DSDL2_LIBRARY=" .. table.concat(fetchinfo.libfiles, ";"))
  48. end
  49. end
  50. end
  51. end
  52. io.replace("CMakeLists.txt", "find_package(SDL2test)", "", {plain = true})
  53. import("package.tools.cmake").install(package, configs)
  54. end)
  55. on_test(function (package)
  56. assert(package:check_cxxsnippets({test = [[
  57. #include <SDL2/SDL.h>
  58. #include <SDL2/SDL_net.h>
  59. int main(int argc, char** argv) {
  60. SDLNet_Init();
  61. SDLNet_Quit();
  62. return 0;
  63. }
  64. ]]}, {configs = {defines = "SDL_MAIN_HANDLED"}}));
  65. end)