summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-01-11 22:45:24 +0800
committerruki <[email protected]>2019-01-11 10:32:29 +0800
commit3e3f60fb34f4171f8f16370ceb58ef9aae0785f1 (patch)
treefee37fdcf9d19d3efbc0ff2882c7a0c70d12754f
parent8fb4e12b6214cb8a21ce055c64e24bf0f47ce9e6 (diff)
mark add_cxsnippet as deprecated
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/core/project/deprecated/project.lua48
-rw-r--r--xmake/core/project/option.lua46
-rw-r--r--xmake/languages/c++/api.lua6
4 files changed, 94 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 43859f86c..3328cebc1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@
* [#264](https://github.com/tboox/xmake/issues/264): Support `xmake update dev` on windows
* [#293](https://github.com/tboox/xmake/issues/293): Add `xmake f/g --mingw=xxx` configuration option and improve to find_mingw
* [#301](https://github.com/tboox/xmake/issues/301): Improve precompiled header file
+* [#322](https://github.com/tboox/xmake/issues/322): Add `option.add_features`, `option.add_cxxsnippets` and `option.add_csnippets`
### Bugs fixed
@@ -554,6 +555,7 @@
* [#264](https://github.com/tboox/xmake/issues/264): 支持在windows上更新dev/master版本,`xmake update dev`
* [#293](https://github.com/tboox/xmake/issues/293): 添加`xmake f/g --mingw=xxx` 配置选线,并且改进find_mingw检测
* [#301](https://github.com/tboox/xmake/issues/301): 改进编译预处理头文件以及依赖头文件生成,编译速度提升30%
+* [#322](https://github.com/tboox/xmake/issues/322): 添加`option.add_features`, `option.add_cxxsnippets` 和 `option.add_csnippets`
### Bugs修复
diff --git a/xmake/core/project/deprecated/project.lua b/xmake/core/project/deprecated/project.lua
index 32c8bf0aa..8bf29610e 100644
--- a/xmake/core/project/deprecated/project.lua
+++ b/xmake/core/project/deprecated/project.lua
@@ -119,6 +119,48 @@ function deprecated_project._api_option_set_enable(interp, ...)
end)
end
+-- add_csnippet for option
+function deprecated_project._api_option_add_csnippet(interp, ...)
+
+ -- get api name
+ local apiname = "add_csnippet"
+
+ -- get api function
+ local apifunc = interp:_api_within_scope("option", apiname .. 's')
+ assert(apifunc)
+
+ -- register api
+ interp:api_register_builtin(apiname, function (...)
+
+ -- deprecated
+ deprecated.add(apiname .. "s(...)", apiname .. "(...)")
+
+ -- dispatch it
+ apifunc(...)
+ end)
+end
+
+-- add_cxxsnippet for option
+function deprecated_project._api_option_add_cxxsnippet(interp, ...)
+
+ -- get api name
+ local apiname = "add_cxxsnippet"
+
+ -- get api function
+ local apifunc = interp:_api_within_scope("option", apiname .. 's')
+ assert(apifunc)
+
+ -- register api
+ interp:api_register_builtin(apiname, function (...)
+
+ -- deprecated
+ deprecated.add(apiname .. "s(...)", apiname .. "(...)")
+
+ -- dispatch it
+ apifunc(...)
+ end)
+end
+
-- enable options?
function deprecated_project._api_is_option(interp, ...)
@@ -156,6 +198,12 @@ function deprecated_project.api_register(interp)
-- register api: set_enable() to option
interp:api_register("option", "set_enable", deprecated_project._api_option_set_enable)
+ -- register api: add_csnippet() to option
+ interp:api_register("option", "add_csnippet", deprecated_project._api_option_add_csnippet)
+
+ -- register api: add_cxxsnippet() to option
+ interp:api_register("option", "add_cxxsnippet", deprecated_project._api_option_add_cxxsnippet)
+
-- register api: set_values() to option
deprecated_interpreter._api_register_set_xxx_xxx(interp, "option", "enable")
deprecated_interpreter._api_register_set_xxx_xxx(interp, "option", "showmenu")
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index 5d59f91b4..637327389 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -31,7 +31,7 @@ local os = require("base/os")
local path = require("base/path")
local table = require("base/table")
local utils = require("base/utils")
-local option_ = require("base/option")
+local baseoption = require("base/option")
local config = require("project/config")
local cache = require("project/cache")
local linker = require("tool/linker")
@@ -76,6 +76,7 @@ function option.apis()
, "option.add_deps"
, "option.add_imports"
, "option.add_vectorexts"
+ , "option.add_features"
}
, script =
{
@@ -106,22 +107,29 @@ function option:_clear()
option._cache():set(self:name(), nil)
end
--- check option for c/c++
-function option:_cx_check()
+-- check option conditions
+function option:_do_check()
-- import check_cxsnippets()
self._check_cxsnippets = self._check_cxsnippets or sandbox_module.import("lib.detect.check_cxsnippets", {anonymous = true})
-- check for c and c++
+ local passed = false
for _, kind in ipairs({"c", "cxx"}) do
-- get conditions
local links = self:get("links")
- local snippets = self:get(kind .. "snippet")
+ local snippets = self:get(kind .. "snippets")
local types = self:get(kind .. "types")
local funcs = self:get(kind .. "funcs")
local includes = self:get(kind .. "includes")
+ -- TODO it is deprecated
+ local snippet = self:get(kind .. "snippet")
+ if snippet then
+ snippets = table.join(snippets or {}, snippet)
+ end
+
-- need check it?
if snippets or types or funcs or links or includes then
@@ -139,12 +147,38 @@ function option:_cx_check()
-- passed?
if results_or_errors then
- self:enable(true)
+ passed = true
break
end
end
end
+ -- check features
+ local features = self:get("features")
+ if features then
+
+ -- import core.tool.compiler
+ self._core_tool_compiler = self._core_tool_compiler or sandbox_module.import("core.tool.compiler", {anonymous = true})
+
+ -- all features are supported?
+ local features_supported = self._core_tool_compiler.has_features(features, {target = self})
+ if features_supported and #features_supported == #features then
+ passed = true
+ end
+
+ -- trace
+ if baseoption.get("verbose") or baseoption.get("diagnosis") then
+ for _, feature in ipairs(table.wrap(features)) do
+ utils.cprint("${dim}checking for the feature(%s) ... %s", feature, passed and "${color.success}${text.success}" or "${color.nothing}${text.nothing}")
+ end
+ end
+ end
+
+ -- enable this option if be passed
+ if passed then
+ self:enable(true)
+ end
+
-- ok
return true
end
@@ -157,7 +191,7 @@ function option:_on_check()
if check then
return sandbox.load(check, self)
else
- return self:_cx_check()
+ return self:_do_check()
end
end
diff --git a/xmake/languages/c++/api.lua b/xmake/languages/c++/api.lua
index fd0ad5d4c..be95e6b6c 100644
--- a/xmake/languages/c++/api.lua
+++ b/xmake/languages/c++/api.lua
@@ -227,8 +227,10 @@ function apis()
_g.dictionary =
{
-- option.add_xxx
- "option.add_csnippet"
- , "option.add_cxxsnippet"
+ "option.add_csnippet" -- TODO deprecated
+ , "option.add_csnippets"
+ , "option.add_cxxsnippet" -- TODO deprecated
+ , "option.add_cxxsnippets"
}
_g.custom =
{