diff options
| author | ruki <[email protected]> | 2023-10-26 22:54:31 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-10-26 22:54:31 +0800 |
| commit | 320f0962992db825d9609d237188c14e28f608de (patch) | |
| tree | b1b9d4a294fd0f9f2c9a7a20c3343227dce92fef | |
| parent | b6631aa5791471e0403314fae8dfe44d9408baec (diff) | |
add extraconf_from
| -rw-r--r-- | tests/apis/target_get_from/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 60 |
2 files changed, 62 insertions, 0 deletions
diff --git a/tests/apis/target_get_from/xmake.lua b/tests/apis/target_get_from/xmake.lua index e583dca00..5e77a0382 100644 --- a/tests/apis/target_get_from/xmake.lua +++ b/tests/apis/target_get_from/xmake.lua @@ -12,6 +12,7 @@ target("foo") add_defines("foo") add_defines("FOO", {public = true}) add_options("bar") + add_linkgroups("m", "pthread", {group = true}) target("test") set_kind("binary") @@ -27,5 +28,6 @@ target("test") print("dep::foo/option::*", target:get_from("defines", "dep::foo/option::*")) print("*", target:get_from("defines", "*")) print("package::zlib", target:get_from("links", "package::zlib")) + print("extraconf(dep::foo)", target:extraconf_from("dep::foo", "linkgroups")) end) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index f58c2de71..96f36ac6d 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -679,6 +679,66 @@ function _instance:extraconf_set(name, item, key, value) self._INFO:extraconf_set(name, item, key, value) end +-- get the extra configuration from the given source +-- +-- e.g. +-- +-- only from the current target: +-- target:extraconf_from("links") +-- target:extraconf_from("links", "self") +-- +-- from the given dep: +-- target:extraconf_from("links", "dep::foo") +-- +-- from the given option: +-- target:extraconf_from("links", "option::foo") +-- +-- from the given package: +-- target:extraconf_from("links", "package::foo") +-- +-- from the given dep/option, dep/package +-- target:extraconf_from("links", "dep::foo/option::bar") +-- target:extraconf_from("links", "dep::foo/package::bar") +-- +function _instance:extraconf_from(source, name, item, key) + source = source or "self" + if source == "self" then + return self:extraconf(name, item, key) + elseif source:startswith("dep::") then + local depname = source:split("::", {plain = true, limit = 2})[2] + local depsource + local splitinfo = depname:split("/", {plain = true}) + if #splitinfo == 2 then + depname = splitinfo[1] + depsource = splitinfo[2] + end + local dep = self:dep(depname) + if dep then + -- e.g. + -- dep::foo/option::bar + -- dep::foo/package::bar + if depsource then + return dep:extraconf_from(dep_source, name, item, key) + else + -- dep::foo + return dep:extraconf(name, item, key) + end + end + elseif source:startswith("option::") then + local opt_ = self:opt(optname, opt) + if opt_ then + return opt_:extraconf(name, item, key) + end + elseif source:startswith("package::") then + local pkg = self:pkg(pkgname, opt) + if pkg then + return pkg:extraconf(name, item, key) + end + else + os.raise("target:extraconf_from(): unknown source %s", source) + end +end + -- get configuration source information of the given api item function _instance:sourceinfo(name, item) return self._INFO:sourceinfo(name, item) |
