diff options
| author | ruki <[email protected]> | 2026-01-24 00:42:35 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-01-24 00:42:35 +0800 |
| commit | e885670797468308c5c9b5be330a5c62c818000c (patch) | |
| tree | 81fe23d6b06324a7760985a954afb77b0d7a1a00 /xmake/modules/private/utils/target.lua | |
| parent | 865ed17e98b3fa230b342138e3aaa6e9e5093cda (diff) | |
improve qt xpack
Diffstat (limited to 'xmake/modules/private/utils/target.lua')
| -rw-r--r-- | xmake/modules/private/utils/target.lua | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/xmake/modules/private/utils/target.lua b/xmake/modules/private/utils/target.lua index 728bd6016..0a3d8358f 100644 --- a/xmake/modules/private/utils/target.lua +++ b/xmake/modules/private/utils/target.lua @@ -23,6 +23,7 @@ import("core.base.option") import("core.base.hashset") import("core.project.config") import("core.project.project") +import("utils.binary.deplibs", {alias = "get_depend_libraries"}) -- Is this target has these tools? function has_tool(toolname, tools) @@ -204,3 +205,62 @@ function config_targets(opt) end end end + +function get_target_package_libfiles(target, opt) + opt = opt or {} + local libfiles = {} + for _, pkg in ipairs(target:orderpkgs(opt)) do + if pkg:enabled() and pkg:get("libfiles") then + for _, libfile in ipairs(table.wrap(pkg:get("libfiles"))) do + local filename = path.filename(libfile) + if filename:endswith(".dll") or filename:endswith(".so") or filename:find("%.so[%.%d+]+$") or filename:endswith(".dylib") then + table.insert(libfiles, libfile) + end + end + end + end + -- we can only reserve used libraries + if project.policy("install.strip_packagelibs") then + if target:is_binary() or target:is_shared() or opt.binaryfile then + -- we need to get all deplibs, e.g. app -> libfoo.so -> libbar.so ... + -- @see https://github.com/xmake-io/xmake/issues/5325#issuecomment-2242597732 + local deplibs = get_depend_libraries(opt.binaryfile or target:targetfile(), { + plat = target:plat(), arch = target:arch(), + recursive = true, resolve_path = true, resolve_hint_paths = libfiles}) + if deplibs then + local depends = hashset.from(deplibs) + table.remove_if(libfiles, function (_, libfile) return not depends:has(libfile) end) + end + end + end + return libfiles +end + +-- get target libraries +function get_target_libfiles(target, libfiles, binaryfile, refs, opt) + if not refs[target] then + local plaindeps = target:get("deps") + if plaindeps then + for _, depname in ipairs(plaindeps) do + local dep = target:dep(depname) + if dep then + if dep:is_shared() then + local depfile = dep:targetfile() + if os.isfile(depfile) then + table.insert(libfiles, depfile) + end + get_target_libfiles(dep, libfiles, dep:targetfile(), refs, opt) + elseif dep:is_library() then + get_target_libfiles(dep, libfiles, binaryfile, refs, opt) + end + end + end + end + table.join2(libfiles, get_target_package_libfiles(target, table.join({binaryfile = binaryfile}, opt))) + refs[target] = true + end +end + + + + |
