diff options
| author | ruki <[email protected]> | 2017-06-27 19:57:45 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-06-27 19:59:50 +0800 |
| commit | d88cab7a400904e6a44f795479cbc3f2bdcc6297 (patch) | |
| tree | daa207a507d1a6d836a22a5b6616c8936d0ff8f6 | |
| parent | 08423656d08715670959b69c64957e9e9b1b3db1 (diff) | |
improve has_cxsnippet and add links
| -rw-r--r-- | xmake/core/tool/builder.lua | 7 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 51 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 59 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/has_cxsnippets.lua | 42 |
4 files changed, 113 insertions, 46 deletions
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 53d658c8c..9143fcbee 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -194,6 +194,13 @@ function builder:_addflags_from_targetdeps(results, target, flagname) end end +-- add flags from the argument option +function builder:_addflags_from_argument(flags, args) + for _, flagkind in ipairs(self:_flagkinds()) do + table.join2(flags, self:_mapflags(args[flagkind])) + end +end + -- add flags (named) from the language function builder:_addflags_from_language(flags, target) diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index a4f8dc5f4..622ed946b 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -192,36 +192,51 @@ function compiler:compflags(opt) -- get target local target = opt.target - -- no target? - if not target then - return "", {} - end - -- get the target key - local key = tostring(target) + local key = nil + if target then + key = tostring(target) + end -- get it directly from cache dirst - self._FLAGS = self._FLAGS or {} - local flags_cached = self._FLAGS[key] - if flags_cached then - return flags_cached[1], flags_cached[2] + if key then + self._FLAGS = self._FLAGS or {} + local flags_cached = self._FLAGS[key] + if flags_cached then + return flags_cached[1], flags_cached[2] + end + end + + -- get target kind + local targetkind = opt.targetkind + if not targetkind and target then + targetkind = target:get("kind") end -- add flags from the configure local flags = {} self:_addflags_from_config(flags) - -- add flags from the target - self:_addflags_from_target(flags, target) - + -- add flags for the target + if target then + self:_addflags_from_target(flags, target) + end + -- add flags (named) from language - self:_addflags_from_language(flags, target) + if target then + self:_addflags_from_language(flags, target) + end + + -- add flags for the argument + self:_addflags_from_argument(flags, opt) -- add flags from the platform - self:_addflags_from_platform(flags, target:get("kind")) + if target then + self:_addflags_from_platform(flags, targetkind) + end -- add flags from the compiler - self:_addflags_from_compiler(flags, target:get("kind")) + self:_addflags_from_compiler(flags, targetkind) -- remove repeat flags = table.unique(flags) @@ -230,7 +245,9 @@ function compiler:compflags(opt) local flags_str = table.concat(flags, " "):trim() -- save flags - self._FLAGS[key] = {flags_str, flags} + if key then + self._FLAGS[key] = {flags_str, flags} + end -- get it return flags_str, flags diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index 43ef26485..6b3ec05d5 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -51,8 +51,10 @@ function linker:_addflags_from_platform(flags, targetkind) table.join2(flags, platform.get(toolkind .. 'flags') or platform.get(flagkind)) -- attempt to add special lanugage flags first for target kind, .e.g gc-ldflags, dc-arflags - local targetflags = platform.get(targetkind) or {} - table.join2(flags, targetflags[toolkind .. 'flags'] or targetflags[flagkind]) + if targetkind then + local targetflags = platform.get(targetkind) or {} + table.join2(flags, targetflags[toolkind .. 'flags'] or targetflags[flagkind]) + end end end @@ -191,36 +193,53 @@ function linker:linkflags(opt) -- get target local target = opt.target - -- no target? - if not target then - return "", {} - end - -- get the target key - local key = tostring(target) + local key = nil + if target then + key = tostring(target) + end -- get it directly from cache dirst - self._FLAGS = self._FLAGS or {} - local flags_cached = self._FLAGS[key] - if flags_cached then - return flags_cached[1], flags_cached[2] + if key then + self._FLAGS = self._FLAGS or {} + local flags_cached = self._FLAGS[key] + if flags_cached then + return flags_cached[1], flags_cached[2] + end + end + + -- get target kind + local targetkind = opt.targetkind + if not targetkind and target then + targetkind = target:get("kind") end -- add flags from the configure local flags = {} self:_addflags_from_config(flags) - -- add flags from the target - self:_addflags_from_target(flags, target) - + -- add flags for the target + if target then + self:_addflags_from_target(flags, target) + end + -- add flags (named) from language - self:_addflags_from_language(flags, target) + if target then + self:_addflags_from_language(flags, target) + end + + -- add flags for the argument + self:_addflags_from_argument(flags, opt) -- add flags from the platform - self:_addflags_from_platform(flags, target:get("kind")) + if target then + self:_addflags_from_platform(flags, targetkind) + end -- add flags from the compiler - self:_addflags_from_compiler(flags, target:get("kind"), target:sourcekinds()) + if target then + self:_addflags_from_compiler(flags, targetkind, target:sourcekinds()) + end -- add flags from the linker self:_addflags_from_linker(flags) @@ -232,7 +251,9 @@ function linker:linkflags(opt) local flags_str = table.concat(flags, " "):trim() -- save flags - self._FLAGS[key] = {flags_str, flags} + if key then + self._FLAGS[key] = {flags_str, flags} + end -- get it return flags_str, flags diff --git a/xmake/modules/lib/detect/has_cxsnippets.lua b/xmake/modules/lib/detect/has_cxsnippets.lua index 78665ac14..3d3d1ee42 100644 --- a/xmake/modules/lib/detect/has_cxsnippets.lua +++ b/xmake/modules/lib/detect/has_cxsnippets.lua @@ -103,7 +103,7 @@ function _sourcecode(snippets, opt) -- add functions for _, funcinfo in ipairs(opt.functions) do - sourcecode = format("%s\n %s;", _funccode(funcinfo)) + sourcecode = format("%s\n %s;", sourcecode, _funccode(funcinfo)) end -- leave main function @@ -119,8 +119,7 @@ end -- @param opt the argument options -- .e.g -- { name = "", verbose = false, target = [target|option], sourcekind = "[cc|cxx]" --- , types = {"wchar_t", "char*"}, includes = "stdio.h", functions = {"sigsetjmp", "sigsetjmp((void*)0, 0)"} --- , links = {"pthread", "z"}} +-- , types = {"wchar_t", "char*"}, includes = "stdio.h", functions = {"sigsetjmp", "sigsetjmp((void*)0, 0)"}} -- -- functions: -- sigsetjmp @@ -152,6 +151,24 @@ function main(csnippets, opt) end end + -- get links + local links = table.wrap(opt.links) + if opt.target then + table.join2(links, opt.target:get("links")) + end + + -- get types + local types = table.wrap(opt.types) + + -- get includes + local includes = table.wrap(opt.includes) + + -- get functions + local functions = {} + for _, funcinfo in ipairs(opt.functions) do + table.insert(functions, _funcname(funcinfo)) + end + -- make source code local sourcecode = _sourcecode(snippets, opt) @@ -171,7 +188,9 @@ function main(csnippets, opt) { function () compiler.compile(sourcefile, objectfile, opt) --- linker.link(objectfile, os.nuldev(), opt.target) + if #links > 0 then + linker.link("binary", {"cc", "cxx"}, objectfile, os.nuldev(), opt) + end return true end, catch @@ -194,14 +213,17 @@ function main(csnippets, opt) cprint("checking for the %s ... %s", opt.name, ifelse(ok, "${green}ok", "${red}no")) else local kind = ifelse(sourcekind == "cc", "c", "c++") - for _, include in ipairs(opt.includes) do - cprint("checking for the %s include %s ... %s", kind, include, ifelse(ok, "${green}ok", "${red}no")) + if #includes > 0 then + cprint("checking for the %s includes %s ... %s", kind, table.concat(includes, ", "), ifelse(ok, "${green}ok", "${red}no")) + end + if #types > 0 then + cprint("checking for the %s types %s ... %s", kind, table.concat(types, ", "), ifelse(ok, "${green}ok", "${red}no")) end - for _, typename in ipairs(opt.types) do - cprint("checking for the %s type %s ... %s", kind, typename, ifelse(ok, "${green}ok", "${red}no")) + if #functions > 0 then + cprint("checking for the %s functions %s ... %s", kind, table.concat(functions, ", "), ifelse(ok, "${green}ok", "${red}no")) end - for _, funcinfo in ipairs(opt.functions) do - cprint("checking for the %s function %s ... %s", kind, _funcname(funcinfo), ifelse(ok, "${green}ok", "${red}no")) + if #links > 0 then + cprint("checking for the %s links %s ... %s", kind, table.concat(links, ", "), ifelse(ok, "${green}ok", "${red}no")) end for _, snippet in ipairs(opt.snippets) do cprint("checking for the %s snippet %s ... %s", kind, snippet:sub(1, 16), ifelse(ok, "${green}ok", "${red}no")) |
