summaryrefslogtreecommitdiff
path: root/xmake/core/package/package.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2023-03-17 23:22:36 +0800
committerGitHub <[email protected]>2023-03-17 23:22:36 +0800
commit404a8a5feadef0c56f57895103ff6f9419cdfd41 (patch)
tree73160a76034e3325c952ea33a893a3edf9de6ae2 /xmake/core/package/package.lua
parent890b52a2b7311315862841b1f5c17fd01bbb7751 (diff)
parentf7bc68f09a8d20fcae1304c9ab70d7f9b7472de5 (diff)
Merge pull request #3521 from xmake-io/hasxxx
add has_xxx for target
Diffstat (limited to 'xmake/core/package/package.lua')
-rw-r--r--xmake/core/package/package.lua85
1 files changed, 75 insertions, 10 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index a7171c1d1..cfc60f696 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -36,6 +36,7 @@ local scopeinfo = require("base/scopeinfo")
local interpreter = require("base/interpreter")
local memcache = require("cache/memcache")
local toolchain = require("tool/toolchain")
+local compiler = require("tool/compiler")
local sandbox = require("sandbox/sandbox")
local config = require("project/config")
local policy = require("project/policy")
@@ -59,6 +60,16 @@ function _instance.new(name, info, opt)
return instance
end
+-- get memcache
+function _instance:_memcache()
+ local cache = self._MEMCACHE
+ if not cache then
+ cache = memcache.cache("core.package.package." .. tostring(self))
+ self._MEMCACHE = cache
+ end
+ return cache
+end
+
-- get the package name
function _instance:name()
return self._NAME
@@ -1110,6 +1121,23 @@ function _instance:toolconfig(name)
end
end
+-- get the target compiler
+function _instance:compiler(sourcekind)
+ local compilerinst = self:_memcache():get("compiler")
+ if not compilerinst then
+ if not sourcekind then
+ os.raise("please pass sourcekind to the first argument of package:compiler(), e.g. cc, cxx, as")
+ end
+ local instance, errors = compiler.load(sourcekind, self)
+ if not instance then
+ os.raise(errors)
+ end
+ compilerinst = instance
+ self:_memcache():set("compiler", compilerinst)
+ end
+ return compilerinst
+end
+
-- has the given tool for the current package?
--
-- e.g.
@@ -2060,7 +2088,7 @@ end
-- has the given c funcs?
--
-- @param funcs the funcs
--- @param opt the argument options, e.g. { includes = ""}
+-- @param opt the argument options, e.g. {includes = "xxx.h", configs = {defines = ""}}
--
-- @return true or false, errors
--
@@ -2074,7 +2102,7 @@ end
-- has the given c++ funcs?
--
-- @param funcs the funcs
--- @param opt the argument options, e.g. {includes = ""}
+-- @param opt the argument options, e.g. {includes = "xxx.h", configs = {defines = ""}}
--
-- @return true or false, errors
--
@@ -2087,8 +2115,8 @@ end
-- has the given c types?
--
--- @param types the types
--- @param opt the argument options, e.g. { defines = ""}
+-- @param types the types
+-- @param opt the argument options, e.g. {configs = {defines = ""}}
--
-- @return true or false, errors
--
@@ -2101,8 +2129,8 @@ end
-- has the given c++ types?
--
--- @param types the types
--- @param opt the argument options, e.g. { defines = ""}
+-- @param types the types
+-- @param opt the argument options, e.g. {configs = {defines = ""}}
--
-- @return true or false, errors
--
@@ -2116,7 +2144,7 @@ end
-- has the given c includes?
--
-- @param includes the includes
--- @param opt the argument options, e.g. { defines = ""}
+-- @param opt the argument options, e.g. {configs = {defines = ""}}
--
-- @return true or false, errors
--
@@ -2130,7 +2158,7 @@ end
-- has the given c++ includes?
--
-- @param includes the includes
--- @param opt the argument options, e.g. { defines = ""}
+-- @param opt the argument options, e.g. {configs = {defines = ""}}
--
-- @return true or false, errors
--
@@ -2141,10 +2169,47 @@ function _instance:has_cxxincludes(includes, opt)
return sandbox_module.import("lib.detect.has_cxxincludes", {anonymous = true})(includes, opt)
end
+-- has the given c flags?
+--
+-- @param flags the flags
+-- @param opt the argument options, e.g. { flagskey = "xxx" }
+--
+-- @return true or false, errors
+--
+function _instance:has_cflags(flags, opt)
+ local compinst = self:compiler("cc")
+ return compinst:has_flags(flags, "cflags", opt)
+end
+
+-- has the given c++ flags?
+--
+-- @param flags the flags
+-- @param opt the argument options, e.g. { flagskey = "xxx" }
+--
+-- @return true or false, errors
+--
+function _instance:has_cxxflags(flags, opt)
+ local compinst = self:compiler("cxx")
+ 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. {flags = ""}
+--
+-- @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
--- @param opt the argument options, e.g. { includes = ""}
+-- @param opt the argument options, e.g. {includes = "xxx.h", configs = {defines = ""}}
--
-- @return true or false, errors
--
@@ -2158,7 +2223,7 @@ end
-- check the given c++ snippets?
--
-- @param snippets the snippets
--- @param opt the argument options, e.g. { includes = ""}
+-- @param opt the argument options, e.g. {includes = "xxx.h", configs = {defines = ""}}
--
-- @return true or false, errors
--