diff options
| author | ruki <[email protected]> | 2023-09-30 15:12:57 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-09-30 15:12:57 +0800 |
| commit | c19eb9cdad616568851a9e9f9e31832938cae8ed (patch) | |
| tree | 5a0c3320b3efc2206a0a80b1849ea544badd8a07 | |
| parent | 2a389d399b2437f8561d650e1badadce51a14a82 (diff) | |
improve linkgroups
| -rw-r--r-- | tests/projects/c++/linkorders/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 18 |
2 files changed, 12 insertions, 8 deletions
diff --git a/tests/projects/c++/linkorders/xmake.lua b/tests/projects/c++/linkorders/xmake.lua index 8a5f1d18c..755e75f51 100644 --- a/tests/projects/c++/linkorders/xmake.lua +++ b/tests/projects/c++/linkorders/xmake.lua @@ -24,6 +24,6 @@ target("demo") end add_linkorders("framework::Foundation", "png16", "foo") add_linkorders("dl", "linkgroup::syslib") - add_linkgroups("m", "pthread", {name = "syslib"}) + add_linkgroups("m", "pthread", {name = "syslib", group = true}) diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 7cff1d48d..0c13552e9 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -306,20 +306,24 @@ end -- make the link group flag function nf_linkgroup(self, linkgroup, target) - local flags = {} + local linkflags = {} for _, lib in ipairs(linkgroup) do - table.insert(flags, nf_link(self, lib)) + table.insert(linkflags, nf_link(self, lib)) end + local flags = {} if not target:is_plat("macosx", "windows", "mingw") then + local group = target:extraconf("linkgroups", linkgroup, "group") + if group then + table.join2(flags, "-Wl,--start-group", linkflags, "-Wl,--end-group") + end local whole = target:extraconf("linkgroups", linkgroup, "whole") if whole then - table.insert(flags, 1, "-Wl,--whole-archive") - table.insert(flags, "-Wl,--no-whole-archive") - else - table.insert(flags, 1, "-Wl,--start-group") - table.insert(flags, "-Wl,--end-group") + table.join2(flags, "-Wl,--whole-archive", linkflags, "-Wl,--no-whole-archive") end end + if #flags == 0 then + flags = linkflags + end return flags end |
