xmake.lua 6.7 KB

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