xmake.lua 4.1 KB

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