xmake.lua 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package("libsdl3")
  2. set_homepage("https://www.libsdl.org/")
  3. set_description("Simple DirectMedia Layer")
  4. set_license("zlib")
  5. if is_plat("mingw") and is_subhost("msys") then
  6. add_extsources("pacman::SDL3")
  7. elseif is_plat("linux") then
  8. add_extsources("pacman::sdl3", "apt::libsdl3-dev")
  9. elseif is_plat("macosx") then
  10. add_extsources("brew::sdl3")
  11. end
  12. add_urls("https://www.libsdl.org/release/SDL3-$(version).zip",
  13. "https://github.com/libsdl-org/SDL/releases/download/release-$(version)/SDL3-$(version).zip", { alias = "archive" })
  14. add_urls("https://github.com/libsdl-org/SDL.git", { alias = "github" })
  15. add_versions("archive:3.2.2", "58d8adc7068d38923f918e0bdaa9c4948f93d9ba204fe4de8cc6eaaf77ad6f82")
  16. add_versions("archive:3.2.0", "abe7114fa42edcc8097856787fa5d37f256d97e365b71368b60764fe7c10e4f8")
  17. add_versions("github:3.2.2", "release-3.2.2")
  18. add_versions("github:3.2.0", "release-3.2.0")
  19. add_deps("cmake", "egl-headers", "opengl-headers")
  20. if is_plat("linux", "bsd", "cross") then
  21. add_configs("x11", {description = "Enables X11 support", default = true, type = "boolean"})
  22. add_configs("wayland", {description = "Enables Wayland support", default = nil, type = "boolean"})
  23. end
  24. if is_plat("wasm") then
  25. add_cxflags("-sUSE_SDL=0")
  26. end
  27. on_load(function (package)
  28. if package:is_plat("linux", "android", "cross") then
  29. -- Enable Wayland by default except when cross-compiling (wayland package doesn't support cross-compilation yet)
  30. if package:config("wayland") == nil and not package:is_cross() then
  31. package:config_set("wayland", true)
  32. end
  33. end
  34. if package:is_plat("windows") then
  35. package:add("deps", "ninja")
  36. package:set("policy", "package.cmake_generator.ninja", true)
  37. end
  38. if package:is_plat("linux", "bsd", "cross") and package:config("x11") then
  39. package:add("deps", "libxext", {private = true})
  40. end
  41. if package:is_plat("linux", "bsd", "cross") and package:config("wayland") then
  42. package:add("deps", "wayland", {private = true})
  43. end
  44. local libsuffix = package:is_debug() and "d" or ""
  45. if not package:config("shared") then
  46. if package:is_plat("windows", "mingw") then
  47. package:add("syslinks", "user32", "gdi32", "winmm", "imm32", "ole32", "oleaut32", "version", "uuid", "advapi32", "setupapi", "shell32")
  48. elseif package:is_plat("linux", "bsd") then
  49. package:add("syslinks", "pthread", "dl")
  50. if package:is_plat("bsd") then
  51. package:add("syslinks", "usbhid")
  52. end
  53. elseif package:is_plat("android") then
  54. package:add("syslinks", "dl", "log", "android", "GLESv1_CM", "GLESv2", "OpenSLES")
  55. elseif package:is_plat("iphoneos", "macosx") then
  56. package:add("frameworks", "AudioToolbox", "AVFoundation", "CoreAudio", "CoreHaptics", "CoreMedia", "CoreVideo", "Foundation", "GameController", "Metal", "QuartzCore", "CoreFoundation", "UniformTypeIdentifiers")
  57. package:add("syslinks", "iconv")
  58. if package:is_plat("macosx") then
  59. package:add("frameworks", "Cocoa", "Carbon", "ForceFeedback", "IOKit")
  60. else
  61. package:add("frameworks", "CoreBluetooth", "CoreGraphics", "CoreMotion", "OpenGLES", "UIKit")
  62. end
  63. end
  64. end
  65. end)
  66. on_install(function (package)
  67. local configs = {}
  68. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  69. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  70. table.insert(configs, "-DSDL_TEST_LIBRARY=OFF")
  71. table.insert(configs, "-DSDL_EXAMPLES=OFF")
  72. local cflags
  73. local packagedeps
  74. if not package:is_plat("wasm") then
  75. packagedeps = {"egl-headers", "opengl-headers"}
  76. end
  77. if package:is_plat("linux", "bsd", "cross") then
  78. table.insert(packagedeps, "libxext")
  79. table.insert(packagedeps, "libx11")
  80. table.insert(packagedeps, "xorgproto")
  81. table.insert(packagedeps, "wayland")
  82. elseif package:is_plat("wasm") then
  83. -- emscripten enables USE_SDL by default which will conflict with libsdl headers
  84. cflags = {"-sUSE_SDL=0"}
  85. end
  86. local includedirs = {}
  87. for _, depname in ipairs(packagedeps) do
  88. local dep = package:dep(depname)
  89. if dep then
  90. local depfetch = dep:fetch()
  91. if depfetch then
  92. for _, includedir in ipairs(depfetch.includedirs or depfetch.sysincludedirs) do
  93. table.insert(includedirs, includedir)
  94. end
  95. end
  96. end
  97. end
  98. if #includedirs > 0 then
  99. includedirs = table.unique(includedirs)
  100. table.insert(configs, "-DCMAKE_INCLUDE_PATH=" .. table.concat(includedirs, ";"))
  101. cflags = cflags or {}
  102. for _, includedir in ipairs(includedirs) do
  103. table.insert(cflags, "-I" .. includedir)
  104. end
  105. end
  106. import("package.tools.cmake").install(package, configs, {cflags = cflags})
  107. end)
  108. on_test(function (package)
  109. assert(package:check_cxxsnippets({test = [[
  110. #include <SDL3/SDL.h>
  111. int main(int argc, char** argv) {
  112. SDL_Init(0);
  113. SDL_Quit();
  114. return 0;
  115. }
  116. ]]}));
  117. end)