Skip to content

Commit

Permalink
improve to inherit links for object #4887
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Mar 29, 2024
1 parent 50dbca6 commit e9ded8f
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions xmake/rules/utils/inherit_links/inherit_links.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e9ded8f

Please sign in to comment.