diff options
| -rw-r--r-- | xmake/core/package/package.lua | 16 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 16 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 10 |
3 files changed, 32 insertions, 10 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 2d7534878..d47858e55 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -845,6 +845,22 @@ function _instance:toolconfig(name) end end +-- has the given tool for the current package? +-- +-- e.g. +-- +-- if package:has_tool("cc", "clang", "gcc") then +-- ... +-- end +function _instance:has_tool(toolkind, ...) + local _, toolname = self:tool(toolkind) + for _, v in ipairs(table.join(...)) do + if v and toolname:find("^" .. v:gsub("%-", "%%-") .. "$") then + return true + end + end +end + -- get the user private data function _instance:data(name) return self._DATA and self._DATA[name] or nil diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 572764c90..499db099c 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1951,6 +1951,22 @@ function _instance:toolconfig(name) end}) end +-- has the given tool for the current target? +-- +-- e.g. +-- +-- if target:has_tool("cc", "clang", "gcc") then +-- ... +-- end +function _instance:has_tool(toolkind, ...) + local _, toolname = self:tool(toolkind) + for _, v in ipairs(table.join(...)) do + if v and toolname:find("^" .. v:gsub("%-", "%%-") .. "$") then + return true + end + end +end + -- get target apis function target.apis() diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index e3c5de456..91bb707f8 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -442,16 +442,6 @@ function builder:map_flags(name, values, opt) end end --- is the given name? -function builder:is(...) - local name = self:name() - for _, v in ipairs(table.join(...)) do - if v and name:find("^" .. v:gsub("%-", "%%-") .. "$") then - return true - end - end -end - -- get the format of the given target kind function builder:format(targetkind) local formats = self:get("formats") |
