diff options
| author | ruki <[email protected]> | 2017-08-14 17:40:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-08-14 17:40:39 +0800 |
| commit | 18e041e57463c847158f3c3d67e7e75e22b082f9 (patch) | |
| tree | e1b1956f5fb9a4aab0fb6db6e155afd637956972 | |
| parent | 06aaf7d5a583fd5a6574661e4b58fbd9f431817a (diff) | |
inherit links and linkdirs from the dependent target and option
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | core/src/demo/xmake.lua | 2 | ||||
| -rw-r--r-- | core/src/xmake/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 114 |
4 files changed, 68 insertions, 52 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d57bd6580..b1c11c551 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Changes * Improve `add_files` to configure the compile option of the given files +* Inherit links and linkdirs from the dependent targets and options ### Bugs fixed @@ -333,6 +334,7 @@ ### 改进 * 改进`add_files`,支持对files粒度进行编译选项的各种配置,更加灵活。 +* 从依赖的target和option中继承links和linkdirs。 ### Bugs修复 diff --git a/core/src/demo/xmake.lua b/core/src/demo/xmake.lua index 57453a87e..e7fd6cbc9 100644 --- a/core/src/demo/xmake.lua +++ b/core/src/demo/xmake.lua @@ -21,7 +21,7 @@ target("demo") -- link readline if not is_plat("windows") then - add_links("readline") +-- add_links("readline") end -- add packages diff --git a/core/src/xmake/xmake.lua b/core/src/xmake/xmake.lua index cf40ab3c3..b22712136 100644 --- a/core/src/xmake/xmake.lua +++ b/core/src/xmake/xmake.lua @@ -26,5 +26,5 @@ target("xmake") add_files("**.c") -- add cfunc - add_cfunc("API", "readline", nil, {"readline/readline.h"}, "readline") + add_cfunc("API", "readline", "readline", {"readline/readline.h"}, "readline") 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? |
