xmake.lua 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. if is_plat("macosx", "iphoneos") then
  18. add_frameworks("CoreFoundation", "CoreGraphics", "ImageIO", "CoreServices")
  19. elseif is_plat("wasm") then
  20. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  21. end
  22. add_deps("cmake")
  23. add_includedirs("include", "include/SDL2")
  24. on_load(function (package)
  25. if package:config("shared") then
  26. package:add("deps", "libsdl", { configs = { shared = true }})
  27. else
  28. package:add("deps", "libsdl")
  29. end
  30. end)
  31. on_install(function (package)
  32. local configs = {"-DSDL2IMAGE_SAMPLES=OFF", "-DSDL2IMAGE_TESTS=OFF"}
  33. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  34. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  35. local libsdl = package:dep("libsdl")
  36. if libsdl and not libsdl:is_system() then
  37. table.insert(configs, "-DSDL2_DIR=" .. libsdl:installdir())
  38. local fetchinfo = libsdl:fetch()
  39. if fetchinfo then
  40. for _, dir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
  41. if os.isfile(path.join(dir, "SDL_version.h")) then
  42. table.insert(configs, "-DSDL2_INCLUDE_DIR=" .. dir)
  43. break
  44. end
  45. end
  46. for _, libfile in ipairs(fetchinfo.libfiles) do
  47. if libfile:match("SDL2%..+$") or libfile:match("SDL2-static%..+$") then
  48. table.insert(configs, "-DSDL2_LIBRARY=" .. table.concat(fetchinfo.libfiles, ";"))
  49. end
  50. end
  51. end
  52. end
  53. import("package.tools.cmake").install(package, configs)
  54. end)
  55. on_test(function (package)
  56. assert(package:has_cfuncs("IMG_Init", {includes = "SDL2/SDL_image.h", configs = {defines = "SDL_MAIN_HANDLED"}}))
  57. end)