xmake.lua 6.4 KB

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