summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-09-28 22:56:17 +0800
committerruki <[email protected]>2023-09-28 22:56:17 +0800
commit2aa8a4a793f3a7281487d6bc8334f975fa6bd26d (patch)
treeb9ecd6a5d7bfab13cf702b97a8a14c4164f2dc66
parent6ffb48dd54c6d2d4e6168fac56943481d58e29c4 (diff)
add whole groups
-rw-r--r--tests/projects/c++/linkorders/xmake.lua9
-rw-r--r--xmake/core/base/interpreter.lua10
-rw-r--r--xmake/core/base/scopeinfo.lua13
-rw-r--r--xmake/languages/c++/xmake.lua2
-rw-r--r--xmake/languages/dlang/xmake.lua2
-rw-r--r--xmake/languages/objc++/xmake.lua2
-rw-r--r--xmake/modules/core/tools/gcc.lua19
7 files changed, 47 insertions, 10 deletions
diff --git a/tests/projects/c++/linkorders/xmake.lua b/tests/projects/c++/linkorders/xmake.lua
index 09fd30378..0742f76c7 100644
--- a/tests/projects/c++/linkorders/xmake.lua
+++ b/tests/projects/c++/linkorders/xmake.lua
@@ -2,6 +2,11 @@ add_rules("mode.debug", "mode.release")
add_requires("libpng")
+target("bar")
+ set_kind("shared")
+ add_files("src/foo.cpp")
+ add_linkgroups("m", "pthread", {whole = true})
+
target("foo")
set_kind("static")
add_files("src/foo.cpp")
@@ -18,7 +23,7 @@ target("demo")
add_frameworks("Foundation", "CoreFoundation")
end
add_linkorders("framework::Foundation", "png16", "foo")
- add_linkorders("m", "pthread")
- add_linkgroups("m", "pthread")
+ add_linkorders("dl", "group::syslib")
+ add_linkgroups("m", "pthread", {name = "syslib"})
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index ab25e927e..6e30552b8 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -1236,10 +1236,11 @@ function interpreter:api_register_set_groups(scope_kind, ...)
scope[name] = values
-- save extra config
- if extra_config and extra_config.name then
+ if extra_config then
scope["__extra_" .. name] = scope["__extra_" .. name] or {}
local extrascope = scope["__extra_" .. name]
- extrascope[extra_config.name] = extra_config
+ local key = table.concat(values, "_")
+ extrascope[key] = extra_config
end
end
@@ -1270,10 +1271,11 @@ function interpreter:api_register_add_groups(scope_kind, ...)
table.insert(scope[name], values)
-- save extra config
- if extra_config and extra_config.name then
+ if extra_config then
scope["__extra_" .. name] = scope["__extra_" .. name] or {}
local extrascope = scope["__extra_" .. name]
- extrascope[extra_config.name] = extra_config
+ local key = table.concat(values, "_")
+ extrascope[key] = extra_config
end
end
diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua
index 8254ffc98..0ca401237 100644
--- a/xmake/core/base/scopeinfo.lua
+++ b/xmake/core/base/scopeinfo.lua
@@ -210,10 +210,11 @@ function _instance:_api_set_groups(name, ...)
scope[name] = values
-- save extra config
- if extra_config and extra_config.name then
+ if extra_config then
scope["__extra_" .. name] = scope["__extra_" .. name] or {}
local extrascope = scope["__extra_" .. name]
- extrascope[extra_config.name] = extra_config
+ local key = table.concat(values, "_")
+ extrascope[key] = extra_config
end
end
@@ -241,10 +242,11 @@ function _instance:_api_add_groups(name, ...)
scope[name] = self:_api_handle(name, scope[name])
-- save extra config
- if extra_config and extra_config.name then
+ if extra_config then
scope["__extra_" .. name] = scope["__extra_" .. name] or {}
local extrascope = scope["__extra_" .. name]
- extrascope[extra_config.name] = extra_config
+ local key = table.concat(values, "_")
+ extrascope[key] = extra_config
end
end
@@ -690,6 +692,9 @@ function _instance:extraconf(name, item, key)
local value = extraconf
if item then
value = extraconf and extraconf[item] or nil
+ if value == nil and extraconf and type(item) == "table" then
+ value = extraconf[table.concat(item, "_")]
+ end
if value and key then
value = value[key]
end
diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua
index e07b9e294..be6dc8bd1 100644
--- a/xmake/languages/c++/xmake.lua
+++ b/xmake/languages/c++/xmake.lua
@@ -75,6 +75,7 @@ language("c++")
, "toolchain.frameworkdirs"
, "config.links"
, "target.links"
+ , "target.linkgroups"
, "toolchain.links"
, "config.frameworks"
, "target.frameworks"
@@ -98,6 +99,7 @@ language("c++")
, "toolchain.frameworkdirs"
, "config.links"
, "target.links"
+ , "target.linkgroups"
, "toolchain.links"
, "config.frameworks"
, "target.frameworks"
diff --git a/xmake/languages/dlang/xmake.lua b/xmake/languages/dlang/xmake.lua
index 9749c0d15..d6b4be932 100644
--- a/xmake/languages/dlang/xmake.lua
+++ b/xmake/languages/dlang/xmake.lua
@@ -52,6 +52,7 @@ language("dlang")
, "toolchain.rpathdirs"
, "config.links"
, "target.links"
+ , "target.linkgroups"
, "toolchain.links"
, "config.syslinks"
, "target.syslinks"
@@ -65,6 +66,7 @@ language("dlang")
, "toolchain.linkdirs"
, "config.links"
, "target.links"
+ , "target.linkgroups"
, "toolchain.links"
, "config.syslinks"
, "target.syslinks"
diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua
index 00fae204b..e1cb6ffa5 100644
--- a/xmake/languages/objc++/xmake.lua
+++ b/xmake/languages/objc++/xmake.lua
@@ -93,6 +93,7 @@ language("objc++")
, "toolchain.frameworkdirs"
, "config.links"
, "target.links"
+ , "target.linkgroups"
, "toolchain.links"
, "config.frameworks"
, "target.frameworks"
@@ -113,6 +114,7 @@ language("objc++")
, "toolchain.frameworkdirs"
, "config.links"
, "target.links"
+ , "target.linkgroups"
, "toolchain.links"
, "config.frameworks"
, "target.frameworks"
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 93525848f..864e894e5 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -304,6 +304,25 @@ function nf_syslink(self, lib)
return nf_link(self, lib)
end
+-- make the link group flag
+function nf_linkgroups(self, libs, target)
+ local flags = {}
+ for _, lib in ipairs(libs) do
+ table.insert(flags, nf_link(self, lib))
+ end
+ if not target:is_plat("macosx", "windows", "mingw") then
+ local whole = target:extraconf("linkgroups", libs, "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")
+ end
+ end
+ return {flags}
+end
+
-- make the linkdir flag
function nf_linkdir(self, dir)
return {"-L" .. path.translate(dir)}