summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-03-09 22:04:08 +0800
committerruki <[email protected]>2019-03-09 22:04:08 +0800
commit24de4d027e54752ef54803df5c283f480ed04f60 (patch)
treef3e9621b24ec05f4727f7978ab0c97430810efc5
parent7a68e6ad25e28c1b1c375147bb0f543ef3a47862 (diff)
inherit value from target deps
-rw-r--r--xmake/core/project/option.lua5
-rw-r--r--xmake/core/project/target.lua5
-rw-r--r--xmake/core/tool/builder.lua148
-rw-r--r--xmake/core/tool/compiler.lua16
-rw-r--r--xmake/core/tool/linker.lua18
5 files changed, 95 insertions, 97 deletions
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index e76fe2237..90fa2d3fa 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -310,6 +310,11 @@ function _instance:del(name, ...)
self._INFO:apival_del(name, ...)
end
+-- get the extra configuration
+function _instance:extraconf(name, item, key)
+ return self._INFO:extraconf(name, item, key)
+end
+
-- get the given dependent option
function _instance:dep(name)
local deps = self:deps()
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 3dd17258d..1bf85014d 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -452,11 +452,6 @@ function _instance:orderdeps()
return self._ORDERDEPS
end
--- get the given dependent config
-function _instance:depconfig(name)
- return self:extraconf("deps", name)
-end
-
-- get target rules
function _instance:rules()
return self._RULES
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index a7b664b4c..8e80f8ada 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -115,34 +115,8 @@ function builder:_flagkinds()
return self._FLAGKINDS
end
--- inherts from target packages
-function builder:_inherit_from_targetpkgs(values, target, name)
- for _, pkg in ipairs(target:orderpkgs()) do
- -- uses them instead of the builtin configs if exists extra package config
- -- e.g. `add_packages("xxx", {links = "xxx"})`
- local configinfo = target:pkgconfig(pkg:name())
- if configinfo and configinfo[name] then
- table.join2(values, configinfo[name])
- else
- -- uses the builtin package configs
- table.join2(values, pkg:get(name))
- end
- end
-end
-
--- inherts from target deps
-function builder:_inherit_from_target(values, target, name)
- table.join2(values, target:get(name))
- if target:type() == "target" then
- for _, opt in ipairs(target:orderopts()) do
- table.join2(values, opt:get(name))
- end
- self:_inherit_from_targetpkgs(values, target, name)
- end
-end
-
--- inherts from target deps
-function builder:_inherit_from_targetdeps(results, target, flagname)
+-- inherit links from target deps
+function builder:_inherit_links_from_targetdeps(results, target, flagname)
-- for all target deps
local orderdeps = target:orderdeps()
@@ -155,8 +129,8 @@ function builder:_inherit_from_targetdeps(results, target, flagname)
-- is static or shared target library? link it
local depkind = dep:targetkind()
local targetkind = target:targetkind()
- local depconfig = table.wrap(target:depconfig(dep:name()))
- if (depkind == "static" or depkind == "shared" or depkind == "object") and (depconfig.inherit == nil or depconfig.inherit) then
+ local depinherit = target:extraconf("deps", dep:name(), "inherit")
+ if (depkind == "static" or depkind == "shared" or depkind == "object") and (depinherit == nil or depinherit) then
if (flagname == "links" or flagname == "syslinks") and (targetkind == "binary" or targetkind == "shared") then
-- add dependent link
@@ -165,7 +139,7 @@ function builder:_inherit_from_targetdeps(results, target, flagname)
end
-- inherit links from the depdent target
- self:_inherit_from_target(results, dep, flagname)
+ self:_add_values_from_target(results, dep, flagname)
elseif flagname == "linkdirs" and (targetkind == "binary" or targetkind == "shared") then
@@ -175,7 +149,7 @@ function builder:_inherit_from_targetdeps(results, target, flagname)
end
-- inherit linkdirs from the depdent target
- self:_inherit_from_target(results, dep, flagname)
+ self:_add_values_from_target(results, dep, flagname)
elseif flagname == "rpathdirs" and (targetkind == "binary" or targetkind == "shared") then
@@ -212,58 +186,78 @@ function builder:_inherit_from_targetdeps(results, target, flagname)
end
end
---[[
--- inherts from target deps
-function builder:_inherit_from_targetdeps(results, target, flagname)
-
- -- for all target deps
+-- inherit values (only for public/interface) from target deps
+--
+-- e.g.
+-- add_defines("", {public = true})
+-- add_defines("", {interface = true})
+--
+function builder:_inherit_values_from_targetdeps(values, target, name)
local orderdeps = target:orderdeps()
local total = #orderdeps
for idx, _ in ipairs(orderdeps) do
-
- -- reverse deps order for links
local dep = orderdeps[total + 1 - idx]
+ local depinherit = target:extraconf("deps", dep:name(), "inherit")
+ if depinherit == nil or depinherit then
+ table.join2(values, dep:get(name, {interface = true}))
+ end
+ end
+end
- -- inherit this dep target?
- local depinherit = target:extraconfig("deps", dep:name(), "inherit")
- if (depinherit == nil or depinherit) then
+-- add values from target
+function builder:_add_values_from_target(values, target, name)
+ table.join2(values, target:get(name))
+ if target:type() == "target" then
+ self:_add_values_from_targetopts(values, target, name)
+ self:_add_values_from_targetpkgs(values, target, name)
+ end
+end
- dep:extraconf(flagname, "")
- table.join2(values, dep:get(name))
+-- add values from target options
+function builder:_add_values_from_targetopts(values, target, name)
+ for _, opt in ipairs(target:orderopts()) do
+ table.join2(values, table.wrap(opt:get(name)))
+ end
+end
- if dep:type() == "target" then
- for _, opt in ipairs(dep:orderopts()) do
- table.join2(values, opt:get(name))
- end
- self:_inherit_from_targetpkgs(values, dep, name)
- end
+-- add values from target packages
+function builder:_add_values_from_targetpkgs(values, target, name)
+ for _, pkg in ipairs(target:orderpkgs()) do
+ -- uses them instead of the builtin configs if exists extra package config
+ -- e.g. `add_packages("xxx", {links = "xxx"})`
+ local configinfo = target:pkgconfig(pkg:name())
+ if configinfo and configinfo[name] then
+ table.join2(values, configinfo[name])
+ else
+ -- uses the builtin package configs
+ table.join2(values, pkg:get(name))
end
end
-end]]
+end
-- add flags from the configure
-function builder:_addflags_from_config(flags)
+function builder:_add_flags_from_config(flags)
for _, flagkind in ipairs(self:_flagkinds()) do
table.join2(flags, config.get(flagkind))
end
end
-- add flags from the option
-function builder:_addflags_from_option(flags, opt)
+function builder:_add_flags_from_option(flags, opt)
for _, flagkind in ipairs(self:_flagkinds()) do
table.join2(flags, self:_mapflags(opt:get(flagkind), flagkind))
end
end
-- add flags from the package
-function builder:_addflags_from_package(flags, pkg)
+function builder:_add_flags_from_package(flags, pkg)
for _, flagkind in ipairs(self:_flagkinds()) do
table.join2(flags, self:_mapflags(pkg:get(flagkind), flagkind))
end
end
-- add flags from the target
-function builder:_addflags_from_target(flags, target)
+function builder:_add_flags_from_target(flags, target)
-- no target?
if not target then
@@ -279,33 +273,33 @@ function builder:_addflags_from_target(flags, target)
local targetflags = cache[key]
if not targetflags then
- -- add flags (named) and inherited flags from language
+ -- add flags from language
targetflags = {}
- self:_addflags_from_language(targetflags, target)
+ self:_add_flags_from_language(targetflags, target)
-- add flags for the target
if target:type() == "target" then
-- add flags from options
for _, opt in ipairs(target:orderopts()) do
- self:_addflags_from_option(targetflags, opt)
+ self:_add_flags_from_option(targetflags, opt)
end
-- add flags from packages
for _, pkg in ipairs(target:orderpkgs()) do
- self:_addflags_from_package(targetflags, pkg)
+ self:_add_flags_from_package(targetflags, pkg)
end
end
-- add the target flags
for _, flagkind in ipairs(self:_flagkinds()) do
-
- -- get flags and extra info
local flags = target:get(flagkind)
- local flagextra = target:get("__extra_" .. flagkind)
- if flagextra then
+ local extraconf = target:extraconf(flagkind)
+ if extraconf then
for _, flag in ipairs(table.wrap(flags)) do
- if (flagextra[flag] or {}).force then
+ -- force to add flags?
+ local flagconf = extraconf[flag]
+ if flagconf and flagconf.force then
table.join2(targetflags, flag)
else
table.join2(targetflags, self:_mapflags(flag, flagkind))
@@ -325,7 +319,7 @@ function builder:_addflags_from_target(flags, target)
end
-- add flags from the argument option
-function builder:_addflags_from_argument(flags, target, args)
+function builder:_add_flags_from_argument(flags, target, args)
-- add flags from the flag kinds (cxflags, ..)
for _, flagkind in ipairs(self:_flagkinds()) do
@@ -343,14 +337,19 @@ function builder:_addflags_from_argument(flags, target, args)
-- add flags (named) from the language
if target then
local key = target:type()
- self:_addflags_from_language(flags, target, {[key] = function (name) return args[name] end})
+ self:_add_flags_from_language(flags, target, {[key] = function (name) return args[name] end})
end
end
--- add flags (named) from the language
-function builder:_addflags_from_language(flags, target, getters)
+-- add flags from the language
+function builder:_add_flags_from_language(flags, target, getters)
-- init getters
+ --
+ -- e.g.
+ --
+ -- target.linkdirs => flags = getters("target")("linkdirs")
+ --
local getters = getters or
{
config = config.get
@@ -363,14 +362,15 @@ function builder:_addflags_from_language(flags, target, getters)
-- link? add includes and links of all dependent targets first
if name == "links" or name == "syslinks" or name == "linkdirs" or name == "rpathdirs" or name == "includedirs" then
- self:_inherit_from_targetdeps(results, target, name)
+ self:_inherit_links_from_targetdeps(results, target, name)
end
+ -- inherit flagvalues (public or interface) of all dependent targets
+ self:_inherit_values_from_targetdeps(results, target, name)
+
-- get flagvalues of target with given flagname
table.join2(results, target:get(name))
end
-
- -- ok?
return results
end
, option = function (name)
@@ -378,10 +378,8 @@ function builder:_addflags_from_language(flags, target, getters)
-- is target? get flagvalues of the attached options and packages
local results = {}
if target:type() == "target" then
- for _, opt in ipairs(target:orderopts()) do
- table.join2(results, table.wrap(opt:get(name)))
- end
- self:_inherit_from_targetpkgs(results, target, name)
+ self:_add_values_from_targetopts(results, target, name)
+ self:_add_values_from_targetpkgs(results, target, name)
-- is option? get flagvalues of option with given flagname
elseif target:type() == "option" then
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua
index 3030946ad..781e95e7d 100644
--- a/xmake/core/tool/compiler.lua
+++ b/xmake/core/tool/compiler.lua
@@ -45,7 +45,7 @@ function compiler:_language()
end
-- add flags from the platform
-function compiler:_addflags_from_platform(flags, targetkind)
+function compiler:_add_flags_from_platform(flags, targetkind)
-- add flags
local toolname = self:name()
@@ -60,7 +60,7 @@ function compiler:_addflags_from_platform(flags, targetkind)
end
-- add flags from the compiler
-function compiler:_addflags_from_compiler(flags, targetkind)
+function compiler:_add_flags_from_compiler(flags, targetkind)
for _, flagkind in ipairs(self:_flagkinds()) do
-- add compiler, e.g. cxflags
@@ -286,31 +286,31 @@ function compiler:compflags(opt)
-- add flags from the configure
local flags = {}
- self:_addflags_from_config(flags)
+ self:_add_flags_from_config(flags)
-- add flags for the target
- self:_addflags_from_target(flags, target)
+ self:_add_flags_from_target(flags, target)
-- add flags for the source file
if opt.sourcefile and target and target.fileconfig then
local fileconfig = target:fileconfig(opt.sourcefile)
if fileconfig then
- self:_addflags_from_argument(flags, target, fileconfig)
+ self:_add_flags_from_argument(flags, target, fileconfig)
end
end
-- add flags for the argument
if opt.config then
- self:_addflags_from_argument(flags, target, opt.config)
+ self:_add_flags_from_argument(flags, target, opt.config)
end
-- add flags from the platform
if target then
- self:_addflags_from_platform(flags, targetkind)
+ self:_add_flags_from_platform(flags, targetkind)
end
-- add flags from the compiler
- self:_addflags_from_compiler(flags, targetkind)
+ self:_add_flags_from_compiler(flags, targetkind)
-- preprocess flags
return self:_preprocess_flags(flags)
diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua
index 9b4ba4857..f7482888c 100644
--- a/xmake/core/tool/linker.lua
+++ b/xmake/core/tool/linker.lua
@@ -41,7 +41,7 @@ local builder = require("tool/builder")
local compiler = require("tool/compiler")
-- add flags from the platform
-function linker:_addflags_from_platform(flags, targetkind)
+function linker:_add_flags_from_platform(flags, targetkind)
-- add flags
local toolkind = self:kind()
@@ -57,7 +57,7 @@ function linker:_addflags_from_platform(flags, targetkind)
end
-- add flags from the compiler
-function linker:_addflags_from_compiler(flags, target, targetkind)
+function linker:_add_flags_from_compiler(flags, target, targetkind)
-- make flags
local flags_of_compiler = {}
@@ -85,7 +85,7 @@ function linker:_addflags_from_compiler(flags, target, targetkind)
end
-- add flags from the linker
-function linker:_addflags_from_linker(flags)
+function linker:_add_flags_from_linker(flags)
-- add flags
local toolkind = self:kind()
@@ -265,28 +265,28 @@ function linker:linkflags(opt)
-- add flags from the configure
local flags = {}
- self:_addflags_from_config(flags)
+ self:_add_flags_from_config(flags)
-- add flags for the target
- self:_addflags_from_target(flags, target)
+ self:_add_flags_from_target(flags, target)
-- add flags for the argument
if opt.config then
- self:_addflags_from_argument(flags, target, opt.config)
+ self:_add_flags_from_argument(flags, target, opt.config)
end
-- add flags from the platform
if target then
- self:_addflags_from_platform(flags, targetkind)
+ self:_add_flags_from_platform(flags, targetkind)
end
-- add flags from the compiler
if target then
- self:_addflags_from_compiler(flags, target, targetkind)
+ self:_add_flags_from_compiler(flags, target, targetkind)
end
-- add flags from the linker
- self:_addflags_from_linker(flags)
+ self:_add_flags_from_linker(flags)
-- preprocess flags
return self:_preprocess_flags(flags)