From e9ded8fe9241b33bebd4902424ac4e0278386a36 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 30 Mar 2024 00:56:15 +0800 Subject: [PATCH] improve to inherit links for object #4887 --- .../utils/inherit_links/inherit_links.lua | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/xmake/rules/utils/inherit_links/inherit_links.lua b/xmake/rules/utils/inherit_links/inherit_links.lua index 2bfd3076f50..b4080075626 100644 --- a/xmake/rules/utils/inherit_links/inherit_links.lua +++ b/xmake/rules/utils/inherit_links/inherit_links.lua @@ -65,9 +65,8 @@ function main(target) return end - -- export links and linkdirs - local targetkind = target:kind() - if targetkind == "shared" or targetkind == "static" then + -- export target links and linkdirs + if target:is_shared() or target:is_static() then local targetfile = target:targetfile() -- rust maybe will disable inherit links, only inherit linkdirs @@ -86,26 +85,26 @@ function main(target) -- we need to add includedirs to support import modules for golang _add_export_value(target, "includedirs", path.directory(targetfile)) end + end - -- we export all links and linkdirs in self/packages/options to the parent target by default - -- - -- @note we only export links for static target, - -- and we need to pass `{public = true}` to add_packages/add_links/... to export it if want to export links for shared target - -- - if target:data("inherit.links.exportlinks") ~= false then - if targetkind == "static" then - for _, name in ipairs({"rpathdirs", "frameworkdirs", "frameworks", "linkdirs", "links", "syslinks", "ldflags", "shflags"}) do - local values = _get_values_from_target(target, name) - if values and #values > 0 then - _add_export_values(target, name, values) - end + -- we export all links and linkdirs in self/packages/options to the parent target by default + -- + -- @note we only export links for static target, + -- and we need to pass `{public = true}` to add_packages/add_links/... to export it if want to export links for shared target + -- + if target:data("inherit.links.exportlinks") ~= false then + if target:is_static() or target:is_object() then + for _, name in ipairs({"rpathdirs", "frameworkdirs", "frameworks", "linkdirs", "links", "syslinks", "ldflags", "shflags"}) do + local values = _get_values_from_target(target, name) + if values and #values > 0 then + _add_export_values(target, name, values) end end end end -- export rpathdirs for all shared library - if targetkind == "binary" then + if target:is_binary() then local targetdir = target:targetdir() for _, dep in ipairs(target:orderdeps({inherit = true})) do if dep:kind() == "shared" then