xmake.lua 6.1 KB

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