xmake.lua 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.4.3", "0a4bb82a30609b606650d538a804a7b40205366ce8fc98871b0ecf3fbb0611ee")
  8. add_versions("1.4.2", "8e8e0406fb9e1d177bb4ba8cfed3ca3935d37144eac8f0219a03e8c1ed5cc18e")
  9. add_versions("1.3.3", "668cdeab898a7dd43cf84739f7e1f3ed6b35ece2ef9968a5c7079fe9adfe1689")
  10. add_patches("1.4.3", "patches/1.4.2/cmake.patch", "0a99382d5d7bd33078572b6cc3af08ee7e5e3618c80754a5fdc400bd69f4e470")
  11. add_patches("1.4.2", "patches/1.4.2/cmake.patch", "0a99382d5d7bd33078572b6cc3af08ee7e5e3618c80754a5fdc400bd69f4e470")
  12. add_patches("1.3.3", "patches/1.3.3/cmake.patch", "49baa40ab70d63e74cfc3f0cc2f13824545a618ceaeffdd51d3333d90b37fd32")
  13. if is_plat("mingw") and is_subhost("msys") then
  14. add_extsources("pacman::flac")
  15. elseif is_plat("linux") then
  16. add_extsources("pacman::flac", "apt::libflac++-dev", "apt::libflac-dev")
  17. elseif is_plat("macosx") then
  18. add_extsources("brew::flac")
  19. end
  20. add_deps("cmake", "libogg")
  21. if is_plat("linux") then
  22. add_syslinks("m")
  23. end
  24. on_load("windows", "mingw", function (package)
  25. if not package:config("shared") then
  26. package:add("defines", "FLAC__NO_DLL")
  27. end
  28. end)
  29. on_install("windows", "linux", "macosx", "iphoneos", "mingw", "android", "wasm", function (package)
  30. local configs = {}
  31. table.insert(configs, "-DBUILD_CXXLIBS=OFF")
  32. table.insert(configs, "-DBUILD_DOCS=OFF")
  33. table.insert(configs, "-DBUILD_PROGRAMS=OFF")
  34. table.insert(configs, "-DBUILD_EXAMPLES=OFF")
  35. table.insert(configs, "-DBUILD_TESTING=OFF")
  36. table.insert(configs, "-DBUILD_UTILS=OFF")
  37. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  38. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  39. table.insert(configs, "-DCMAKE_POSITION_INDEPENDENT_CODE=ON")
  40. table.insert(configs, "-DINSTALL_MANPAGES=OFF")
  41. if package:is_plat("wasm") then
  42. -- wasm doesn't support stack protector
  43. table.insert(configs, "-DWITH_STACK_PROTECTOR=OFF")
  44. end
  45. -- fix, undefined reference to `__memset_chk'
  46. -- @see https://github.com/msys2/MINGW-packages/issues/5803
  47. if package:config("shared") and package:is_plat("mingw") then
  48. io.replace("CMakeLists.txt", "add_definitions(-DHAVE_CONFIG_H)", "add_definitions(-DHAVE_CONFIG_H -D_FORTIFY_SOURCE=0)", {plain = true})
  49. end
  50. -- we pass libogg as packagedeps instead of findOgg.cmake (it does not work)
  51. local libogg = package:dep("libogg"):fetch()
  52. if libogg then
  53. local links = table.concat(table.wrap(libogg.links), " ")
  54. io.replace("CMakeLists.txt", "find_package(OGG REQUIRED)", "", {plain = true}) -- v1.3.3
  55. io.replace("CMakeLists.txt", "find_package(Ogg REQUIRED)", "", {plain = true}) -- v1.3.4+
  56. io.replace("src/libFLAC/CMakeLists.txt",
  57. [[
  58. if(TARGET Ogg::ogg)
  59. target_link_libraries(FLAC PUBLIC Ogg::ogg)
  60. endif()]], "target_link_libraries(FLAC PUBLIC " .. links .. ")", {plain = true})
  61. end
  62. import("package.tools.cmake").install(package, configs, {packagedeps = "libogg"})
  63. end)
  64. on_test(function (package)
  65. assert(package:has_cfuncs("FLAC__format_sample_rate_is_valid", {includes = "FLAC/format.h"}))
  66. end)