summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-11-22 00:37:37 +0800
committerruki <[email protected]>2018-11-21 21:45:46 +0800
commite940f6ee0d984a69ccc253f30a14cc0da991d05e (patch)
treefba1288008dc4282ebf0d232839211606ed31caf
parente18261cb79944a7797e174816f345e4ed2a20d1d (diff)
attach package info
-rw-r--r--xmake/core/project/project.lua3
-rw-r--r--xmake/core/project/target.lua42
-rw-r--r--xmake/core/tool/builder.lua26
3 files changed, 57 insertions, 14 deletions
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 71920be07..5178315e8 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -226,9 +226,6 @@ function project.interpreter()
}
}
- -- register api: add_packages() to target
- interp:api_register_builtin("add_packages", interp:_api_within_scope("target", "add_options"))
-
-- register api: deprecated
deprecated_project.api_register(interp)
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 907ba0054..95d5bffd1 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -34,6 +34,7 @@ local deprecated = require("base/deprecated")
local rule = require("project/rule")
local option = require("project/option")
local config = require("project/config")
+local requireinfo = require("project/requireinfo")
local tool = require("tool/tool")
local linker = require("tool/linker")
local compiler = require("tool/compiler")
@@ -66,6 +67,7 @@ function target.apis()
, "target.add_deps"
, "target.add_rules"
, "target.add_options"
+ , "target.add_packages"
, "target.add_imports"
, "target.add_languages"
, "target.add_vectorexts"
@@ -502,24 +504,52 @@ function target:options()
return self._OPTIONS
end
- -- load options
+ -- load options if be enabled
self._OPTIONS = {}
for _, name in ipairs(table.wrap(self:get("options"))) do
-
- -- get option if be enabled
local opt = nil
if config.get(name) then opt = option.load(name) end
- if nil ~= opt then
-
- -- insert it and must ensure the order for linking
+ if opt then
table.insert(self._OPTIONS, opt)
end
end
+ -- load options from packages if no require info, be compatible with the option package in (*.pkg)
+ for _, name in ipairs(table.wrap(self:get("packages"))) do
+ if not requireinfo.load(name) then
+ local opt = nil
+ if config.get(name) then opt = option.load(name) end
+ if opt then
+ table.insert(self._OPTIONS, opt)
+ end
+ end
+ end
+
-- get it
return self._OPTIONS
end
+-- get the required packages
+function target:packages()
+
+ -- attempt to get it from cache first
+ if self._PACKAGES then
+ return self._PACKAGES
+ end
+
+ -- load packages if be enabled
+ self._PACKAGES = {}
+ for _, name in ipairs(table.wrap(self:get("packages"))) do
+ local package = requireinfo.load(name)
+ if package and package:enabled() then
+ table.insert(self._PACKAGES, package)
+ end
+ end
+
+ -- get it
+ return self._PACKAGES
+end
+
-- get the object files directory
function target:objectdir(onlyroot)
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index e7defb63e..4f332b9ab 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -198,9 +198,16 @@ function builder:_addflags_from_config(flags)
end
-- add flags from the option
-function builder:_addflags_from_option(flags, target)
+function builder:_addflags_from_option(flags, opt)
for _, flagkind in ipairs(self:_flagkinds()) do
- table.join2(flags, self:_mapflags(target:get(flagkind)))
+ table.join2(flags, self:_mapflags(opt:get(flagkind)))
+ end
+end
+
+-- add flags from the package
+function builder:_addflags_from_package(flags, pkg)
+ for _, flagkind in ipairs(self:_flagkinds()) do
+ table.join2(flags, self:_mapflags(pkg:get(flagkind)))
end
end
@@ -225,11 +232,18 @@ function builder:_addflags_from_target(flags, target)
targetflags = {}
self:_addflags_from_language(targetflags, target)
- -- add the flags for the target options
+ -- add flags for the target
if target:type() == "target" then
+
+ -- add flags from options
for _, opt in ipairs(target:options()) do
self:_addflags_from_option(targetflags, opt)
end
+
+ -- add flags from packages
+ for _, pkg in ipairs(target:packages()) do
+ self:_addflags_from_package(targetflags, pkg)
+ end
end
-- add the target flags
@@ -310,13 +324,15 @@ function builder:_addflags_from_language(flags, target, getters)
end
, option = function (name)
- -- is target? get flagvalues of the attached options
+ -- is target? get flagvalues of the attached options and packages
local results = {}
if target:type() == "target" then
-
for _, opt in ipairs(target:options()) do
table.join2(results, table.wrap(opt:get(name)))
end
+ for _, pkg in ipairs(target:packages()) do
+ table.join2(results, table.wrap(pkg:get(name)))
+ end
-- is option? get flagvalues of option with given flagname
elseif target:type() == "option" then