From bf6315e4e63270175eb27d9ab73dc98f3408cea8 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 2 Jun 2015 10:12:47 +0800 Subject: append config and target flags --- xmake/scripts/compiler/compiler.lua | 67 +++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 18 deletions(-) (limited to 'xmake/scripts/compiler/compiler.lua') diff --git a/xmake/scripts/compiler/compiler.lua b/xmake/scripts/compiler/compiler.lua index 7b52bd951..a4c5c59b7 100644 --- a/xmake/scripts/compiler/compiler.lua +++ b/xmake/scripts/compiler/compiler.lua @@ -59,35 +59,66 @@ function compiler._mapflags(self, flags) end -- make the compile command -function compiler._make(self, filetype, srcfile, objfile, flags) +function compiler._make(self, target, filetype, srcfile, objfile) -- check - assert(self and filetype); + assert(self and target and filetype); -- the configure local configs = self._CONFIGS assert(configs) - -- get the common flags string for the current compiler - local flags_common = nil - if filetype == "cc" then flags_common = configs.cflags - elseif filetype == "cxx" then flags_common = configs.cxxflags - elseif filetype == "mm" then flags_common = configs.mflags - elseif filetype == "mxx" then flags_common = configs.mxxflags - elseif filetype == "as" then flags_common = configs.asflags + -- the flag names + local flag_names = nil + if filetype == "cc" then flag_names = { "cxflags", "cflags" } + elseif filetype == "cxx" then flag_names = { "cxflags", "cxxflags" } + elseif filetype == "mm" then flag_names = { "mxflags", "mflags" } + elseif filetype == "mxx" then flag_names = { "mxflags", "mxxflags" } + elseif filetype == "as" then flag_names = { "asflags" } + -- error + utils.error("unknown filetype for compiler: %s", filetype) + return end - flags_common = flags_common or "" - -- map flags - flags = compiler._mapflags(self, utils.wrap(flags)) - assert(flags) - - -- make flags string - flags = table.concat(flags) - assert(flags) + -- get the common flags from the current compiler + local flags_common = "" + for _, flag_name in ipairs(flag_names) do + flags_common = string.format("%s %s", flags_common, configs[flag_name] or "") + end + + -- get the target flags from the current project + local flags_target = "" + for _, flag_name in ipairs(flag_names) do + + -- get flags + local flags = target[flag_name] + if flags then + flags = table.concat(compiler._mapflags(self, utils.wrap(flags)), " ") + end + + -- append flags + flags_target = string.format("%s %s", flags_target, flags or "") + end + + -- get the config flags + local flags_config = "" + for _, flag_name in ipairs(flag_names) do + + -- get flags + local flags = config.get(flag_name) + if flags then + flags = table.concat(compiler._mapflags(self, utils.wrap(flags)), " ") + end + + -- append flags + flags_config = string.format("%s %s", flags_config, flags or "") + end + + -- make the flags string + local flags = string.format("%s %s %s", flags_common, flags_target, flags_config) -- get it - return self._make(configs, srcfile, objfile, flags_common .. " " .. flags) + return self._make(configs, srcfile, objfile, flags) end -- load the given compiler -- cgit v1.3.1