Kaynağa Gözat

libsvtav1: add package (#4161)

* libsvtav1: add package

* fix size_t

* cpuinfo: fix cross compilation

* cpuinfo: enable all platform

* disable cross & add on_check

* Update xmake.lua
star9029 1 yıl önce
ebeveyn
işleme
9b3413f3ca
2 değiştirilmiş dosya ile 74 ekleme ve 1 silme
  1. 21 1
      packages/c/cpuinfo/xmake.lua
  2. 53 0
      packages/l/libsvtav1/xmake.lua

+ 21 - 1
packages/c/cpuinfo/xmake.lua

@@ -18,7 +18,18 @@ package("cpuinfo")
         add_syslinks("pthread")
     end
 
-    on_install("windows", "linux", "macosx", "bsd", "android", function (package)
+    on_check("windows|arm.*", function (package)
+        import("core.tool.toolchain")
+        import("core.base.semver")
+
+        local msvc = toolchain.load("msvc", {plat = package:plat(), arch = package:arch()})
+        if msvc then
+            local vs_sdkver = msvc:config("vs_sdkver")
+            assert(vs_sdkver and semver.match(vs_sdkver):gt("10.0.19041"), "package(cpuinfo): need vs_sdkver > 10.0.19041.0")
+        end
+    end)
+
+    on_install("!cross", function (package)
         local configs = {"-DCPUINFO_BUILD_TOOLS=OFF",
                          "-DCPUINFO_BUILD_UNIT_TESTS=OFF",
                          "-DCPUINFO_BUILD_MOCK_TESTS=OFF",
@@ -26,6 +37,15 @@ package("cpuinfo")
                          "-DCPUINFO_BUILD_PKG_CONFIG=OFF"}
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
         table.insert(configs, "-DCPUINFO_LIBRARY_TYPE=" .. (package:config("shared") and "shared" or "static"))
+
+        if package:is_plat("mingw") then
+            table.insert(configs, "-DCMAKE_SYSTEM_PROCESSOR=Windows")
+        end
+        if (package:is_cross() or package:is_plat("mingw")) and (not package:is_plat("android")) then
+            io.replace("CMakeLists.txt", [[SET(CPUINFO_TARGET_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}")]], "", {plain = true})
+            table.insert(configs, "-DCPUINFO_TARGET_PROCESSOR=" .. package:arch())
+        end
+
         if package:is_plat("windows") then
             table.insert(configs, "-DCPUINFO_RUNTIME_TYPE=" .. (package:config("vs_runtime"):startswith("MT") and "static" or "shared"))
             local vs_sdkver = import("core.tool.toolchain").load("msvc"):config("vs_sdkver")

+ 53 - 0
packages/l/libsvtav1/xmake.lua

@@ -0,0 +1,53 @@
+package("libsvtav1")
+    set_homepage("https://gitlab.com/AOMediaCodec/SVT-AV1")
+    set_description("An AV1-compliant software encoder/decoder library")
+    set_license("BSD-3-Clause")
+
+    add_urls("https://gitlab.com/AOMediaCodec/SVT-AV1/-/archive/$(version)/SVT-AV1-$(version).tar.gz",
+             "https://gitlab.com/AOMediaCodec/SVT-AV1.git")
+
+    add_versions("v2.1.0", "72a076807544f3b269518ab11656f77358284da7782cece497781ab64ed4cb8a")
+    
+    add_configs("encoder", {description = "Enable encoder", default = true, type = "boolean"})
+    add_configs("decoder", {description = "Enable decoder", default = true, type = "boolean"})
+    add_configs("minimal_build", {description = "Enable minimal build", default = false, type = "boolean"})
+
+    if is_plat("mingw") and is_subhost("msys") then
+        add_extsources("pacman::svt-av1")
+    elseif is_plat("linux") then
+        add_extsources("pacman::svt-av1", "apt::libsvtav1-dev")
+    elseif is_plat("macosx") then
+        add_extsources("brew::svt-av1")
+    end
+
+    if is_plat("linux", "bsd") then
+        add_syslinks("pthread", "dl", "m")
+    end
+
+    add_deps("cmake", "nasm")
+    add_deps("cpuinfo")
+
+    on_install("!cross and !windows@arm.*", function (package)
+        if package:is_plat("windows") and package:config("shared") then
+            package:add("defines", "EB_DLL")
+        end
+
+        local configs = {"-DBUILD_TESTING=OFF", "-DBUILD_APPS=OFF", "-DUSE_EXTERNAL_CPUINFO=ON"}
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+        table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+        table.insert(configs, "-DSVT_AV1_LTO=" .. (package:config("lto") and "ON" or "OFF"))
+
+        table.insert(configs, "-DBUILD_ENC=" .. (package:config("encoder") and "ON" or "OFF"))
+        table.insert(configs, "-DBUILD_DEC=" .. (package:config("decoder") and "ON" or "OFF"))
+        table.insert(configs, "-DMINIMAL_BUILD=" .. (package:config("minimal_build") and "ON" or "OFF"))
+        import("package.tools.cmake").install(package, configs)
+    end)
+
+    on_test(function (package)
+        if package:config("encoder") then
+            assert(package:has_cfuncs("svt_av1_enc_init_handle", {includes = {"stddef.h", "svt-av1/EbSvtAv1Enc.h"}}))
+        end
+        if package:config("decoder") then
+            assert(package:has_cfuncs("svt_av1_dec_init_handle", {includes = {"stddef.h", "svt-av1/EbSvtAv1Dec.h"}}))
+        end
+    end)