xmake.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package("libvorbis")
  2. set_homepage("https://xiph.org/vorbis")
  3. set_description("Reference implementation of the Ogg Vorbis audio format.")
  4. set_license("BSD-3")
  5. set_urls("https://ftp.osuosl.org/pub/xiph/releases/vorbis/libvorbis-$(version).tar.gz",
  6. "https://github.com/xiph/vorbis/releases/download/v$(version)/libvorbis-$(version).tar.gz",
  7. "https://gitlab.xiph.org/xiph/vorbis.git")
  8. add_versions("1.3.7", "0e982409a9c3fc82ee06e08205b1355e5c6aa4c36bca58146ef399621b0ce5ab")
  9. add_configs("vorbisenc", {description = "Includes vorbisenc", default = true, type = "boolean"})
  10. add_configs("vorbisfile", {description = "Includes vorbisfile", default = true, type = "boolean"})
  11. if is_plat("mingw") and is_subhost("msys") then
  12. add_extsources("pacman::libvorbis")
  13. elseif is_plat("linux") then
  14. add_extsources("pacman::libvorbis", "apt::libvorbis-dev")
  15. elseif is_plat("macosx") then
  16. add_extsources("brew::libvorbis")
  17. end
  18. add_deps("cmake", "libogg")
  19. on_fetch(function (package, opt)
  20. if opt.system then
  21. local libs = {"vorbis"}
  22. -- vorbisenc and vorbisfile depends on vorbis, put them first to fix link order
  23. if package:config("vorbisenc") then
  24. table.insert(libs, 1, "vorbisenc")
  25. end
  26. if package:config("vorbisfile") then
  27. table.insert(libs, 1, "vorbisfile")
  28. end
  29. local result
  30. for _, name in ipairs(libs) do
  31. local pkginfo = package:find_package(name, opt)
  32. if not pkginfo then
  33. return -- we must find all wanted libraries
  34. end
  35. if not result then
  36. result = table.copy(pkginfo)
  37. else
  38. local includedirs = pkginfo.sysincludedirs or pkginfo.includedirs
  39. result.links = table.wrap(result.links)
  40. result.linkdirs = table.wrap(result.linkdirs)
  41. result.includedirs = table.wrap(result.includedirs)
  42. table.join2(result.includedirs, includedirs)
  43. table.join2(result.linkdirs, pkginfo.linkdirs)
  44. table.join2(result.links, pkginfo.links)
  45. end
  46. if result then
  47. result.version = result.version or pkginfo.version
  48. end
  49. end
  50. return result
  51. end
  52. end)
  53. on_load(function (package)
  54. local ext = (package:is_plat("mingw") and package:config("shared")) and ".dll" or ""
  55. if package:config("vorbisenc") then
  56. package:add("links", "vorbisenc" .. ext)
  57. end
  58. if package:config("vorbisfile") then
  59. package:add("links", "vorbisfile" .. ext)
  60. end
  61. package:add("links", "vorbis" .. ext)
  62. end)
  63. on_install("windows", "linux", "macosx", "iphoneos", "mingw", "android", "wasm", function (package)
  64. local configs = {}
  65. table.insert(configs, "-DBUILD_TESTING=OFF")
  66. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  67. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  68. if not package:config("vorbisenc") then
  69. io.replace("CMakeLists.txt", "${CMAKE_CURRENT_BINARY_DIR}/vorbisenc.pc", "", {plain = true})
  70. end
  71. if not package:config("vorbisfile") then
  72. io.replace("CMakeLists.txt", "${CMAKE_CURRENT_BINARY_DIR}/vorbisfile.pc", "", {plain = true})
  73. end
  74. -- we pass libogg as packagedeps instead of findOgg.cmake (it does not work)
  75. local libogg = package:dep("libogg"):fetch()
  76. if libogg then
  77. local links = table.concat(table.wrap(libogg.links), " ")
  78. io.replace("CMakeLists.txt", "find_package(Ogg REQUIRED)", "", {plain = true})
  79. io.replace("lib/CMakeLists.txt", "Ogg::ogg", links, {plain = true})
  80. end
  81. -- disable .def file for mingw
  82. if package:config("shared") and package:is_plat("mingw") then
  83. io.replace("lib/CMakeLists.txt", [[list(APPEND VORBIS_SOURCES ../win32/vorbis.def)
  84. list(APPEND VORBISENC_SOURCES ../win32/vorbisenc.def)
  85. list(APPEND VORBISFILE_SOURCES ../win32/vorbisfile.def)]], "", {plain = true})
  86. end
  87. import("package.tools.cmake").install(package, configs, {packagedeps = "libogg"})
  88. end)
  89. on_test(function (package)
  90. assert(package:has_cfuncs("vorbis_info_init", {includes = "vorbis/codec.h"}))
  91. if package:config("vorbisenc") then
  92. assert(package:has_cfuncs("vorbis_encode_init", {includes = "vorbis/vorbisenc.h"}))
  93. end
  94. if package:config("vorbisfile") then
  95. assert(package:has_cfuncs("ov_open_callbacks", {includes = "vorbis/vorbisfile.h"}))
  96. end
  97. end)