summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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