xmake.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package("libsdl_mixer")
  2. set_homepage("https://www.libsdl.org/projects/SDL_mixer/")
  3. set_description("Simple DirectMedia Layer mixer audio library")
  4. set_license("zlib")
  5. add_urls("https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-$(version).zip",
  6. "https://github.com/libsdl-org/SDL_mixer/releases/download/release-$(version)/SDL2_mixer-$(version).zip")
  7. add_versions("2.0.4", "9affb8c7bf6fbffda0f6906bfb99c0ea50dca9b188ba9e15be90042dc03c5ded")
  8. add_versions("2.6.0", "aca0ffc96a4bf2a56a16536a269de28e341ce38a46a25180bc1ef75e19b08a3a")
  9. add_versions("2.6.1", "788c748c1d3a87126511e60995b03526ed4e31e2ba053dffd9dcc8abde97b950")
  10. add_versions("2.6.2", "61549615a67e731805ca1df553e005be966a625c1d20fb085bf99edeef6e0469")
  11. add_versions("2.8.0", "02df784cc68723419dd266530ee6964f810a6f02a27b03ecc85689c2e5e442ce")
  12. if is_plat("mingw") and is_subhost("msys") then
  13. add_extsources("pacman::SDL2_mixer")
  14. elseif is_plat("linux") then
  15. add_extsources("pacman::sdl2_mixer", "apt::libsdl2-mixer-dev")
  16. elseif is_plat("macosx") then
  17. add_extsources("brew::sdl2_mixer")
  18. end
  19. add_deps("cmake")
  20. add_includedirs("include", "include/SDL2")
  21. if is_plat("wasm") then
  22. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  23. end
  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 = {
  33. "-DSDL2MIXER_CMD=OFF",
  34. "-DSDL2MIXER_FLAC=OFF",
  35. "-DSDL2MIXER_GME=OFF",
  36. "-DSDL2MIXER_MIDI=OFF",
  37. "-DSDL2MIXER_MOD=OFF",
  38. "-DSDL2MIXER_MP3=ON", -- was on by not being here
  39. "-DSDL2MIXER_OPUS=OFF",
  40. "-DSDL2MIXER_SAMPLES=OFF",
  41. "-DSDL2MIXER_WAVE=ON", -- was on by not being here
  42. "-DSDL2MIXER_WAVPACK=OFF",
  43. }
  44. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  45. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  46. local libsdl = package:dep("libsdl")
  47. if libsdl and not libsdl:is_system() then
  48. table.insert(configs, "-DSDL2_DIR=" .. libsdl:installdir())
  49. local fetchinfo = libsdl:fetch()
  50. if fetchinfo then
  51. for _, dir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
  52. if os.isfile(path.join(dir, "SDL_version.h")) then
  53. table.insert(configs, "-DSDL2_INCLUDE_DIR=" .. dir)
  54. break
  55. end
  56. end
  57. for _, libfile in ipairs(fetchinfo.libfiles) do
  58. if libfile:match("SDL2%..+$") or libfile:match("SDL2-static%..+$") then
  59. table.insert(configs, "-DSDL2_LIBRARY=" .. table.concat(fetchinfo.libfiles, ";"))
  60. end
  61. end
  62. end
  63. end
  64. import("package.tools.cmake").install(package, configs)
  65. end)
  66. on_test(function (package)
  67. assert(package:check_cxxsnippets({test = [[
  68. #include <SDL2/SDL.h>
  69. #include <SDL2/SDL_mixer.h>
  70. int main(int argc, char** argv) {
  71. Mix_Init(MIX_INIT_OGG);
  72. Mix_Quit();
  73. return 0;
  74. }
  75. ]]}, {configs = {defines = "SDL_MAIN_HANDLED"}}));
  76. end)