diff options
| author | ruki <[email protected]> | 2018-12-20 23:55:49 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-12-20 17:34:56 +0800 |
| commit | d95758dc85e1e34e6ce507ffee78f7634a0661c5 (patch) | |
| tree | f740966dedf5eea54bf54c4f7d379fcfa012034a | |
| parent | cbce3651b8baff9d4cad89b3056e629c9ace4a41 (diff) | |
add flagkind to has_flags
| -rw-r--r-- | xmake/core/tool/builder.lua | 24 | ||||
| -rw-r--r-- | xmake/core/tool/tool.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/core/tools/nvcc.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/has_flags.lua | 2 |
6 files changed, 29 insertions, 23 deletions
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 653f7cbe1..5966c0c2f 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -54,7 +54,7 @@ function builder:_targetkind() end -- map gcc flag to the given builder flag -function builder:_mapflag(flag, mapflags) +function builder:_mapflag(flag, flagkind, mapflags) -- attempt to map it directly local flag_mapped = mapflags[flag] @@ -71,13 +71,13 @@ function builder:_mapflag(flag, mapflags) end -- has this flag? - if self:has_flags(flag) then + if self:has_flags(flag, flagkind) then return flag end end -- map gcc flags to the given builder flags -function builder:_mapflags(flags) +function builder:_mapflags(flags, flagkind) -- wrap flags first flags = table.wrap(flags) @@ -89,7 +89,7 @@ function builder:_mapflags(flags) -- map flags for _, flag in pairs(flags) do - local flag_mapped = self:_mapflag(flag, mapflags) + local flag_mapped = self:_mapflag(flag, flagkind, mapflags) if flag_mapped then table.insert(results, flag_mapped) end @@ -99,7 +99,7 @@ function builder:_mapflags(flags) -- has flags? for _, flag in pairs(flags) do - if self:has_flags(flag) then + if self:has_flags(flag, flagkind) then table.insert(results, flag) end end @@ -216,14 +216,14 @@ end -- add flags from the option function builder:_addflags_from_option(flags, opt) for _, flagkind in ipairs(self:_flagkinds()) do - table.join2(flags, self:_mapflags(opt:get(flagkind))) + table.join2(flags, self:_mapflags(opt:get(flagkind), flagkind)) end end -- add flags from the package function builder:_addflags_from_package(flags, pkg) for _, flagkind in ipairs(self:_flagkinds()) do - table.join2(flags, self:_mapflags(pkg:get(flagkind))) + table.join2(flags, self:_mapflags(pkg:get(flagkind), flagkind)) end end @@ -273,11 +273,11 @@ function builder:_addflags_from_target(flags, target) if (flagextra[flag] or {}).force then table.join2(targetflags, flag) else - table.join2(targetflags, self:_mapflags(flag)) + table.join2(targetflags, self:_mapflags(flag, flagkind)) end end else - table.join2(targetflags, self:_mapflags(flags)) + table.join2(targetflags, self:_mapflags(flags, flagkind)) end end @@ -296,7 +296,7 @@ function builder:_addflags_from_argument(flags, target, args) for _, flagkind in ipairs(self:_flagkinds()) do -- add auto mapping flags - table.join2(flags, self:_mapflags(args[flagkind])) + table.join2(flags, self:_mapflags(args[flagkind], flagkind)) -- add original flags local original_flags = (args.force or {})[flagkind] @@ -445,8 +445,8 @@ function builder:get(name) end -- has flags? -function builder:has_flags(flags) - return self:_tool():has_flags(flags) +function builder:has_flags(flags, flagkind) + return self:_tool():has_flags(flags, flagkind) end -- get the format of the given target kind diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua index 7b1bcaed3..7556860ab 100644 --- a/xmake/core/tool/tool.lua +++ b/xmake/core/tool/tool.lua @@ -109,13 +109,19 @@ function _instance:get(name) end -- has the given flag? -function _instance:has_flags(flags) +function _instance:has_flags(flags, flagkind) -- import has_flags() self._has_flags = self._has_flags or import("lib.detect.has_flags") + -- get base flags + local baseflags = self:get(self:kind() .. 'flags') + if not baseflags and flagkind then + baseflags = self:get(flagkind) + end + -- has flags? - return self._has_flags(self:name(), flags, {program = self:program(), toolkind = self:kind()}) + return self._has_flags(self:name(), table.join(flags, baseflags), {program = self:program(), toolkind = self:kind(), flagkind = flagkind}) end -- load the given tool from the given kind diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index e2434d0ec..a05add33e 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -105,7 +105,7 @@ function nf_symbol(self, level, target) -- check and add symbol output file flags = "-Zi -Fd" .. target:symbolfile() - if self:has_flags({"-Zi", "-FS", "-Fd" .. os.tmpfile() .. ".pdb"}) then + if self:has_flags({"-Zi", "-FS", "-Fd" .. os.tmpfile() .. ".pdb"}, "cxflags") then flags = "-FS " .. flags end else @@ -165,7 +165,7 @@ function nf_vectorext(self, extension) -- check it local flag = maps[extension] - if flag and self:has_flags(flag) then + if flag and self:has_flags(flag, "cxflags") then return flag end end @@ -215,7 +215,7 @@ function nf_language(self, stdname) local flag = maps[stdname] -- not support it? - if flag and flag:find("std:c++", 1, true) and not self:has_flags(flag) then + if flag and flag:find("std:c++", 1, true) and not self:has_flags(flag, "cxflags") then return end diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 278df4451..89773c85c 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -254,12 +254,12 @@ end -- make the rpathdir flag function nf_rpathdir(self, dir) - if self:has_flags("-Wl,-rpath=" .. dir) then + if self:has_flags("-Wl,-rpath=" .. dir, "ldflags") then return "-Wl,-rpath=" .. os.args(dir:gsub("@[%w_]+", function (name) local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"} return maps[name] end)) - elseif self:has_flags("-Xlinker -rpath -Xlinker " .. dir) then + elseif self:has_flags("-Xlinker -rpath -Xlinker " .. dir, "ldflags") then return "-Xlinker -rpath -Xlinker " .. os.args(dir:gsub("%$ORIGIN", "@loader_path")) end end @@ -330,7 +330,7 @@ function _include_deps(self, sourcefile, flags) -- support -E -MM? some old gcc does not support it at same time if _g._HAS_EMM == nil then - _g._HAS_EMM = self:has_flags("-E -MM") + _g._HAS_EMM = self:has_flags("-E -MM", "cxflags") end if not _g._HAS_EMM then return {} diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index dbbf5476d..8e64b6704 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -134,12 +134,12 @@ end -- make the rpathdir flag function nf_rpathdir(self, dir) - if self:has_flags("-Wl,-rpath=" .. dir) then + if self:has_flags("-Wl,-rpath=" .. dir, "ldflags") then return "-Wl,-rpath=" .. os.args(dir:gsub("@[%w_]+", function (name) local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"} return maps[name] end)) - elseif self:has_flags("-Xlinker -rpath -Xlinker " .. dir) then + elseif self:has_flags("-Xlinker -rpath -Xlinker " .. dir, "ldflags") then return "-Xlinker -rpath -Xlinker " .. os.args(dir:gsub("%$ORIGIN", "@loader_path")) end end diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua index 4f3d42eab..9245b3f30 100644 --- a/xmake/modules/lib/detect/has_flags.lua +++ b/xmake/modules/lib/detect/has_flags.lua @@ -87,7 +87,7 @@ function main(name, flags, opt) local arch = config.get("arch") or os.arch() -- init cache key - local key = plat .. "_" .. arch .. "_" .. tool.program .. "_" .. (tool.version or "") .. "_" .. (opt.toolkind or "") .. "_" .. table.concat(flags, " ") + local key = plat .. "_" .. arch .. "_" .. tool.program .. "_" .. (tool.version or "") .. "_" .. (opt.toolkind or "") .. "_" .. (opt.flagkind or "") .. "_" .. table.concat(flags, " ") -- @note avoid detect the same program in the same time if running in the coroutine (.e.g ccache) local coroutine_running = coroutine.running() |
