xmake.lua 5.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package("svt-av1")
  2. set_homepage("https://gitlab.com/AOMediaCodec/SVT-AV1")
  3. set_description("Scalable Video Technology for AV1 (SVT-AV1 Encoder and Decoder)")
  4. set_license("BSD-2-clause")
  5. add_urls("https://gitlab.com/AOMediaCodec/SVT-AV1.git",
  6. "https://gitlab.com/AOMediaCodec/SVT-AV1/-/archive/v$(version)/SVT-AV1-v$(version).tar.gz")
  7. add_versions("1.4.0", "0a4650b822c4eeb9656fbe96bd795e7a73cbfd1ab8c12546348ba88d8ed6b415")
  8. add_versions("1.4.1", "e3f7fc194afc6c90b43e0b80fa24c09940cb03bea394e0e1f5d1ded18e9ab23f")
  9. add_versions("1.5.0", "64e27b024eb43e4ba4e7b85584e0497df534043b2ce494659532c585819d0333")
  10. add_versions("1.6.0", "3bc207247568ac713245063555082bfc905edc31df3bf6355e3b194cb73ad817")
  11. add_configs("encoder", {description = "Build Encoder lib", default = true, type = "boolean"})
  12. add_configs("decoder", {description = "Build Decoder lib", default = true, type = "boolean"})
  13. add_configs("avx512", {description = "Enable building avx512 code", default = false, type = "boolean"})
  14. if not is_plat("windows") then
  15. add_configs("pgo", {description = "Enable profile guided optimization. Creates the RunPGO and CompilePGO targets", default = false, type = "boolean"})
  16. add_configs("native", {description = "Build for native performance (march=native)", default = false, type = "boolean"})
  17. end
  18. if is_plat("wasm") then
  19. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  20. end
  21. if is_plat("bsd", "linux", "wasm") then
  22. add_syslinks("pthread")
  23. end
  24. add_deps("cmake")
  25. on_load(function (package)
  26. if package:is_targetarch("x64", "x86", "x86_64") then
  27. if is_host("windows") or package:is_plat("bsd") then
  28. package:add("deps", "nasm")
  29. else
  30. package:add("deps", "yasm")
  31. end
  32. end
  33. if not package:has_cfuncs("_mm512_extracti64x4_epi64", {includes = "immintrin.h"}) then
  34. package:config_set("enable-avx512", false)
  35. end
  36. end)
  37. on_install(function (package)
  38. local configs = {"-DBUILD_TESTING=OFF", "-DCOVERAGE=OFF", "-DBUILD_APPS=OFF"}
  39. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  40. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  41. table.insert(configs, "-DBUILD_ENC=" .. (package:config("encoder") and "ON" or "OFF"))
  42. table.insert(configs, "-DBUILD_DEC=" .. (package:config("decoder") and "ON" or "OFF"))
  43. table.insert(configs, "-DENABLE_AVX512=" .. (package:config("avx512") and "ON" or "OFF"))
  44. table.insert(configs, "-DSVT_AV1_LTO=" .. (package:config("lto") and "ON" or "OFF"))
  45. table.insert(configs, "-DSVT_AV1_PGO=" .. (package:config("pgo") and "ON" or "OFF"))
  46. table.insert(configs, "-DNATIVE=" .. (package:config("native") and "ON" or "OFF"))
  47. if package:is_plat("wasm") then
  48. io.replace("CMakeLists.txt", "if(MINGW)", "if(TRUE)\n check_both_flags_add(-pthread)\n elseif(MINGW)", {plain = true})
  49. io.replace("CMakeLists.txt", "set(CMAKE_EXE_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS} -z noexecstack -z relro -z now\")", "", {plain = true})
  50. io.replace("Source/Lib/Decoder/CMakeLists.txt", "list(APPEND PLATFORM_LIBS Threads::Threads)", "", {plain = true})
  51. io.replace("Source/Lib/Encoder/CMakeLists.txt", "list(APPEND PLATFORM_LIBS Threads::Threads)", "", {plain = true})
  52. io.replace("Source/Lib/Decoder/Codec/EbDecHandle.c", "!geteuid()", "0", {plain = true})
  53. io.replace("Source/Lib/Common/Codec/EbThreads.c", "!geteuid()", "0", {plain = true})
  54. io.replace("Source/Lib/Encoder/Globals/EbEncHandle.c", "!geteuid()", "0", {plain = true})
  55. elseif package:is_plat("mingw") and package:is_arch("x64", "x86_64") then
  56. table.insert(configs, "-DCMAKE_SYSTEM_PROCESSOR=AMD64")
  57. elseif package:is_plat("android") then
  58. io.replace("CMakeLists.txt", "CMAKE_C_COMPILER_ID MATCHES \"Clang\" AND UNIX AND NOT APPLE", "FALSE", {plain = true})
  59. io.replace("Source/Lib/Decoder/CMakeLists.txt", "list(APPEND PLATFORM_LIBS Threads::Threads)", "", {plain = true})
  60. io.replace("Source/Lib/Decoder/CMakeLists.txt", "set(LIBS_PRIVATE \"-lpthread -lm\")", "set(LIBS_PRIVATE \"-lm\")", {plain = true})
  61. io.replace("Source/Lib/Encoder/CMakeLists.txt", "list(APPEND PLATFORM_LIBS Threads::Threads)", "", {plain = true})
  62. io.replace("Source/Lib/Encoder/CMakeLists.txt", "set(LIBS_PRIVATE \"-lpthread -lm\")", "set(LIBS_PRIVATE \"-lm\")", {plain = true})
  63. io.replace("Source/Lib/Common/Codec/EbThreads.h", "#if defined(__linux__)", "#if 0", {plain = true})
  64. end
  65. import("package.tools.cmake").install(package, configs)
  66. end)
  67. on_test(function (package)
  68. assert(package:has_cfuncs("svt_av1_enc_init_handle", {includes = "svt-av1/EbSvtAv1Enc.h"}))
  69. end)