xmake.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package("x265")
  2. set_homepage("http://x265.org")
  3. set_description("A free software library and application for encoding video streams into the H.265/MPEG-H HEVC compression format.")
  4. set_license("GPL-2.0")
  5. add_urls("https://github.com/videolan/x265.git",
  6. "https://bitbucket.org/multicoreware/x265_git")
  7. add_urls("https://github.com/videolan/x265/archive/refs/tags/$(version).tar.gz", {alias = "github"})
  8. add_urls("https://bitbucket.org/multicoreware/x265_git/downloads/x265_$(version).tar.gz", {alias = "bitbucket"})
  9. add_versions("bitbucket:4.0", "75b4d05629e365913de3100b38a459b04e2a217a8f30efaa91b572d8e6d71282")
  10. add_versions("github:3.4", "544d147bf146f8994a7bf8521ed878c93067ea1c7c6e93ab602389be3117eaaf")
  11. add_versions("github:3.3", "ca25a38772fc6b49e5f1aa88733bc1dc92da7dc18f02a85cc3e99d76ba85b0a9")
  12. add_versions("github:3.2.1", "b5ee7ea796a664d6e2763f9c0ae281fac5d25892fc2cb134698547103466a06a")
  13. add_versions("github:3.2", "4dd707648ea90b96bf1f8ea6a36ed21c11fe3a9048923909c5b629755ca8d8f3")
  14. add_configs("hdr10_plus", {description = "Enable dynamic HDR10 compilation", default = false, type = "boolean"})
  15. add_configs("svt_hevc", {description = "Enable SVT HEVC Encoder", default = false, type = "boolean"})
  16. add_configs("high_bit_depth", {description = "Store pixel samples as 16bit values (Main10/Main12)", default = false, type = "boolean"})
  17. add_configs("main12", {description = "Support Main12 instead of Main10", default = false, type = "boolean"})
  18. if is_plat("linux") then
  19. add_configs("numa", {description = "Enable libnuma", default = false, type = "boolean"})
  20. elseif is_plat("wasm") then
  21. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  22. end
  23. add_configs("tools", {description = "Build tools", default = false, type = "boolean"})
  24. if is_plat("macosx") then
  25. add_syslinks("c++")
  26. elseif is_plat("linux", "bsd") then
  27. add_syslinks("pthread", "dl")
  28. end
  29. set_policy("package.cmake_generator.ninja", true)
  30. add_deps("cmake", "ninja", "nasm >=2.13")
  31. if on_check then
  32. on_check("cross", function (package)
  33. if package:version():ge("4.0") then
  34. raise("package(x265 >=4.0) unsupported cross pltform")
  35. end
  36. end)
  37. end
  38. on_install("!cross", function (package)
  39. os.cd("source")
  40. -- Let xmake cp pdb
  41. io.replace("CMakeLists.txt", "if((WIN32 AND ENABLE_CLI) OR (WIN32 AND ENABLE_SHARED))", "if(0)", {plain = true})
  42. if package:is_plat("android") then
  43. io.replace("CMakeLists.txt", "list(APPEND PLATFORM_LIBS pthread)", "", {plain = true})
  44. elseif package:is_plat("wasm") then
  45. io.replace("CMakeLists.txt", "X86 AND NOT X64", "FALSE", {plain = true})
  46. end
  47. local configs = {}
  48. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  49. table.insert(configs, "-DCHECKED_BUILD=" .. (package:is_debug() and "ON" or "OFF"))
  50. table.insert(configs, "-DENABLE_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
  51. table.insert(configs, "-DENABLE_PIC=" .. (package:config("pic") and "ON" or "OFF"))
  52. table.insert(configs, "-DENABLE_HDR10_PLUS=" .. (package:config("hdr10_plus") and "ON" or "OFF"))
  53. table.insert(configs, "-DENABLE_SVT_HEVC=" .. (package:config("svt_hevc") and "ON" or "OFF"))
  54. table.insert(configs, "-DHIGH_BIT_DEPTH=" .. (package:config("high_bit_depth") and "ON" or "OFF"))
  55. table.insert(configs, "-DMAIN12=" .. (package:config("main12") and "ON" or "OFF"))
  56. table.insert(configs, "-DENABLE_CLI=" .. (package:config("tools") and "ON" or "OFF"))
  57. table.insert(configs, "-DNATIVE_BUILD=" .. (package:is_cross() and "OFF" or "ON"))
  58. if package:config("numa") then
  59. table.insert(configs, "-DENABLE_LIBNUMA=ON")
  60. package:add("syslinks", "numa")
  61. else
  62. table.insert(configs, "-DENABLE_LIBNUMA=OFF")
  63. end
  64. if package:version() then
  65. table.insert(configs, "-DX265_LATEST_TAG=" .. package:version():rawstr())
  66. end
  67. if (package:is_plat("windows") and package:is_arch("arm.*"))
  68. or package:is_plat("android", "iphoneos", "wasm") then
  69. table.insert(configs, "-DENABLE_ASSEMBLY=OFF")
  70. end
  71. if package:is_cross() and package:is_targetarch("arm.*") then
  72. if package:is_arch64() then
  73. table.insert(configs, "-DCROSS_COMPILE_ARM64=ON")
  74. else
  75. table.insert(configs, "-DCROSS_COMPILE_ARM=ON")
  76. end
  77. end
  78. if package:is_plat("windows") then
  79. table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''")
  80. end
  81. local opt = {}
  82. if package:gitref() or package:version():ge("4.0") then
  83. if package:is_plat("wasm") then
  84. opt.cxflags = "-pthread"
  85. package:add("ldflags", "-s USE_PTHREADS=1")
  86. end
  87. end
  88. import("package.tools.cmake").install(package, configs, opt)
  89. if package:is_plat("windows") then
  90. if package:config("shared") then
  91. os.tryrm(package:installdir("lib/x265-static.lib"))
  92. end
  93. -- Error links, switch to xmake pc file
  94. os.rm(package:installdir("lib/pkgconfig/x265.pc"))
  95. if package:is_debug() then
  96. local dir = package:installdir(package:config("shared") and "bin" or "lib")
  97. os.trycp(path.join(package:buildir(), "libx265.pdb"), dir)
  98. if package:config("tools") then
  99. os.trycp(path.join(package:buildir(), "x265.pdb"), package:installdir("bin"))
  100. end
  101. end
  102. else
  103. if package:config("shared") then
  104. os.tryrm(package:installdir("lib/libx265.a"))
  105. end
  106. end
  107. end)
  108. on_test(function (package)
  109. assert(package:has_cfuncs("x265_api_get", {includes = "x265.h"}))
  110. end)