summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-11-28 03:11:08 +0800
committerruki <[email protected]>2021-11-28 03:11:08 +0800
commit3726f42847029c73301a87937e80a9c78465fdb2 (patch)
treef8c88fe5087af55c5d3c712c248e303cdc95d16a
parent04a13fd238c754b55338f9debdcf09aff27427ee (diff)
add target:compiler
-rw-r--r--xmake/core/project/target.lua38
1 files changed, 26 insertions, 12 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 922d7d483..572764c90 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -582,21 +582,35 @@ function _instance:basename()
return self:get("basename") or self:name()
end
--- get the target linker
-function _instance:linker()
-
- -- get it from cache first
- if self._LINKER then
- return self._LINKER
+-- 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 target: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
- -- get the linker instance
- local instance, errors = linker.load(self:kind(), self:sourcekinds(), self)
- if not instance then
- os.raise(errors)
+-- get the target linker
+function _instance:linker()
+ local linkerinst = self:_memcache():get("linker")
+ if not linkerinst then
+ local instance, errors = linker.load(self:kind(), self:sourcekinds(), self)
+ if not instance then
+ os.raise(errors)
+ end
+ linkerinst = instance
+ self:_memcache():set("linker", linkerinst)
end
- self._LINKER = instance
- return instance
+ return linkerinst
end
-- make linking command for this target