xmake.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. package("sfml")
  2. set_homepage("https://www.sfml-dev.org")
  3. set_description("Simple and Fast Multimedia Library")
  4. set_license("zlib")
  5. add_urls("https://github.com/SFML/SFML/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/SFML/SFML.git")
  7. -- Before 2.6.0 only x86 is supported for Mac
  8. if not is_plat("macosx") or not is_arch("arm.*") then
  9. add_versions("2.5.1", "438c91a917cc8aa19e82c6f59f8714da353c488584a007d401efac8368e1c785")
  10. end
  11. add_versions("2.6.0", "0c3f84898ea1db07dc46fa92e85038d8c449e3c8653fe09997383173de96bc06")
  12. add_configs("graphics", {description = "Use the graphics module", default = true, type = "boolean"})
  13. add_configs("window", {description = "Use the window module", default = true, type = "boolean"})
  14. add_configs("audio", {description = "Use the audio module", default = true, type = "boolean"})
  15. add_configs("network", {description = "Use the network module", default = true, type = "boolean"})
  16. if is_plat("windows", "mingw") then
  17. add_configs("main", {description = "Link to the sfml-main library", default = true, type = "boolean"})
  18. end
  19. if is_plat("macosx") then
  20. add_extsources("brew::sfml/sfml-all")
  21. end
  22. on_component("graphics", function (package, component)
  23. local e = package:config("shared") and "" or "-s"
  24. if package:debug() then
  25. e = e .. "-d"
  26. end
  27. component:add("links", "sfml-graphics" .. e)
  28. component:add("deps", "window", "system")
  29. component:add("extsources", "brew::sfml/sfml-graphics")
  30. end)
  31. on_component("window", function (package, component)
  32. local e = package:config("shared") and "" or "-s"
  33. if package:debug() then
  34. e = e .. "-d"
  35. end
  36. component:add("links", "sfml-window" .. e)
  37. component:add("deps", "system")
  38. component:add("extsources", "brew::sfml/sfml-window")
  39. if not package:config("shared") then
  40. if package:is_plat("windows", "mingw") then
  41. component:add("syslinks", "opengl32", "gdi32", "advapi32", "user32")
  42. elseif package:is_plat("linux") then
  43. component:add("syslinks", "dl")
  44. elseif package:is_plat("bsd") then
  45. component:add("syslinks", "usbhid")
  46. elseif package:is_plat("macosx") then
  47. component:add("frameworks", "Foundation", "AppKit", "IOKit", "Carbon")
  48. elseif package:is_plat("iphoneos") then
  49. component:add("frameworks", "Foundation", "UIKit", "CoreGraphics", "QuartzCore", "CoreMotion")
  50. end
  51. end
  52. end)
  53. on_component("audio", function (package, component)
  54. local e = package:config("shared") and "" or "-s"
  55. if package:debug() then
  56. e = e .. "-d"
  57. end
  58. component:add("links", "sfml-audio" .. e)
  59. component:add("deps", "system")
  60. component:add("extsources", "brew::sfml/sfml-audio")
  61. if not package:config("shared") and package:is_plat("windows", "mingw") then
  62. component:add("links", "openal32", "flac", "vorbisenc", "vorbisfile", "vorbis", "ogg")
  63. end
  64. end)
  65. on_component("network", function (package, component)
  66. local e = package:config("shared") and "" or "-s"
  67. if package:debug() then
  68. e = e .. "-d"
  69. end
  70. component:add("links", "sfml-network" .. e)
  71. component:add("deps", "system")
  72. component:add("extsources", "brew::sfml/sfml-network")
  73. component:add("extsources", "apt::sfml-network")
  74. if not package:config("shared") and package:is_plat("windows", "mingw") then
  75. component:add("syslinks", "ws2_32")
  76. end
  77. end)
  78. on_component("system", function (package, component)
  79. local e = package:config("shared") and "" or "-s"
  80. if package:debug() then
  81. e = e .. "-d"
  82. end
  83. component:add("links", "sfml-system" .. e)
  84. if package:is_plat("windows", "mingw") then
  85. component:add("syslinks", "winmm")
  86. end
  87. if package:is_plat("windows", "mingw") and package:config("main") then
  88. component:add("deps", "main")
  89. end
  90. component:add("extsources", "brew::sfml/sfml-system")
  91. if not package:config("shared") then
  92. if package:is_plat("windows", "mingw") then
  93. component:add("syslinks", "winmm")
  94. elseif package:is_plat("linux") then
  95. component:add("syslinks", "rt", "pthread")
  96. elseif package:is_plat("bsd", "macosx") then
  97. component:add("syslinks", "pthread")
  98. end
  99. end
  100. end)
  101. on_component("main", function (package, component)
  102. if package:is_plat("windows", "mingw") then
  103. local main_module = "sfml-main"
  104. if package:debug() then
  105. main_module = main_module .. "-d"
  106. end
  107. component:add("links", main_module)
  108. end
  109. end)
  110. on_load("windows", "linux", "macosx", "mingw", function (package)
  111. if package:is_plat("windows", "linux", "macosx") then
  112. package:add("deps", "cmake")
  113. end
  114. if not package:config("shared") then
  115. package:add("defines", "SFML_STATIC")
  116. end
  117. if package:config("graphics") then
  118. package:add("deps", "freetype")
  119. end
  120. if package:is_plat("linux") then
  121. if package:config("window") or package:config("graphics") then
  122. package:add("deps", "libx11", "libxcursor", "libxrandr", "libxrender", "libxfixes", "libxext", "eudev")
  123. package:add("deps", "opengl", "glx", {optional = true})
  124. end
  125. end
  126. if package:config("audio") then
  127. package:add("deps", "libogg", "libflac", "libvorbis", "openal-soft")
  128. end
  129. package:add("components", "system")
  130. for _, component in ipairs({"graphics", "window", "audio", "network"}) do
  131. if package:config(component) then
  132. package:add("components", component)
  133. end
  134. end
  135. if package:is_plat("windows", "mingw") and package:config("main") then
  136. package:add("components", "main")
  137. end
  138. end)
  139. on_install("windows", "linux", "macosx", "mingw", function (package)
  140. local configs = {"-DSFML_BUILD_DOC=OFF", "-DSFML_BUILD_EXAMPLES=OFF"}
  141. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  142. if package:config("shared") then
  143. table.insert(configs, "-DBUILD_SHARED_LIBS=ON")
  144. -- Fix missing system libs
  145. if package:config("audio") then
  146. if package:is_plat("windows", "mingw") then
  147. local file = io.open("src/SFML/Audio/CMakeLists.txt", "a")
  148. file:print("target_link_libraries(OpenAL INTERFACE winmm)")
  149. file:close()
  150. end
  151. end
  152. if package:config("graphics") then
  153. local freetype = package:dep("freetype")
  154. if freetype then
  155. local fetchinfo = freetype:fetch()
  156. if fetchinfo then
  157. if not freetype:config("shared") then
  158. local libfiles = {}
  159. for _, dep in ipairs(freetype:librarydeps()) do
  160. local depinfo = dep:fetch()
  161. if depinfo then
  162. table.join2(libfiles, depinfo.libfiles)
  163. end
  164. end
  165. if #libfiles > 0 then
  166. local libraries = {}
  167. for _, libfile in ipairs(libfiles) do
  168. table.insert(libraries, (libfile:gsub("\\", "/")))
  169. end
  170. local file = io.open("src/SFML/Graphics/CMakeLists.txt", "a")
  171. file:print("target_link_libraries(Freetype INTERFACE " .. table.concat(libraries, " ") .. ")")
  172. file:close()
  173. end
  174. end
  175. end
  176. end
  177. end
  178. if package:config("window") and package:is_plat("linux") then
  179. local libfiles = {}
  180. for _, name in ipairs({"libx11", "libxcursor", "libxrandr", "libxrender", "libxfixes", "libxext"}) do
  181. local dep = package:dep(name)
  182. if dep then
  183. local fetchinfo = dep:fetch()
  184. if fetchinfo then
  185. table.join2(libfiles, fetchinfo.libfiles)
  186. end
  187. end
  188. end
  189. if #libfiles > 0 then
  190. libfiles = table.reverse_unique(libfiles)
  191. local libraries = {}
  192. for _, libfile in ipairs(libfiles) do
  193. table.insert(libraries, (libfile:gsub("\\", "/")))
  194. end
  195. local file = io.open("src/SFML/Window/CMakeLists.txt", "a")
  196. file:print("target_link_libraries(sfml-window PRIVATE " .. table.concat(libraries, " ") .. ")")
  197. file:close()
  198. end
  199. end
  200. else
  201. table.insert(configs, "-DBUILD_SHARED_LIBS=OFF")
  202. if package:is_plat("windows") and package:config("vs_runtime"):startswith("MT") then
  203. table.insert(configs, "-DSFML_USE_STATIC_STD_LIBS=ON")
  204. end
  205. end
  206. table.insert(configs, "-DSFML_BUILD_AUDIO=" .. (package:config("audio") and "ON" or "OFF"))
  207. table.insert(configs, "-DSFML_BUILD_GRAPHICS=" .. (package:config("graphics") and "ON" or "OFF"))
  208. table.insert(configs, "-DSFML_BUILD_WINDOW=" .. (package:config("window") and "ON" or "OFF"))
  209. table.insert(configs, "-DSFML_BUILD_NETWORK=" .. (package:config("network") and "ON" or "OFF"))
  210. table.insert(configs, "-DWARNINGS_AS_ERRORS=OFF")
  211. table.insert(configs, "-DSFML_USE_SYSTEM_DEPS=TRUE")
  212. local packagedeps
  213. if package:config("audio") then
  214. packagedeps = packagedeps or {}
  215. table.insert(packagedeps, "openal-soft")
  216. end
  217. if package:config("graphics") then
  218. packagedeps = packagedeps or {}
  219. table.insert(packagedeps, "freetype")
  220. table.insert(packagedeps, "zlib")
  221. end
  222. import("package.tools.cmake").install(package, configs, {packagedeps = packagedeps})
  223. end)
  224. on_test(function (package)
  225. assert(package:check_cxxsnippets({test = [[
  226. void test(int args, char** argv) {
  227. sf::Clock c;
  228. c.restart();
  229. }
  230. ]]}, {includes = "SFML/System.hpp"}))
  231. if package:config("graphics") then
  232. assert(package:check_cxxsnippets({test = [[
  233. void test(int args, char** argv) {
  234. sf::Text text;
  235. text.setString("Hello world");
  236. }
  237. ]]}, {includes = "SFML/Graphics.hpp"}))
  238. end
  239. if package:config("window") or package:config("graphics") then
  240. assert(package:check_cxxsnippets({test = [[
  241. void test(int args, char** argv) {
  242. sf::Window window(sf::VideoMode(1280, 720), "Title");
  243. sf::Event event;
  244. window.pollEvent(event);
  245. }
  246. ]]}, {includes = "SFML/Window.hpp"}))
  247. end
  248. if package:config("audio") then
  249. assert(package:check_cxxsnippets({test = [[
  250. void test(int args, char** argv) {
  251. sf::Music music;
  252. music.openFromFile("music.ogg");
  253. music.play();
  254. }
  255. ]]}, {includes = "SFML/Audio.hpp"}))
  256. end
  257. if package:config("network") then
  258. assert(package:check_cxxsnippets({test = [[
  259. void test(int args, char** argv) {
  260. sf::UdpSocket socket;
  261. socket.bind(54000);
  262. char data[100];
  263. std::size_t received;
  264. sf::IpAddress sender;
  265. unsigned short port;
  266. socket.receive(data, 100, received, sender, port);
  267. }
  268. ]]}, {includes = "SFML/Network.hpp"}))
  269. end
  270. end)