summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-09-27 23:32:18 +0800
committerruki <[email protected]>2023-09-27 23:32:18 +0800
commitda714a6b9bad1fb0608445bcb48c079bf0202ea8 (patch)
tree41fc6a5af44256384be1249f9a1d302f23667263
parentfe931254f8f5fc0003b3fef14414b8adfa3adfd9 (diff)
get linkorders
-rw-r--r--tests/projects/c++/linkorders/xmake.lua6
-rw-r--r--xmake/core/tool/builder.lua40
2 files changed, 43 insertions, 3 deletions
diff --git a/tests/projects/c++/linkorders/xmake.lua b/tests/projects/c++/linkorders/xmake.lua
index b3df5f820..7742a1aee 100644
--- a/tests/projects/c++/linkorders/xmake.lua
+++ b/tests/projects/c++/linkorders/xmake.lua
@@ -12,7 +12,11 @@ target("demo")
add_deps("foo")
add_files("src/main.cpp")
if is_plat("linux", "macosx") then
- add_syslinks("pthread", "m")
+ add_syslinks("pthread", "m", "dl")
end
+ if is_plat("macosx") then
+ add_frameworks("Foundation", "CoreFoundation")
+ end
+ add_linkorders("framework::Foundation", "png16", "foo", "m", "pthread")
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index 1822efea0..ee5fa5972 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -408,10 +408,10 @@ function builder:_add_flags_from_language(flags, target, getters)
end
end
- -- process link orders
+ -- sort links
local kind = self:kind()
if (kind == "ld" or kind == "sh") and target and target:type() == "target" then
- utils.dump(items)
+ self:_sort_links_of_items(target, items)
end
-- get flags from the items
@@ -436,6 +436,42 @@ function builder:_add_flags_from_language(flags, target, getters)
end
end
+-- sort links of items
+function builder:_sort_links_of_items(target, items)
+ local linkorders = target:get("linkorders")
+ if linkorders then
+ local links = {}
+ local link_mapper
+ local framework_mapper
+ table.remove_if(items, function (_, item)
+ local name = item.name
+ local removed = false
+ for _, value in ipairs(item.values) do
+ if name == "links" or name == "syslinks" then
+ table.insert(links, value)
+ link_mapper = item.mapper
+ removed = true
+ elseif name == "frameworks" then
+ table.insert(links, "framework::" .. value)
+ framework_mapper = item.mapper
+ removed = true
+ end
+ end
+ return removed
+ end)
+ utils.dump(links)
+ for _, link in ipairs(links) do
+ if link:startswith("framework::") then
+ link = link:sub(12)
+ table.insert(items, {name = "frameworks", values = table.wrap(link), check = false, multival = false, mapper = framework_mapper})
+ else
+ table.insert(items, {name = "links", values = table.wrap(link), check = false, multival = false, mapper = link_mapper})
+ end
+ end
+ utils.dump(links)
+ end
+end
+
-- preprocess flags
function builder:_preprocess_flags(flags)