xmake.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package("sfml")
  2. set_homepage("https://www.sfml-dev.org")
  3. set_description("Simple and Fast Multimedia Library")
  4. if is_plat("windows", "linux") then
  5. set_urls("https://www.sfml-dev.org/files/SFML-$(version)-sources.zip")
  6. add_urls("https://github.com/SFML/SFML/releases/download/$(version)/SFML-$(version)-sources.zip")
  7. add_versions("2.5.1", "bf1e0643acb92369b24572b703473af60bac82caf5af61e77c063b779471bb7f")
  8. elseif is_plat("macosx") then
  9. if is_arch("x64", "x86_64") then
  10. set_urls("https://www.sfml-dev.org/files/SFML-$(version)-macOS-clang.tar.gz")
  11. add_versions("2.5.1", "6af0f14fbd41dc038a00d7709f26fb66bb7ccdfe6187657ef0ef8cba578dcf14")
  12. add_configs("debug", {builtin = true, description = "Enable debug symbols.", default = false, type = "boolean", readonly = true})
  13. add_configs("shared", {description = "Build shared library.", default = true, type = "boolean", readonly = true})
  14. end
  15. elseif is_plat("mingw") then
  16. if is_arch("x64", "x86_64") then
  17. set_urls("https://www.sfml-dev.org/files/SFML-$(version)-windows-gcc-7.3.0-mingw-64-bit.zip")
  18. add_versions("2.5.1", "671e786f1af934c488cb22c634251c8c8bd441c709b4ef7bc6bbe227b2a28560")
  19. elseif is_arch("x86", "i386") then
  20. set_urls("https://www.sfml-dev.org/files/SFML-$(version)-windows-gcc-7.3.0-mingw-32-bit.zip")
  21. add_versions("2.5.1", "92d864c9c9094dc9d91e0006d66784f25ac900a8ee23c3f79db626de46a1d9d8")
  22. end
  23. end
  24. if is_plat("linux") then
  25. add_syslinks("pthread")
  26. end
  27. add_configs("graphics", {description = "Use the graphics module", default = true, type = "boolean"})
  28. add_configs("window", {description = "Use the window module", default = true, type = "boolean"})
  29. add_configs("audio", {description = "Use the audio module", default = true, type = "boolean"})
  30. add_configs("network", {description = "Use the network module", default = true, type = "boolean"})
  31. if is_plat("windows", "mingw") then
  32. add_configs("main", {description = "Link to the sfml-main library", default = true, type = "boolean"})
  33. end
  34. on_load("windows", "linux", "macosx", "mingw", function (package)
  35. if package:is_plat("windows", "linux") then
  36. package:add("deps", "cmake")
  37. end
  38. if not package:config("shared") then
  39. package:add("defines", "SFML_STATIC")
  40. end
  41. local e = ""
  42. local a = "sfml-"
  43. if not package:config("shared") then
  44. e = "-s"
  45. end
  46. if package:debug() then
  47. e = e .. "-d"
  48. end
  49. local main_module = a .. "main"
  50. if package:debug() then
  51. main_module = main_module .. "-d"
  52. end
  53. if package:config("graphics") then
  54. package:add("links", a .. "graphics" .. e)
  55. if package:is_plat("mingw") then
  56. package:add("links", "freetype")
  57. end
  58. end
  59. if package:config("window") or package:config("graphics") then
  60. package:add("links", a .. "window" .. e)
  61. if package:is_plat("windows", "mingw") then
  62. package:add("syslinks", "opengl32", "gdi32", "user32", "advapi32")
  63. end
  64. if package:is_plat("linux") then
  65. package:add("deps", "libx11", "libxrandr", "freetype", "eudev")
  66. package:add("deps", "opengl", "glx", {optional = true})
  67. end
  68. end
  69. if package:config("audio") then
  70. package:add("links", a .. "audio" .. e)
  71. if package:is_plat("mingw") then
  72. package:add("links", "openal32", "flac", "vorbisenc", "vorbisfile", "vorbis", "ogg")
  73. elseif package:is_plat("linux") then
  74. package:add("deps", "libogg", "libflac", "libvorbis", "openal-soft")
  75. end
  76. end
  77. if package:config("network") then
  78. package:add("links", a .. "network" .. e)
  79. if package:is_plat("windows", "mingw") then
  80. package:add("syslinks", "ws2_32")
  81. end
  82. end
  83. if package:is_plat("windows", "mingw") and package:config("main") then
  84. package:add("links", main_module)
  85. end
  86. package:add("links", a .. "system" .. e)
  87. if package:is_plat("windows", "mingw") then
  88. package:add("syslinks", "winmm")
  89. end
  90. end)
  91. on_install("windows", "linux", function (package)
  92. local configs = {"-DSFML_BUILD_DOC=OFF", "-DSFML_BUILD_EXAMPLES=OFF"}
  93. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  94. if package:config("shared") then
  95. table.insert(configs, "-DBUILD_SHARED_LIBS=ON")
  96. else
  97. table.insert(configs, "-DBUILD_SHARED_LIBS=OFF")
  98. if package:is_plat("windows") and package:config("vs_runtime"):startswith("MT") then
  99. table.insert(configs, "-DSFML_USE_STATIC_STD_LIBS=ON")
  100. end
  101. end
  102. table.insert(configs, "-DSFML_BUILD_AUDIO=" .. (package:config("audio") and "ON" or "OFF"))
  103. table.insert(configs, "-DSFML_BUILD_GRAPHICS=" .. (package:config("graphics") and "ON" or "OFF"))
  104. table.insert(configs, "-DSFML_BUILD_WINDOW=" .. (package:config("window") and "ON" or "OFF"))
  105. table.insert(configs, "-DSFML_BUILD_NETWORK=" .. (package:config("network") and "ON" or "OFF"))
  106. import("package.tools.cmake").install(package, configs)
  107. end)
  108. on_install("macosx", "mingw", function (package)
  109. os.cp("lib", package:installdir())
  110. os.cp("include", package:installdir())
  111. if package:is_plat("mingw") then
  112. os.cp("bin/*", package:installdir("lib"), {rootdir = "bin"})
  113. end
  114. end)
  115. on_test(function (package)
  116. assert(package:check_cxxsnippets({test = [[
  117. void test(int args, char** argv) {
  118. sf::Clock c;
  119. c.restart();
  120. }
  121. ]]}, {includes = "SFML/System.hpp"}))
  122. end)