summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-03-18 00:37:10 +0800
committerruki <[email protected]>2023-03-18 00:37:10 +0800
commit21f980d98c09362721ccd48f42a6fa5508cf4375 (patch)
tree2565eb5dc7d9ee075e698236ffb989889bb30081
parent0d2f106b0d7304e352dc830f5d325fb6619c32be (diff)
add has_features
-rw-r--r--xmake/core/package/package.lua13
-rw-r--r--xmake/core/project/option.lua3
-rw-r--r--xmake/core/project/target.lua13
-rw-r--r--xmake/core/sandbox/modules/import/core/tool/compiler.lua27
-rw-r--r--xmake/modules/lib/detect/has_features.lua20
5 files changed, 40 insertions, 36 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 910be52b6..48cf97b04 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -2193,6 +2193,19 @@ function _instance:has_cxxflags(flags, opt)
return compinst:has_flags(flags, "cxxflags", opt)
end
+-- has the given features?
+--
+-- @param features the features, e.g. {"c_static_assert", "cxx_constexpr"}
+-- @param opt the argument options, e.g. {cxflags = "", defines = "", includedirs = "", ...}
+--
+-- @return true or false, errors
+--
+function _instance:has_features(features, opt)
+ opt = opt or {}
+ opt.target = self
+ return sandbox_module.import("core.tool.compiler", {anonymous = true}).has_features(features, opt)
+end
+
-- check the given c snippets?
--
-- @param snippets the snippets
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index dcb94aa55..73e3a8f1f 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -209,8 +209,7 @@ function _instance:_do_check_features()
-- all features are supported?
features = table.wrap(features)
- local features_supported = self._core_tool_compiler.has_features(features, {target = self})
- if features_supported and #features_supported == #features then
+ if self._core_tool_compiler.has_features(features, {target = self}) then
passed = 1
end
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index dfcf58a56..549f18301 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -2354,6 +2354,19 @@ function _instance:has_cxxflags(flags, opt)
return compinst:has_flags(flags, "cxxflags", opt)
end
+-- has the given features?
+--
+-- @param features the features, e.g. {"c_static_assert", "cxx_constexpr"}
+-- @param opt the argument options, e.g. {cxflags = "", defines = "", includedirs = "", ...}
+--
+-- @return true or false, errors
+--
+function _instance:has_features(features, opt)
+ opt = opt or {}
+ opt.target = self
+ return sandbox_module.import("core.tool.compiler", {anonymous = true}).has_features(features, opt)
+end
+
-- check the given c snippets?
--
-- @param snippets the snippets
diff --git a/xmake/core/sandbox/modules/import/core/tool/compiler.lua b/xmake/core/sandbox/modules/import/core/tool/compiler.lua
index 4545a0a14..aae2201ce 100644
--- a/xmake/core/sandbox/modules/import/core/tool/compiler.lua
+++ b/xmake/core/sandbox/modules/import/core/tool/compiler.lua
@@ -226,7 +226,7 @@ end
-- @param opt the argument options (contain all the compiler attributes of target),
-- e.g. {target = ..., targetkind = "static", cxflags = "", defines = "", includedirs = "", ...}
--
--- @return the supported features or nil
+-- @return the true or false
--
function sandbox_core_tool_compiler.has_features(features, opt)
@@ -236,14 +236,10 @@ function sandbox_core_tool_compiler.has_features(features, opt)
return
end
- -- init options
- opt = opt or {}
-
- -- get the language kinds
- local langkinds = language.langkinds()
-
-- classify features by the source kind
+ opt = opt or {}
local features_by_kind = {}
+ local langkinds = language.langkinds()
for _, feature in ipairs(table.wrap(features)) do
-- get language kind
@@ -260,29 +256,18 @@ function sandbox_core_tool_compiler.has_features(features, opt)
end
-- has features for each compiler?
- local results = nil
for sourcekind, features in pairs(features_by_kind) do
-
- -- get the compiler instance
local instance = sandbox_core_tool_compiler.load(sourcekind, opt)
-
- -- get flags
local flags = instance:compflags(opt)
-
- -- has features?
local ok, results_or_errors = sandbox.load(sandbox_core_tool_compiler._has_features, instance:name(), features, {flags = flags, program = instance:program(), envs = instance:runenvs()})
if not ok then
raise(results_or_errors)
end
-
- -- save results
- if results_or_errors then
- results = table.join(results or {}, results_or_errors)
+ if not results_or_errors then
+ return false
end
end
-
- -- ok?
- return results
+ return true
end
-- has the given flags?
diff --git a/xmake/modules/lib/detect/has_features.lua b/xmake/modules/lib/detect/has_features.lua
index 80dbc2ec7..2b879dd1e 100644
--- a/xmake/modules/lib/detect/has_features.lua
+++ b/xmake/modules/lib/detect/has_features.lua
@@ -28,7 +28,7 @@ import("lib.detect.features", {alias = "get_features"})
-- @param features the features
-- @param opt the argument options, e.g. {verbose = false, flags = {}, program = ""}}
--
--- @return the supported features or nil
+-- @return true or false
--
-- @code
-- local features = has_features("clang", "cxx_constexpr")
@@ -37,20 +37,14 @@ import("lib.detect.features", {alias = "get_features"})
-- @endcode
--
function main(name, features, opt)
-
- -- init options
opt = opt or {}
-
- -- get all features
- local all = get_features(name, opt) or {}
-
- -- get results
- local results = nil
+ local allfeatures = get_features(name, opt) or {}
+ local passed = 0
+ features = table.wrap(features)
for _, feature in ipairs(features) do
- if all[feature] then
- results = results or {}
- table.insert(results, feature)
+ if allfeatures[feature] then
+ passed = passed + 1
end
end
- return results
+ return passed == #features
end