summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-03-21 12:55:10 +0800
committerruki <[email protected]>2021-03-21 12:55:10 +0800
commitefa052bcecd4203dfce0fda26a297f3ce45ed47d (patch)
tree6c647dba446e5dcbc1a1bba06991813215c1ac1b
parent03b2656fb77fb3339e43bf8871398b0e2f052a80 (diff)
improve linker and compiler for package
-rw-r--r--xmake/core/package/package.lua40
-rw-r--r--xmake/core/tool/builder.lua8
-rw-r--r--xmake/core/tool/compiler.lua8
-rw-r--r--xmake/core/tool/linker.lua4
4 files changed, 21 insertions, 39 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index d609c907d..033503580 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -1370,11 +1370,8 @@ end
-- @return true or false
--
function _instance:has_cfuncs(funcs, opt)
- if not self:is_plat(config.get("plat")) or self:config("toolchains") then
- -- TODO we also need check it later for package with custom toolchains
- return true
- end
opt = opt or {}
+ opt.target = self
opt.configs = self:_generate_build_configs(opt.configs)
return sandbox_module.import("lib.detect.has_cfuncs", {anonymous = true})(funcs, opt)
end
@@ -1387,11 +1384,8 @@ end
-- @return true or false
--
function _instance:has_cxxfuncs(funcs, opt)
- if not self:is_plat(config.get("plat")) or self:config("toolchains") then
- -- TODO we also need check it later for package with custom toolchains
- return true
- end
opt = opt or {}
+ opt.target = self
opt.configs = self:_generate_build_configs(opt.configs)
return sandbox_module.import("lib.detect.has_cxxfuncs", {anonymous = true})(funcs, opt)
end
@@ -1404,11 +1398,8 @@ end
-- @return true or false
--
function _instance:has_ctypes(types, opt)
- if not self:is_plat(config.get("plat")) or self:config("toolchains") then
- -- TODO we also need check it later for package with custom toolchains
- return true
- end
opt = opt or {}
+ opt.target = self
opt.configs = self:_generate_build_configs(opt.configs)
return sandbox_module.import("lib.detect.has_ctypes", {anonymous = true})(types, opt)
end
@@ -1421,11 +1412,8 @@ end
-- @return true or false
--
function _instance:has_cxxtypes(types, opt)
- if not self:is_plat(config.get("plat")) or self:config("toolchains") then
- -- TODO we also need check it later for package with custom toolchains
- return true
- end
opt = opt or {}
+ opt.target = self
opt.configs = self:_generate_build_configs(opt.configs)
return sandbox_module.import("lib.detect.has_cxxtypes", {anonymous = true})(types, opt)
end
@@ -1438,11 +1426,8 @@ end
-- @return true or false
--
function _instance:has_cincludes(includes, opt)
- if not self:is_plat(config.get("plat")) or self:config("toolchains") then
- -- TODO we also need check it later for package with custom toolchains
- return true
- end
opt = opt or {}
+ opt.target = self
opt.configs = self:_generate_build_configs(opt.configs)
return sandbox_module.import("lib.detect.has_cincludes", {anonymous = true})(includes, opt)
end
@@ -1455,11 +1440,8 @@ end
-- @return true or false
--
function _instance:has_cxxincludes(includes, opt)
- if not self:is_plat(config.get("plat")) or self:config("toolchains") then
- -- TODO we also need check it later for package with custom toolchains
- return true
- end
opt = opt or {}
+ opt.target = self
opt.configs = self:_generate_build_configs(opt.configs)
return sandbox_module.import("lib.detect.has_cxxincludes", {anonymous = true})(includes, opt)
end
@@ -1472,11 +1454,8 @@ end
-- @return true or false
--
function _instance:check_csnippets(snippets, opt)
- if not self:is_plat(config.get("plat")) or self:config("toolchains") then
- -- TODO we also need check it later for package with custom toolchains
- return true
- end
opt = opt or {}
+ opt.target = self
opt.configs = self:_generate_build_configs(opt.configs)
return sandbox_module.import("lib.detect.check_csnippets", {anonymous = true})(snippets, opt)
end
@@ -1489,11 +1468,8 @@ end
-- @return true or false
--
function _instance:check_cxxsnippets(snippets, opt)
- if not self:is_plat(config.get("plat")) or self:config("toolchains") then
- -- TODO we also need check it later for package with custom toolchains
- return true
- end
opt = opt or {}
+ opt.target = self
opt.configs = self:_generate_build_configs(opt.configs)
return sandbox_module.import("lib.detect.check_cxxsnippets", {anonymous = true})(snippets, opt)
end
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index 08a6080c7..9b59de413 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -181,6 +181,12 @@ function builder:_add_flags_from_target(flags, target)
return
end
+ -- only for target and option
+ local target_type = target:type()
+ if target_type ~= "target" and target_type ~= "option" then
+ return
+ end
+
-- init cache
self._TARGETFLAGS = self._TARGETFLAGS or {}
local cache = self._TARGETFLAGS
@@ -195,7 +201,7 @@ function builder:_add_flags_from_target(flags, target)
self:_add_flags_from_language(targetflags, target)
-- add flags for the target
- if target:type() == "target" then
+ if target_type == "target" then
-- add flags from options
self:_add_flags_from_targetopts(targetflags, target)
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua
index b896d04b6..0e64de8c3 100644
--- a/xmake/core/tool/compiler.lua
+++ b/xmake/core/tool/compiler.lua
@@ -46,7 +46,7 @@ function compiler:_add_flags_from_toolchains(flags, targetkind, target)
-- add flags for platform with the given target kind, e.g. binary.gcc.cxflags or binary.cxflags
if targetkind then
local toolname = self:name()
- if target and target:type() == "target" then
+ if target and target.toolconfig then
for _, flagkind in ipairs(self:_flagkinds()) do
local toolflags = target:toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind)
table.join2(flags, toolflags or target:toolconfig(targetkind .. '.' .. flagkind))
@@ -79,7 +79,7 @@ function compiler._load_tool(sourcekind, target)
-- get program from target
local program, toolname, toolchain_info
- if target and target:type() == "target" then
+ if target and target.tool then
program, toolname, toolchain_info = target:tool(sourcekind)
end
@@ -138,7 +138,7 @@ function compiler.load(sourcekind, target)
-- add toolchains flags to the compiler tool, e.g. gcc.cxflags or cxflags
local toolname = compiler_tool:name()
- if target and target:type() == "target" then
+ if target and target.toolconfig then
for _, flagkind in ipairs(instance:_flagkinds()) do
compiler_tool:add(flagkind, target:toolconfig(toolname .. '.' .. flagkind) or target:toolconfig(flagkind))
end
@@ -296,7 +296,7 @@ function compiler:compflags(opt)
-- get target kind
local targetkind = opt.targetkind
- if not targetkind and target and target.targetkind then
+ if not targetkind and target and target:type() == "target" then
targetkind = target:kind()
end
diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua
index 65eabce46..cc67088a2 100644
--- a/xmake/core/tool/linker.lua
+++ b/xmake/core/tool/linker.lua
@@ -86,7 +86,7 @@ function linker._load_tool(targetkind, sourcekinds, target)
-- get program from target
local program, toolname, toolchain_info
- if target and target:type() == "target" then
+ if target and target.tool then
program, toolname, toolchain_info = target:tool(_linkerinfo.linkerkind)
end
@@ -185,7 +185,7 @@ function linker.load(targetkind, sourcekinds, target)
-- add special lanugage flags first, e.g. go.gcldflags or gcc.ldflags or gcldflags or ldflags
local toolkind = linkertool:kind()
local toolname = linkertool:name()
- if target and target:type() == "target" then
+ if target and target.toolconfig then
for _, flagkind in ipairs(instance:_flagkinds()) do
linkertool:add(toolkind .. 'flags', target:toolconfig(toolname .. '.' .. toolkind .. 'flags') or target:toolconfig(toolkind .. 'flags'))
linkertool:add(flagkind, target:toolconfig(toolname .. '.' .. flagkind) or target:toolconfig(flagkind))