xmake.lua 13 KB

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