xmake.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package("csfml")
  2. set_homepage("https://www.sfml-dev.org")
  3. set_description("Official binding of SFML for C")
  4. set_license("zlib")
  5. add_urls("https://github.com/SFML/CSFML/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/SFML/CSFML.git")
  7. add_versions("3.0.0", "903cd4a782fb0b233f732dc5b37861b552998e93ae8f268c40bd4ce50b2e88ca")
  8. add_versions("2.6.1", "f3f3980f6b5cad85b40e3130c10a2ffaaa9e36de5f756afd4aacaed98a7a9b7b")
  9. add_configs("graphics", {description = "Use the graphics module", default = true, type = "boolean"})
  10. add_configs("window", {description = "Use the window module", default = true, type = "boolean"})
  11. add_configs("audio", {description = "Use the audio module", default = true, type = "boolean"})
  12. add_configs("network", {description = "Use the network module", default = true, type = "boolean"})
  13. add_deps("cmake")
  14. if is_plat("windows", "mingw") then
  15. add_syslinks("avrt")
  16. end
  17. on_load(function (package)
  18. if package:version():ge("3.0.0") then
  19. if not package:config("shared") then
  20. package:add("defines", "CSFML_STATIC")
  21. end
  22. package:add("deps", "sfml " .. package:version(), {configs = {
  23. graphics = package:config("graphics"),
  24. window = package:config("window"),
  25. audio = package:config("audio"),
  26. network = package:config("network")
  27. }})
  28. else
  29. if package:version():ge("2.6.0") and package:version():le("2.6.1") then
  30. package:add("deps", "sfml " .. package:version(), {configs = {
  31. graphics = package:config("graphics"),
  32. window = package:config("window"),
  33. audio = package:config("audio"),
  34. network = package:config("network")
  35. }})
  36. end
  37. end
  38. if package:config("graphics") then
  39. package:add("deps", "zlib")
  40. end
  41. end)
  42. on_install("windows", "linux", "macosx", "mingw@windows,msys", function (package)
  43. if package:version():lt("3.0.0") then
  44. -- Mac OS X do not use BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "@rpath"
  45. io.replace("cmake/Macros.cmake", "if(SFML_OS_MACOSX AND BUILD_SHARED_LIBS)", "if(0)", {plain = true})
  46. if package:is_plat("windows", "mingw") then
  47. if not package:config("shared") then
  48. if package:is_plat("windows") then
  49. io.replace("include/SFML/Config.h",
  50. [[#define CSFML_API_IMPORT CSFML_EXTERN_C __declspec(dllimport)]],
  51. [[#define CSFML_API_IMPORT CSFML_EXTERN_C __declspec(dllexport)]], {plain = true})
  52. end
  53. if package:is_plat("mingw") then
  54. io.replace("cmake/Macros.cmake", [[if (SFML_OS_WINDOWS AND SFML_COMPILER_GCC)]], [[if(0)]], {plain = true})
  55. io.replace("include/SFML/Config.h",
  56. [[#define CSFML_API_IMPORT CSFML_EXTERN_C __declspec(dllimport)]],
  57. [[#define CSFML_API_IMPORT CSFML_EXTERN_C]], {plain = true})
  58. end
  59. -- Do not use CMAKE_SHARED_LIBRARY_SUFFIX when building static lib
  60. io.replace("cmake/Macros.cmake", "if(SFML_OS_WINDOWS)", "if(0)", {plain = true})
  61. end
  62. -- Add missing syslink
  63. io.replace("src/SFML/Audio/CMakeLists.txt", "DEPENDS sfml-audio)", "DEPENDS sfml-audio avrt)", {plain = true})
  64. end
  65. -- Add missing zlib headers
  66. if package:config("graphics") then
  67. io.replace("src/SFML/CMakeLists.txt",
  68. [[find_package(SFML 2.6 COMPONENTS ${SFML_MODULES} REQUIRED)]],
  69. [[find_package(SFML 2.6 COMPONENTS ${SFML_MODULES} REQUIRED)
  70. find_package(ZLIB)]], {plain = true})
  71. io.replace("src/SFML/Graphics/CMakeLists.txt",
  72. "DEPENDS sfml-graphics)", [[DEPENDS sfml-graphics ZLIB::ZLIB)]], {plain = true})
  73. end
  74. end
  75. local configs = {"-DCSFML_BUILD_EXAMPLES=OFF", "-DCSFML_BUILD_DOC=OFF"}
  76. table.insert(configs, "-DCSFML_BUILD_GRAPHICS=".. (package:config("graphics") and "ON" or "OFF"))
  77. table.insert(configs, "-DCSFML_BUILD_WINDOW=".. (package:config("window") and "ON" or "OFF"))
  78. table.insert(configs, "-DCSFML_BUILD_AUDIO=".. (package:config("audio") and "ON" or "OFF"))
  79. table.insert(configs, "-DCSFML_BUILD_NETWORK=".. (package:config("network") and "ON" or "OFF"))
  80. -- If dependency SFML is static or shared
  81. local sfml = package:dep("sfml")
  82. if sfml then
  83. table.insert(configs, "-DSFML_ROOT=" .. sfml:installdir())
  84. table.insert(configs, "-DCSFML_LINK_SFML_STATICALLY=" .. (sfml:config("shared") and "OFF" or "ON"))
  85. end
  86. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  87. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  88. import("package.tools.cmake").install(package, configs, {packagedeps = "zlib"})
  89. end)
  90. on_test(function (package)
  91. local includedir = package:version():ge("3.0.0") and "CSFML" or "SFML"
  92. if package:config("graphics") then
  93. assert(package:has_cfuncs("sfImage_create", {includes = includedir .. "/Graphics.h"}))
  94. end
  95. if package:config("window") then
  96. assert(package:has_cfuncs("sfWindow_create", {includes = includedir .. "/Window.h"}))
  97. end
  98. if package:config("audio") then
  99. assert(package:has_cfuncs("sfMusic_createFromMemory", {includes = includedir .. "/Audio.h"}))
  100. end
  101. if package:config("network") then
  102. assert(package:has_cfuncs("sfTcpSocket_create", {includes = includedir .. "/Network.h"}))
  103. end
  104. end)