xmake.lua 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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-3-Clause")
  5. add_urls("https://gitlab.com/AOMediaCodec/SVT-AV1/-/archive/$(version)/SVT-AV1-$(version).tar.gz",
  6. "https://gitlab.com/AOMediaCodec/SVT-AV1.git")
  7. add_versions("v2.2.1", "d02b54685542de0236bce4be1b50912aba68aff997c43b350d84a518df0cf4e5")
  8. add_versions("v2.1.0", "72a076807544f3b269518ab11656f77358284da7782cece497781ab64ed4cb8a")
  9. add_versions("v1.4.0", "0a4650b822c4eeb9656fbe96bd795e7a73cbfd1ab8c12546348ba88d8ed6b415")
  10. add_versions("v1.4.1", "e3f7fc194afc6c90b43e0b80fa24c09940cb03bea394e0e1f5d1ded18e9ab23f")
  11. add_versions("v1.5.0", "64e27b024eb43e4ba4e7b85584e0497df534043b2ce494659532c585819d0333")
  12. add_versions("v1.6.0", "3bc207247568ac713245063555082bfc905edc31df3bf6355e3b194cb73ad817")
  13. add_configs("encoder", {description = "Build Encoder lib (deprecated after v2.1.1)", default = true, type = "boolean"})
  14. add_configs("decoder", {description = "Build Decoder lib (deprecated after v2.1.1)", default = true, type = "boolean"})
  15. add_configs("avx512", {description = "Enable building avx512 code", default = false, type = "boolean"})
  16. add_configs("minimal_build", {description = "Enable minimal build", default = false, type = "boolean"})
  17. add_configs("tools", {description = "Build tools", default = false, type = "boolean"})
  18. if is_plat("android") and is_host("linux") then
  19. -- llvm-ar: not found
  20. add_configs("shared", {description = "Build shared library.", default = true, type = "boolean", readonly = true})
  21. end
  22. if is_plat("mingw") and is_subhost("msys") then
  23. add_extsources("pacman::svt-av1")
  24. elseif is_plat("linux") then
  25. add_extsources("pacman::svt-av1", "apt::libsvtav1-dev")
  26. elseif is_plat("macosx") then
  27. add_extsources("brew::svt-av1")
  28. end
  29. if not is_plat("windows") then
  30. add_configs("pgo", {description = "Enable profile guided optimization. Creates the RunPGO and CompilePGO targets", default = false, type = "boolean"})
  31. add_configs("native", {description = "Build for native performance (march=native)", default = false, type = "boolean"})
  32. end
  33. if is_plat("wasm") then
  34. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  35. end
  36. if is_plat("linux", "bsd") then
  37. add_syslinks("pthread", "m")
  38. elseif is_plat("wasm") then
  39. add_syslinks("pthread")
  40. add_ldflags("-s USE_PTHREADS=1")
  41. end
  42. add_deps("cmake", "nasm")
  43. add_deps("cpuinfo")
  44. on_load(function (package)
  45. if package:is_plat("windows") and package:config("shared") then
  46. package:add("defines", "EB_DLL")
  47. end
  48. end)
  49. on_install("!cross and (!windows or windows|!arm64)", function (package)
  50. local configs = {
  51. "-DBUILD_TESTING=OFF",
  52. "-DCOVERAGE=OFF",
  53. "-DUSE_EXTERNAL_CPUINFO=ON",
  54. }
  55. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  56. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  57. table.insert(configs, "-DSVT_AV1_LTO=" .. (package:config("lto") and "ON" or "OFF"))
  58. table.insert(configs, "-DSVT_AV1_PGO=" .. (package:config("pgo") and "ON" or "OFF"))
  59. table.insert(configs, "-DBUILD_ENC=" .. (package:config("encoder") and "ON" or "OFF"))
  60. table.insert(configs, "-DBUILD_DEC=" .. (package:config("decoder") and "ON" or "OFF"))
  61. table.insert(configs, "-DMINIMAL_BUILD=" .. (package:config("minimal_build") and "ON" or "OFF"))
  62. table.insert(configs, "-DENABLE_AVX512=" .. (package:config("avx512") and "ON" or "OFF"))
  63. table.insert(configs, "-DNATIVE=" .. (package:config("native") and "ON" or "OFF"))
  64. table.insert(configs, "-DBUILD_APPS=" .. (package:config("tools") and "ON" or "OFF"))
  65. if package:is_plat("windows") then
  66. table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''")
  67. end
  68. if package:version() and package:version():lt("2.0.0") then
  69. if package:is_plat("wasm") then
  70. io.replace("CMakeLists.txt", "if(MINGW)", "if(TRUE)\n check_both_flags_add(-pthread)\n elseif(MINGW)", {plain = true})
  71. io.replace("CMakeLists.txt", "set(CMAKE_EXE_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS} -z noexecstack -z relro -z now\")", "", {plain = true})
  72. io.replace("Source/Lib/Decoder/CMakeLists.txt", "list(APPEND PLATFORM_LIBS Threads::Threads)", "", {plain = true})
  73. io.replace("Source/Lib/Encoder/CMakeLists.txt", "list(APPEND PLATFORM_LIBS Threads::Threads)", "", {plain = true})
  74. io.replace("Source/Lib/Decoder/Codec/EbDecHandle.c", "!geteuid()", "0", {plain = true})
  75. io.replace("Source/Lib/Common/Codec/EbThreads.c", "!geteuid()", "0", {plain = true})
  76. io.replace("Source/Lib/Encoder/Globals/EbEncHandle.c", "!geteuid()", "0", {plain = true})
  77. elseif package:is_plat("mingw") and package:is_arch("x64", "x86_64") then
  78. table.insert(configs, "-DCMAKE_SYSTEM_PROCESSOR=AMD64")
  79. elseif package:is_plat("android") then
  80. io.replace("CMakeLists.txt", "CMAKE_C_COMPILER_ID MATCHES \"Clang\" AND UNIX AND NOT APPLE", "FALSE", {plain = true})
  81. io.replace("Source/Lib/Decoder/CMakeLists.txt", "list(APPEND PLATFORM_LIBS Threads::Threads)", "", {plain = true})
  82. io.replace("Source/Lib/Decoder/CMakeLists.txt", "set(LIBS_PRIVATE \"-lpthread -lm\")", "set(LIBS_PRIVATE \"-lm\")", {plain = true})
  83. io.replace("Source/Lib/Encoder/CMakeLists.txt", "list(APPEND PLATFORM_LIBS Threads::Threads)", "", {plain = true})
  84. io.replace("Source/Lib/Encoder/CMakeLists.txt", "set(LIBS_PRIVATE \"-lpthread -lm\")", "set(LIBS_PRIVATE \"-lm\")", {plain = true})
  85. io.replace("Source/Lib/Common/Codec/EbThreads.h", "#if defined(__linux__)", "#if 0", {plain = true})
  86. end
  87. end
  88. local opt = {}
  89. if package:is_plat("wasm") then
  90. -- https://stackoverflow.com/questions/58854858/undefined-symbol-stack-chk-guard-in-libopenh264-so-when-building-ffmpeg-wit
  91. -- https://github.com/emscripten-core/emscripten/issues/17030
  92. opt.cxflags = {"-fno-stack-protector", "-U_FORTIFY_SOURCE"}
  93. opt.ldflags = {"-fno-stack-protector", "-U_FORTIFY_SOURCE"}
  94. end
  95. import("package.tools.cmake").install(package, configs, opt)
  96. if package:is_plat("windows") and package:is_debug() then
  97. local dir = package:installdir(package:config("shared") and "bin" or "lib")
  98. os.vcp("Bin/**.pdb", dir)
  99. end
  100. end)
  101. on_test(function (package)
  102. local ldflags = {}
  103. if package:is_plat("wasm") then
  104. table.insert(ldflags, "-s USE_PTHREADS=1")
  105. table.insert(ldflags, "-s TOTAL_MEMORY=256MB")
  106. end
  107. if package:gitref() or package:version():ge("2.1.1") then
  108. assert(package:has_cfuncs("svt_av1_enc_init_handle", {
  109. includes = "svt-av1/EbSvtAv1Enc.h", configs = {ldflags = ldflags}
  110. }))
  111. else
  112. if package:config("encoder") then
  113. assert(package:has_cfuncs("svt_av1_enc_init_handle", {includes = {"stddef.h", "svt-av1/EbSvtAv1Enc.h"}}))
  114. end
  115. if package:config("decoder") then
  116. assert(package:has_cfuncs("svt_av1_dec_init_handle", {includes = {"stddef.h", "svt-av1/EbSvtAv1Dec.h"}}))
  117. end
  118. end
  119. end)