summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2020-05-26 00:34:08 +0800
committerruki <[email protected]>2020-05-25 21:24:53 +0800
commit97b53dfcb67c898f40fae06b6b939e4dac32a3a0 (patch)
treec91bfc82592938ae27e2a72ec38737b33cd3988a /xmake
parent05b37be8865ff1af2051766a835e7576a6780e55 (diff)
add set_toolchains for target
Diffstat (limited to 'xmake')
-rw-r--r--xmake/core/project/project.lua19
-rw-r--r--xmake/core/project/target.lua62
-rw-r--r--xmake/core/tool/compiler.lua12
-rw-r--r--xmake/core/tool/linker.lua12
-rw-r--r--xmake/core/tool/tool.lua6
5 files changed, 89 insertions, 22 deletions
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 1c97bdfd4..be492e662 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -429,7 +429,7 @@ function project._load_targets()
end
end
- -- laod packages
+ -- load packages
t._PACKAGES = t._PACKAGES or {}
for _, packagename in ipairs(table.wrap(t:get("packages"))) do
local p = requires[packagename]
@@ -437,6 +437,23 @@ function project._load_targets()
table.insert(t._PACKAGES, p)
end
end
+
+ -- load toolchains
+ local toolchains = t:get("toolchains")
+ if toolchains then
+ t._TOOLCHAINS = {}
+ for _, name in ipairs(table.wrap(toolchains)) do
+ local toolchain_inst, errors = toolchain.load(name)
+ -- attempt to load toolchain from project
+ if not toolchain_inst then
+ toolchain_inst = project.toolchain(name)
+ end
+ if not toolchain_inst then
+ return nil, errors
+ end
+ table.insert(t._TOOLCHAINS, toolchain_inst)
+ end
+ end
end
-- enter toolchains environment
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 9a519cbed..a397f7adc 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -1650,6 +1650,67 @@ function _instance:pcoutputfile(langkind)
end
end
+-- get the toolchains
+function _instance:toolchains()
+ local toolchains = self._TOOLCHAINS
+ if toolchains == nil then
+ local instance, errors = platform.load()
+ if not instance then
+ os.raise(errors)
+ end
+ toolchains = instance:toolchains()
+ self._TOOLCHAINS = toolchains
+ end
+ return toolchains
+end
+
+-- get the program and name of the given tool kind
+function _instance:tool(toolkind)
+
+ -- init tools
+ local tools = self._TOOLS
+ if not tools then
+ tools = {}
+ self._TOOLS = tools
+ end
+
+ -- get tool program
+ local program, toolname
+ local toolinfo = tools[toolkind]
+ if toolinfo == nil then
+ toolinfo = {}
+
+ -- get program from set_toolchain/set_tools (deprecated)
+ program = self:get("toolchain." .. toolkind)
+ if not program then
+ local tools = self:get("tools") -- TODO: deprecated
+ if tools then
+ program = tools[toolkind]
+ end
+ end
+
+ -- get program from target/toolchains
+ if not program then
+ local toolchains = self:toolchains()
+ for idx, toolchain_inst in ipairs(toolchains) do
+ program, toolname = toolchain_inst:tool(toolkind)
+ if program then
+ break
+ end
+ end
+ end
+ if program then
+ toolinfo[1] = program
+ toolinfo[2] = toolname
+ end
+ tools[toolkind] = toolinfo
+ else
+ program = toolinfo[1]
+ toolname = toolinfo[2]
+ end
+ return program, toolname
+end
+
-- get target apis
function target.apis()
@@ -1671,6 +1732,7 @@ function target.apis()
, "target.set_warnings"
, "target.set_optimize"
, "target.set_languages"
+ , "target.set_toolchains"
-- target.add_xxx
, "target.add_deps"
, "target.add_rules"
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua
index 27c81879c..1f0d7d6d6 100644
--- a/xmake/core/tool/compiler.lua
+++ b/xmake/core/tool/compiler.lua
@@ -71,19 +71,13 @@ end
function compiler._load_tool(sourcekind, target)
-- get program from target
- local program = nil
+ local program, toolname
if target then
- program = target:get("toolchain." .. sourcekind)
- if not program then
- local tools = target:get("tools") -- TODO: deprecated
- if tools then
- program = tools[sourcekind]
- end
- end
+ program, toolname = target:tool(sourcekind)
end
-- load the compiler tool from the source kind
- local result, errors = tool.load(sourcekind, program)
+ local result, errors = tool.load(sourcekind, program, toolname)
if not result then
return nil, errors
end
diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua
index b3f91a904..bbb088e7c 100644
--- a/xmake/core/tool/linker.lua
+++ b/xmake/core/tool/linker.lua
@@ -78,19 +78,13 @@ function linker._load_tool(targetkind, sourcekinds, target)
for _, _linkerinfo in ipairs(linkerinfos) do
-- get program from target
- local program = nil
+ local program, toolname
if target then
- program = target:get("toolchain." .. _linkerinfo.linkerkind)
- if not program then
- local tools = target:get("tools") -- TODO: deprecated
- if tools then
- program = tools[_linkerinfo.linkerkind]
- end
- end
+ program, toolname = target:tool(_linkerinfo.linkerkind)
end
-- load the linker tool from the linker kind (with cache)
- linkertool, errors = tool.load(_linkerinfo.linkerkind, program)
+ linkertool, errors = tool.load(_linkerinfo.linkerkind, program, toolname)
if linkertool then
linkerinfo = _linkerinfo
linkerinfo.program = program
diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua
index 70c6e62f8..9e6dec6d4 100644
--- a/xmake/core/tool/tool.lua
+++ b/xmake/core/tool/tool.lua
@@ -130,9 +130,10 @@ end
-- load the given tool from the given kind
--
-- @param kind the tool kind e.g. cc, cxx, mm, mxx, as, ar, ld, sh, ..
--- @param program the tool program, e.g. /xxx/arm-linux-gcc, [email protected]
+-- @param program the tool program, e.g. /xxx/arm-linux-gcc, [email protected], (optional)
+-- @param toolname gcc, clang, .. (optional)
--
-function tool.load(kind, program)
+function tool.load(kind, program, toolname)
-- init key
local key = kind .. (program or "") .. (config.get("arch") or os.arch())
@@ -144,7 +145,6 @@ function tool.load(kind, program)
end
-- contain toolname? parse it, e.g. '[email protected]'
- local toolname = nil
if program then
local pos = program:find('@', 1, true)
if pos then