xmake.lua 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package("libflac")
  2. set_homepage("https://xiph.org/flac")
  3. set_description("Free Lossless Audio Codec")
  4. set_license("BSD")
  5. set_urls("https://github.com/xiph/flac/archive/$(version).tar.gz",
  6. "https://github.com/xiph/flac.git")
  7. add_versions("1.3.3", "668cdeab898a7dd43cf84739f7e1f3ed6b35ece2ef9968a5c7079fe9adfe1689")
  8. add_patches("1.3.3", path.join(os.scriptdir(), "patches", "1.3.3", "cmake.patch"), "49baa40ab70d63e74cfc3f0cc2f13824545a618ceaeffdd51d3333d90b37fd32")
  9. if is_plat("mingw") and is_subhost("msys") then
  10. add_extsources("pacman::flac")
  11. elseif is_plat("linux") then
  12. add_extsources("pacman::flac", "apt::libflac++-dev", "apt::libflac-dev")
  13. elseif is_plat("macosx") then
  14. add_extsources("brew::flac")
  15. end
  16. add_deps("cmake", "libogg")
  17. if is_plat("linux") then
  18. add_syslinks("m")
  19. end
  20. on_load("windows", "mingw", function (package)
  21. if not package:config("shared") then
  22. package:add("defines", "FLAC__NO_DLL")
  23. end
  24. end)
  25. on_install("windows", "linux", "macosx", "iphoneos", "mingw", "android", function (package)
  26. local configs = {}
  27. table.insert(configs, "-DBUILD_CXXLIBS=OFF")
  28. table.insert(configs, "-DBUILD_DOCS=OFF")
  29. table.insert(configs, "-DBUILD_PROGRAMS=OFF")
  30. table.insert(configs, "-DBUILD_EXAMPLES=OFF")
  31. table.insert(configs, "-DBUILD_TESTING=OFF")
  32. table.insert(configs, "-DBUILD_UTILS=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. table.insert(configs, "-DCMAKE_POSITION_INDEPENDENT_CODE=ON")
  36. -- fix, undefined reference to `__memset_chk'
  37. -- @see https://github.com/msys2/MINGW-packages/issues/5803
  38. if package:config("shared") and package:is_plat("mingw") then
  39. io.replace("CMakeLists.txt", "add_definitions(-DHAVE_CONFIG_H)", "add_definitions(-DHAVE_CONFIG_H -D_FORTIFY_SOURCE=0)", {plain = true})
  40. end
  41. -- we pass libogg as packagedeps instead of findOgg.cmake (it does not work)
  42. local libogg = package:dep("libogg"):fetch()
  43. if libogg then
  44. local links = table.concat(table.wrap(libogg.links), " ")
  45. io.replace("CMakeLists.txt", "find_package(OGG REQUIRED)", "", {plain = true})
  46. io.replace("src/libFLAC/CMakeLists.txt",
  47. [[
  48. if(TARGET Ogg::ogg)
  49. target_link_libraries(FLAC PUBLIC Ogg::ogg)
  50. endif()]], "target_link_libraries(FLAC PUBLIC " .. links .. ")", {plain = true})
  51. end
  52. import("package.tools.cmake").install(package, configs, {packagedeps = "libogg"})
  53. end)
  54. on_test(function (package)
  55. assert(package:has_cfuncs("FLAC__format_sample_rate_is_valid", {includes = "FLAC/format.h"}))
  56. end)