summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2017-08-14 17:40:39 +0800
committerruki <[email protected]>2017-08-14 17:40:39 +0800
commit18e041e57463c847158f3c3d67e7e75e22b082f9 (patch)
treee1b1956f5fb9a4aab0fb6db6e155afd637956972 /xmake
parent06aaf7d5a583fd5a6574661e4b58fbd9f431817a (diff)
inherit links and linkdirs from the dependent target and option
Diffstat (limited to 'xmake')
-rw-r--r--xmake/core/tool/builder.lua114
1 files changed, 64 insertions, 50 deletions
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index e648a67d0..d9c12dda6 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -112,11 +112,72 @@ end
-- get the flag kinds
function builder:_flagkinds()
-
- -- get it
return self._FLAGKINDS
end
+-- inherts from target deps
+function builder:_inherit_from_target(values, target, name)
+ table.join2(values, target:get(name))
+ if target.options then
+ for _, opt in ipairs(target:options()) do
+ table.join2(values, opt:get(name))
+ end
+ end
+end
+
+-- inherts from target deps
+function builder:_inherit_from_targetdeps(results, target, flagname)
+
+ -- for all target deps
+ local orderdeps = target:orderdeps()
+ local total = #orderdeps
+ for idx, _ in ipairs(orderdeps) do
+
+ -- reverse deps order for links
+ local dep = orderdeps[total + 1 - idx]
+
+ -- is static or shared target library? link it
+ local depkind = dep:get("kind")
+ local targetkind = target:get("kind")
+ if depkind == "static" or depkind == "shared" then
+ if flagname == "links" and (targetkind == "binary" or targetkind == "shared") then
+
+ -- add dependent link
+ table.insert(results, dep:name())
+
+ -- inherit links from the depdent target
+ self:_inherit_from_target(results, dep, "links")
+
+ elseif flagname == "linkdirs" and (targetkind == "binary" or targetkind == "shared") then
+
+ -- add dependent linkdirs
+ table.insert(results, path.directory(dep:targetfile()))
+
+ -- inherit linkdirs from the depdent target
+ self:_inherit_from_target(results, dep, "linkdirs")
+
+ elseif flagname == "rpathdirs" and targetkind == "binary" then
+
+ -- add dependent rpathdirs (need absolute path)
+ table.insert(results, path.directory(path.absolute(dep:targetfile(), os.projectdir())))
+
+ elseif flagname == "includedirs" then
+
+ -- add dependent headerdir
+ if dep:get("headers") and os.isdir(dep:headerdir()) then
+ table.insert(results, dep:headerdir())
+ end
+
+ -- add dependent configheader directory
+ local configheader = dep:configheader()
+ if configheader and os.isfile(configheader) then
+ table.insert(results, path.directory(configheader))
+ end
+ end
+ end
+ end
+end
+
-- add flags from the configure
function builder:_addflags_from_config(flags)
for _, flagkind in ipairs(self:_flagkinds()) do
@@ -172,53 +233,6 @@ function builder:_addflags_from_target(flags, target)
table.join2(flags, targetflags)
end
--- add flags from target deps
-function builder:_addflags_from_targetdeps(results, target, flagname)
-
- -- for all target deps
- local orderdeps = target:orderdeps()
- local total = #orderdeps
- for idx, _ in ipairs(orderdeps) do
-
- -- reverse deps order for links
- local dep = orderdeps[total + 1 - idx]
-
- -- is static or shared target library? link it
- local depkind = dep:get("kind")
- local targetkind = target:get("kind")
- if depkind == "static" or depkind == "shared" then
- if flagname == "links" and (targetkind == "binary" or targetkind == "shared") then
-
- -- add dependent link
- table.insert(results, dep:name())
-
- elseif flagname == "linkdirs" and (targetkind == "binary" or targetkind == "shared") then
-
- -- add dependent linkdirs
- table.insert(results, path.directory(dep:targetfile()))
-
- elseif flagname == "rpathdirs" and targetkind == "binary" then
-
- -- add dependent rpathdirs (need absolute path)
- table.insert(results, path.directory(path.absolute(dep:targetfile(), os.projectdir())))
-
- elseif flagname == "includedirs" then
-
- -- add dependent headerdir
- if dep:get("headers") and os.isdir(dep:headerdir()) then
- table.insert(results, dep:headerdir())
- end
-
- -- add dependent configheader directory
- local configheader = dep:configheader()
- if configheader and os.isfile(configheader) then
- table.insert(results, path.directory(configheader))
- end
- end
- end
- end
-end
-
-- add flags from the argument option
function builder:_addflags_from_argument(flags, target, args)
@@ -249,7 +263,7 @@ function builder:_addflags_from_language(flags, target, getters)
-- link? add includes and links of all dependent targets
if name == "links" or name == "linkdirs" or name == "rpathdirs" or name == "includedirs" then
- self:_addflags_from_targetdeps(results, target, name)
+ self:_inherit_from_targetdeps(results, target, name)
end
-- ok?