xmake.lua 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package("libsdl_image")
  2. set_homepage("http://www.libsdl.org/projects/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.6.0", "2252cdfd5be73cefaf727edc39c2ef3b7682e797acbd3126df117e925d46aaf6")
  15. add_versions("2.6.1", "cbfea63a46715c63a1db9e41617e550749a95ffd33ef9bd5ba6e58b2bdca6ed3")
  16. add_versions("2.6.2", "efe3c229853d0d40c35e5a34c3f532d5d9728f0abc623bc62c962bcef8754205")
  17. add_versions("2.6.3", "b448a8ca5b7927d9bd1577d393f4d6c59581f87ee525652a27e699941db37b7c")
  18. add_versions("2.8.0", "fed33c3fe9f8d38ab4460bdd100c4495be40f8afdac1d44bfcd2b0259b74a123")
  19. add_versions("2.8.1", "0c5afef0ac4bc951a46c6790e576c9b3e7ed2c5ab1d2bbfa5e7e9300718f67d2")
  20. add_versions("2.8.2", "2196ad6665b68fc453a659e172d67fbf18d548277aa07344dfd2deed9d9b84bd")
  21. if is_plat("macosx", "iphoneos") then
  22. add_frameworks("CoreFoundation", "CoreGraphics", "ImageIO", "CoreServices")
  23. elseif is_plat("wasm") then
  24. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  25. end
  26. add_deps("cmake")
  27. add_includedirs("include", "include/SDL2")
  28. on_load(function (package)
  29. if package:config("shared") then
  30. package:add("deps", "libsdl", { configs = { shared = true }})
  31. else
  32. package:add("deps", "libsdl")
  33. end
  34. end)
  35. on_install(function (package)
  36. local configs = {"-DSDL2IMAGE_SAMPLES=OFF", "-DSDL2IMAGE_TESTS=OFF"}
  37. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  38. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  39. local libsdl = package:dep("libsdl")
  40. if libsdl and not libsdl:is_system() then
  41. table.insert(configs, "-DSDL2_DIR=" .. libsdl:installdir())
  42. local fetchinfo = libsdl:fetch()
  43. if fetchinfo then
  44. for _, dir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
  45. if os.isfile(path.join(dir, "SDL_version.h")) then
  46. table.insert(configs, "-DSDL2_INCLUDE_DIR=" .. dir)
  47. break
  48. end
  49. end
  50. for _, libfile in ipairs(fetchinfo.libfiles) do
  51. if libfile:match("SDL2%..+$") or libfile:match("SDL2-static%..+$") then
  52. table.insert(configs, "-DSDL2_LIBRARY=" .. table.concat(fetchinfo.libfiles, ";"))
  53. end
  54. end
  55. end
  56. end
  57. import("package.tools.cmake").install(package, configs)
  58. end)
  59. on_test(function (package)
  60. assert(package:check_cxxsnippets({test = [[
  61. #include <SDL2/SDL.h>
  62. #include <SDL2/SDL_image.h>
  63. int main(int argc, char** argv) {
  64. IMG_Init(IMG_INIT_PNG);
  65. IMG_Quit();
  66. return 0;
  67. }
  68. ]]}, {configs = {defines = "SDL_MAIN_HANDLED"}}));
  69. end)