From 0d2535b47cebcbe2ae826cbf27c656b209d8f72e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Sun, 30 May 2021 15:12:28 +0200 Subject: [PATCH] Fix libvorbis handling --- xmake-repo/packages/l/libvorbis/xmake.lua | 97 +++++++++++++++++++++++ xmake.lua | 2 +- 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 xmake-repo/packages/l/libvorbis/xmake.lua diff --git a/xmake-repo/packages/l/libvorbis/xmake.lua b/xmake-repo/packages/l/libvorbis/xmake.lua new file mode 100644 index 000000000..b4e493467 --- /dev/null +++ b/xmake-repo/packages/l/libvorbis/xmake.lua @@ -0,0 +1,97 @@ +package("libvorbis") + + set_homepage("https://xiph.org/vorbis") + set_description("Reference implementation of the Ogg Vorbis audio format.") + set_license("BSD-3") + + set_urls("https://ftp.osuosl.org/pub/xiph/releases/vorbis/libvorbis-$(version).tar.gz", + "https://github.com/xiph/vorbis/releases/download/v$(version)/libvorbis-$(version).tar.gz", + "https://gitlab.xiph.org/xiph/vorbis.git") + + add_versions("1.3.7", "0e982409a9c3fc82ee06e08205b1355e5c6aa4c36bca58146ef399621b0ce5ab") + + add_configs("with_vorbisenc", {description = "Includes libvorbisenc", default = true, type = "boolean"}) + add_configs("with_vorbisfile", {description = "Includes libvorbisfile", default = true, type = "boolean"}) + + add_deps("cmake", "libogg") + + on_fetch(function (package, opt) + if opt.system then + local vorbis = find_package("vorbis") + if not vorbis then + return + end + local result = table.copy(vorbis) + + if package:config("with_vorbisenc") then + local vorbisenc = find_package("vorbisenc") + if not vorbisenc then + return + end + + result.includedirs = table.join(vorbisenc.includedirs, result.includedirs or {}) + result.linkdirs = table.join(vorbisenc.linkdirs, result.linkdirs or {}) + result.links = table.join(vorbisenc.links, result.links or {}) + end + + if package:config("with_vorbisfile") then + local vorbisfile = find_package("vorbisfile") + if not vorbisfile then + return + end + + result.includedirs = table.join(vorbisfile.includedirs, result.includedirs or {}) + result.linkdirs = table.join(vorbisfile.linkdirs, result.linkdirs or {}) + result.links = table.join(vorbisfile.links, result.links or {}) + end + + return result + end + end) + + on_load(function (package) + if package:config("with_vorbisenc") then + package:add("links", "vorbisenc") + end + if package:config("with_vorbisfile") then + package:add("links", "vorbisfile") + end + package:add("links", "vorbis") + end) + + on_install("windows", "linux", "macosx", "iphoneos", "mingw", "android", function (package) + local configs = {} + table.insert(configs, "-DBUILD_TESTING=OFF") + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release")) + table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) + if not package:config("with_vorbisenc") then + io.replace("CMakeLists.txt", "${CMAKE_CURRENT_BINARY_DIR}/vorbisenc.pc", "", {plain = true}) + end + if not package:config("with_vorbisfile") then + io.replace("CMakeLists.txt", "${CMAKE_CURRENT_BINARY_DIR}/vorbisfile.pc", "", {plain = true}) + end + -- we pass libogg as packagedeps instead of findOgg.cmake (it does not work) + local libogg = package:dep("libogg"):fetch() + if libogg then + local links = table.concat(table.wrap(libogg.links), " ") + io.replace("CMakeLists.txt", "find_package(Ogg REQUIRED)", "", {plain = true}) + io.replace("lib/CMakeLists.txt", "Ogg::ogg", links, {plain = true}) + end + -- disable .def file for mingw + if package:config("shared") and package:is_plat("mingw") then + io.replace("lib/CMakeLists.txt", [[list(APPEND VORBIS_SOURCES ../win32/vorbis.def) + list(APPEND VORBISENC_SOURCES ../win32/vorbisenc.def) + list(APPEND VORBISFILE_SOURCES ../win32/vorbisfile.def)]], "", {plain = true}) + end + import("package.tools.cmake").install(package, configs, {packagedeps = "libogg"}) + end) + + on_test(function (package) + assert(package:has_cfuncs("vorbis_info_init", {includes = "vorbis/codec.h"})) + if package:config("with_vorbisenc") then + assert(package:has_cfuncs("vorbis_encode_init", {includes = "vorbis/vorbisenc.h"})) + end + if package:config("with_vorbisfile") then + assert(package:has_cfuncs("ov_open_callbacks", {includes = "vorbis/vorbisfile.h"})) + end + end) diff --git a/xmake.lua b/xmake.lua index a8e24625f..7505c0374 100644 --- a/xmake.lua +++ b/xmake.lua @@ -93,7 +93,7 @@ local modules = { add_repositories("local-repo xmake-repo") add_requires("chipmunk2d", "dr_wav", "freetype", "libsndfile", "libsdl", "libvorbis", "minimp3", "stb") -add_requireconfs("libvorbis", { system = false }) +add_requires("libvorbis", { configs = { with_vorbisenc = false } }) add_requires("newtondynamics", { debug = is_plat("windows") and is_mode("debug") }) -- Newton doesn't like compiling in Debug on Linux set_project("NazaraEngine")