summaryrefslogtreecommitdiff
path: root/xmake/core/package/package.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2023-03-18 00:33:31 +0800
committerruki <[email protected]>2023-03-18 00:33:31 +0800
commit0d2f106b0d7304e352dc830f5d325fb6619c32be (patch)
tree2c290cb9dd221033d4b8de0537a2de0986e5b1cf /xmake/core/package/package.lua
parent890b52a2b7311315862841b1f5c17fd01bbb7751 (diff)
add has_flags
Diffstat (limited to 'xmake/core/package/package.lua')
-rw-r--r--xmake/core/package/package.lua54
1 files changed, 53 insertions, 1 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index a7171c1d1..910be52b6 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.
@@ -2087,7 +2115,7 @@ end
-- has the given c types?
--
--- @param types the types
+-- @param types the types
-- @param opt the argument options, e.g. { defines = ""}
--
-- @return true or false, errors
@@ -2141,6 +2169,30 @@ 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
+
-- check the given c snippets?
--
-- @param snippets the snippets