2
0

xmake.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package("libsdl2_image")
  2. set_homepage("https://github.com/libsdl-org/SDL_image")
  3. set_description("Simple DirectMedia Layer image loading library")
  4. set_license("zlib")
  5. if is_plat("mingw") and is_subhost("msys") then
  6. add_extsources("pacman::SDL2_image")
  7. elseif is_plat("linux") then
  8. add_extsources("pacman::sdl2_image", "apt::libsdl2-image-dev")
  9. elseif is_plat("macosx") then
  10. add_extsources("brew::sdl2_image")
  11. end
  12. add_urls("https://www.libsdl.org/projects/SDL_image/release/SDL2_image-$(version).zip",
  13. "https://github.com/libsdl-org/SDL_image/releases/download/release-$(version)/SDL2_image-$(version).zip")
  14. add_versions("2.8.8", "def4c7cba37a2f2cce83cfeff053220b2e1481c3c00d59638b1c526ae58545ac")
  15. add_versions("2.8.5", "1ad911966aabf194a8a5e5744f5e67de2b61cc6e2c399de0abb80e05ce526b2c")
  16. add_versions("2.8.4", "a99a906b23d13707df63bc02b7b6a2911282ff82f0f0bd72eaad7a6e53bd1f63")
  17. add_versions("2.8.3", "3d24c5a2b29813d515d4e37a9703bc3ae849963d1dc09e1ad6b46e1b4a6bb3c1")
  18. add_versions("2.6.0", "2252cdfd5be73cefaf727edc39c2ef3b7682e797acbd3126df117e925d46aaf6")
  19. add_versions("2.6.1", "cbfea63a46715c63a1db9e41617e550749a95ffd33ef9bd5ba6e58b2bdca6ed3")
  20. add_versions("2.6.2", "efe3c229853d0d40c35e5a34c3f532d5d9728f0abc623bc62c962bcef8754205")
  21. add_versions("2.6.3", "b448a8ca5b7927d9bd1577d393f4d6c59581f87ee525652a27e699941db37b7c")
  22. add_versions("2.8.0", "fed33c3fe9f8d38ab4460bdd100c4495be40f8afdac1d44bfcd2b0259b74a123")
  23. add_versions("2.8.1", "0c5afef0ac4bc951a46c6790e576c9b3e7ed2c5ab1d2bbfa5e7e9300718f67d2")
  24. add_versions("2.8.2", "2196ad6665b68fc453a659e172d67fbf18d548277aa07344dfd2deed9d9b84bd")
  25. if is_plat("macosx", "iphoneos") then
  26. add_frameworks("CoreFoundation", "CoreGraphics", "ImageIO", "CoreServices")
  27. elseif is_plat("wasm") then
  28. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  29. end
  30. add_deps("cmake")
  31. add_includedirs("include", "include/SDL2")
  32. on_load(function (package)
  33. package:add("deps", "libsdl2", { configs = { shared = package:config("shared") }})
  34. end)
  35. on_install(function (package)
  36. if package:is_plat("wasm") then
  37. io.replace("CMakeLists.txt", "sdl_find_sdl2(${sdl2_target_name} ${SDL_REQUIRED_VERSION})", "", {plain = true})
  38. io.replace("CMakeLists.txt", "target_link_libraries(SDL2_image PRIVATE $<BUILD_INTERFACE:${sdl2_target_name}>)", [[
  39. target_include_directories(SDL2_image PRIVATE ${SDL2_INCLUDE_DIR})
  40. target_link_libraries(SDL2_image PRIVATE $<BUILD_INTERFACE:${SDL2_LIBRARY}>)
  41. ]], {plain = true})
  42. io.replace("CMakeLists.txt", "target_link_libraries(SDL2_image PRIVATE ${sdl2_target_name})", [[
  43. target_include_directories(SDL2_image PRIVATE ${SDL2_INCLUDE_DIR})
  44. target_link_libraries(SDL2_image PRIVATE ${SDL2_LIBRARY})
  45. ]], {plain = true})
  46. end
  47. local configs = {"-DSDL2IMAGE_SAMPLES=OFF", "-DSDL2IMAGE_TESTS=OFF", "-DSDL2IMAGE_VENDORED=OFF"}
  48. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  49. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  50. local libsdl2 = package:dep("libsdl2")
  51. if libsdl2 and not libsdl2:is_system() then
  52. table.insert(configs, "-DSDL2_DIR=" .. libsdl2:installdir())
  53. local fetchinfo = libsdl2:fetch()
  54. if fetchinfo then
  55. for _, dir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
  56. if os.isfile(path.join(dir, "SDL_version.h")) then
  57. table.insert(configs, "-DSDL2_INCLUDE_DIR=" .. dir)
  58. break
  59. end
  60. end
  61. local libfiles = {}
  62. for _, libfile in ipairs(fetchinfo.libfiles) do
  63. if libfile:match("SDL2%..+$") or libfile:match("SDL2-static%..+$") then
  64. if not (package:config("shared") and libfile:endswith(".dll")) then
  65. table.insert(libfiles, libfile)
  66. end
  67. end
  68. end
  69. table.insert(configs, "-DSDL2_LIBRARY=" .. table.concat(libfiles, ";"))
  70. end
  71. end
  72. import("package.tools.cmake").install(package, configs)
  73. end)
  74. on_test(function (package)
  75. assert(package:check_cxxsnippets({test = [[
  76. #include <SDL2/SDL.h>
  77. #include <SDL2/SDL_image.h>
  78. int main(int argc, char** argv) {
  79. IMG_Init(IMG_INIT_PNG);
  80. IMG_Quit();
  81. return 0;
  82. }
  83. ]]}, {configs = {defines = "SDL_MAIN_HANDLED"}}));
  84. end)