浏览代码

zstd: use cmake (#5858)

* zstd: use cmake

* zstd: improve deps

* zstd: fix syslinks
star9029 9 月之前
父节点
当前提交
a536096bf3

+ 26 - 12
packages/l/libdwarf/xmake.lua

@@ -3,7 +3,9 @@ package("libdwarf")
     set_description("Libdwarf is a C library intended to simplify reading (and writing) applications using DWARF2, DWARF3, DWARF4 and DWARF5")
     set_license("LGPL-2.1")
 
-    add_urls("https://github.com/davea42/libdwarf-code/releases/download/v$(version)/libdwarf-$(version).tar.xz")
+    add_urls("https://github.com/davea42/libdwarf-code/releases/download/v$(version)/libdwarf-$(version).tar.xz",
+             "https://github.com/davea42/libdwarf-code.git")
+
     add_versions("0.11.0", "846071fb220ac1952f9f15ebbac6c7831ef50d0369b772c07a8a8139a42e07d2")
     add_versions("0.10.1", "b511a2dc78b98786064889deaa2c1bc48a0c70115c187900dd838474ded1cc19")
     add_versions("0.10.0", "17b7143c4b3e5949d1578c43e8f1e2abd9f1a47e725e6600fe7ac4833a93bb77")
@@ -12,35 +14,47 @@ package("libdwarf")
     add_versions("0.9.0", "d3cad80a337276a7581bb90ebcddbd743484a99a959157c066dd30f7535db59b")
     add_versions("0.8.0", "771814a66b5aadacd8381b22d8a03b9e197bd35c202d27e19fb990e9b6d27b17")
 
+    add_configs("tools", {description = "Build tools", default = false, type = "boolean"})
+
     add_deps("cmake")
     add_deps("zlib", "zstd")
     if is_plat("windows", "mingw") then
         add_links("dwarf")
     end
 
-    on_install("windows", "linux", "macosx", "mingw", "cross", function (package)
-        local configs = {}
-        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
-        table.insert(configs, "-DBUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
-        table.insert(configs, "-DBUILD_NON_SHARED=" .. (package:config("shared") and "OFF" or "ON"))
-
+    on_install(function (package)
         if is_plat("windows", "mingw") and not package:config("shared") then
             package:add("defines", "LIBDWARF_STATIC=1")
         end
 
+        local version = package:version()
+        if package:gitref() or version:ge("0.9.2") then
+            -- https://github.com/davea42/libdwarf-code/pull/226
+            io.replace("CMakeLists.txt", "find_package(zstd)", "find_package(zstd CONFIG REQUIRED)", {plain = true})
+        else
+            io.replace("CMakeLists.txt", "find_package(ZSTD)", "find_package(zstd CONFIG REQUIRED)", {plain = true})
+        end
+        io.replace("CMakeLists.txt", [[set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")]], "", {plain = true})
+        if not package:config("tools") then
+            io.replace("CMakeLists.txt", "add_subdirectory(src/bin/dwarfdump)", "", {plain = true})
+        end
         if package:is_plat("windows") then
-            table.insert(configs, "-DCMAKE_INSTALL_PREFIX='./'")
             io.replace("src/lib/libdwarf/libdwarf_private.h", "typedef long long off_t;", "#include <sys/types.h>", {plain = true})
             io.replace("src/lib/libdwarf/libdwarf_private.h", "typedef long off_t;", "#include <sys/types.h>", {plain = true})
         end
 
-        io.replace("CMakeLists.txt", "add_subdirectory(src/bin/dwarfdump)", "", {plain = true})
+        local configs = {}
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+        table.insert(configs, "-DBUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
+        table.insert(configs, "-DBUILD_NON_SHARED=" .. (package:config("shared") and "OFF" or "ON"))
+        table.insert(configs, "-DBUILD_DWARFDUMP=" .. (package:config("tools") and "ON" or "OFF"))
+        table.insert(configs, "-DBUILD_DWARFGEN=" .. (package:config("tools") and "ON" or "OFF"))
         import("package.tools.cmake").install(package, configs)
 
-        if package:version():ge("0.9.1") then
-            local includedir = package:installdir("include", "libdwarf")
+        if package:gitref() or version:ge("0.9.1") then
+            local includedir = package:installdir("include/libdwarf")
             os.mkdir(includedir)
-            os.mv(package:installdir("include", "*.h"), includedir)
+            os.cp(package:installdir("include/*.h"), includedir)
         end
     end)
 

+ 0 - 17
packages/m/microsoft-seal/patches/4.1.2/cmake-config-zstd.patch

@@ -1,17 +0,0 @@
-diff --git a/cmake/SEALConfig.cmake.in b/cmake/SEALConfig.cmake.in
-index 45f855e..94ea283 100644
---- a/cmake/SEALConfig.cmake.in
-+++ b/cmake/SEALConfig.cmake.in
-@@ -89,8 +89,10 @@ if(NOT SEAL_CARRY_DEPS)
-         seal_find_dependency(ZLIB)
-     endif()
-     if(SEAL_USE_ZSTD)
--        seal_find_dependency(zstd)
--        if(NOT TARGET zstd::libzstd_static)
-+        include(FindPkgConfig)
-+        pkg_search_module("libzstd" REQUIRED IMPORTED_TARGET "libzstd")
-+        set(zstd_static "PkgConfig::libzstd")
-+        if(0)
-             if(TARGET libzstd)
-                 get_target_property(libzstd_type libzstd TYPE)
-                 if(libzstd_type STREQUAL "SHARED")

+ 0 - 18
packages/m/microsoft-seal/patches/4.1.2/find-zstd.patch

@@ -1,18 +0,0 @@
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index de598c7..0035bf7 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -190,9 +190,10 @@ if(SEAL_USE_ZSTD)
-         seal_fetch_thirdparty_content(ExternalZSTD)
-         set(zstd_static "libzstd_static")
-     else()
--        find_package(zstd CONFIG)
--        if(NOT zstd_FOUND)
--            message(FATAL_ERROR "Zstandard: not found")
-+        include(FindPkgConfig)
-+        pkg_search_module("libzstd" REQUIRED IMPORTED_TARGET "libzstd")
-+        if(libzstd_FOUND)
-+            set(zstd_static "PkgConfig::libzstd")
-         else()
-             if(TARGET zstd::libzstd_static)
-                 set(zstd_static "zstd::libzstd_static")

+ 0 - 3
packages/m/microsoft-seal/xmake.lua

@@ -31,9 +31,6 @@ package("microsoft-seal")
     on_load(function (package)
         if package:config("zstd") then
             package:add("deps", "zstd")
-            package:add("deps", (is_subhost("windows") and "pkgconf") or "pkg-config")
-            package:add("patches", "4.1.2", "patches/4.1.2/find-zstd.patch", "d7261a78d6cc873b3563610429dbfa7eb8c67fa410825eb1b180a06f02dd5f1e")
-            package:add("patches", "4.1.2", "patches/4.1.2/cmake-config-zstd.patch", "a2291f35ee40ef52c021e709dcab2a5414381c0eafeb36efce15ecb4b423114a")
         end
         if package:config("zlib") then
             package:add("deps", "zlib")

+ 23 - 0
packages/z/zstd/patches/1.5.6/fix-rc-build.patch

@@ -0,0 +1,23 @@
+From fd5f8106a58601a963ee816e6a57aa7c61fafc53 Mon Sep 17 00:00:00 2001
+From: BadWolf <[email protected]>
+Date: Sat, 6 Apr 2024 00:05:58 +0200
+Subject: [PATCH] fix missing include folder for resource compiler
+
+---
+ build/cmake/lib/CMakeLists.txt | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/build/cmake/lib/CMakeLists.txt b/build/cmake/lib/CMakeLists.txt
+index 5d514ccb2e9..43b14d1753b 100644
+--- a/build/cmake/lib/CMakeLists.txt
++++ b/build/cmake/lib/CMakeLists.txt
+@@ -118,7 +118,7 @@ endmacro ()
+ 
+ # Define directories containing the library's public headers
+ set(PUBLIC_INCLUDE_DIRS ${LIBRARY_DIR})
+-
++set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /I ${LIBRARY_DIR}")
+ # Split project to static and shared libraries build
+ set(library_targets)
+ if (ZSTD_BUILD_SHARED)
+ 

+ 31 - 0
packages/z/zstd/port/xmake.lua

@@ -0,0 +1,31 @@
+option("ver", {default = "v1.5.6"})
+
+local version = get_config("ver")
+if version then
+    set_version(version)
+end
+
+add_rules("mode.debug", "mode.release", "asm")
+
+add_rules("utils.install.pkgconfig_importfiles", {filename = "libzstd.pc"})
+
+target("zstd")
+    set_kind("$(kind)")
+    add_files("lib/common/*.c")
+    add_files("lib/compress/*.c")
+    add_files("lib/decompress/*.c")
+    add_files("lib/dictBuilder/*.c")
+    add_headerfiles("lib/*.h")
+    add_defines("XXH_NAMESPACE=ZSTD_")
+
+    if is_kind("shared") and is_plat("windows") then
+        add_defines("ZSTD_DLL_EXPORT=1")
+    end
+
+    on_config(function (target)
+        if target:is_arch("x64", "x86_64") and target:has_tool("cc", "clang", "gcc") then
+            target:add("files", "lib/decompress/*.S")
+        else
+            target:add("defines", "ZSTD_DISABLE_ASM")
+        end
+    end)

+ 33 - 27
packages/z/zstd/xmake.lua

@@ -1,48 +1,54 @@
 package("zstd")
-
     set_homepage("https://www.zstd.net/")
     set_description("Zstandard - Fast real-time compression algorithm")
     set_license("BSD-3-Clause")
 
     set_urls("https://github.com/facebook/zstd/archive/refs/tags/$(version).tar.gz",
              "https://github.com/facebook/zstd.git")
+
     add_versions("v1.4.5", "734d1f565c42f691f8420c8d06783ad818060fc390dee43ae0a89f86d0a4f8c2")
     add_versions("v1.5.0", "0d9ade222c64e912d6957b11c923e214e2e010a18f39bec102f572e693ba2867")
     add_versions("v1.5.2", "f7de13462f7a82c29ab865820149e778cbfe01087b3a55b5332707abf9db4a6e")
     add_versions("v1.5.5", "98e9c3d949d1b924e28e01eccb7deed865eefebf25c2f21c702e5cd5b63b85e1")
     add_versions("v1.5.6", "30f35f71c1203369dc979ecde0400ffea93c27391bfd2ac5a9715d2173d92ff7")
 
-    on_load("windows", function (package)
-        if package:config("shared") then
+    add_patches("1.5.6", "patches/1.5.6/fix-rc-build.patch", "c898c652a4f48ce63b0b9da03406eb988de453f0c7b93f43f42f4e1e394eb17c")
+
+    add_configs("cmake", {description = "Use cmake buildsystem", default = true, type = "boolean"})
+    add_configs("tools", {description = "Build tools", default = false, type = "boolean"})
+    add_configs("contrib", {description = "Build contrib", default = false, type = "boolean"})
+
+    if is_plat("linux", "bsd") then
+        add_syslinks("pthread")
+    end
+
+    on_load(function (package)
+        -- Some downstream cmake package need patch: find_package(zstd CONFIG REQUIRED)
+        -- https://github.com/facebook/zstd/issues/3271
+        if package:config("cmake") then
+            package:add("deps", "cmake")
+        end
+        if package:is_plat("windows") and package:config("shared") then
             package:add("defines", "ZSTD_DLL_IMPORT=1")
         end
     end)
 
     on_install(function (package)
-        io.writefile("xmake.lua", ([[
-            set_version("%s")
-            add_rules("mode.debug", "mode.release", "asm")
-            add_rules("utils.install.pkgconfig_importfiles", {filename = "libzstd.pc"})
-            target("zstd")
-                set_kind("$(kind)")
-                add_files("lib/common/*.c")
-                add_files("lib/compress/*.c")
-                add_files("lib/decompress/*.c")
-                add_files("lib/dictBuilder/*.c")
-                add_headerfiles("lib/*.h")
-                add_defines("XXH_NAMESPACE=ZSTD_")
-                if is_kind("shared") and is_plat("windows") then
-                    add_defines("ZSTD_DLL_EXPORT=1")
-                end
-                on_config(function (target)
-                    if target:is_arch("x64", "x86_64") and target:has_tool("cc", "clang", "gcc") then
-                        target:add("files", "lib/decompress/*.S")
-                    else
-                        target:add("defines", "ZSTD_DISABLE_ASM")
-                    end
-                end)
-        ]]):format(package:version_str()))
-        import("package.tools.xmake").install(package)
+        if not package:config("cmake") then
+            os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
+            import("package.tools.xmake").install(package, {ver = package:version_str()})
+            return
+        end
+
+        os.cd("build/cmake")
+
+        local configs = {"-DBUILD_TESTING=OFF"}
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+        table.insert(configs, "-DZSTD_BUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
+        table.insert(configs, "-DZSTD_BUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
+        table.insert(configs, "-DZSTD_BUILD_PROGRAMS=" .. (package:config("tools") and "ON" or "OFF"))
+        table.insert(configs, "-DZSTD_BUILD_CONTRIB=" .. (package:config("contrib") and "ON" or "OFF"))
+        import("package.tools.cmake").install(package, configs)
     end)
 
     on_test(function (package)