diff options
| author | ruki <[email protected]> | 2015-06-15 08:48:55 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-15 08:48:55 +0800 |
| commit | 31bba0ba7852b0699e41642815455afb62ddc8b7 (patch) | |
| tree | 214944d863b5dfd9b55e7eaba1a755d82c27f5a5 /xmake/scripts | |
| parent | 7693b33a4e39c66fa52af65c57c6f0ddaaf56bca (diff) | |
support multi-languages and fix macro defines
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/base/compiler.lua | 33 | ||||
| -rw-r--r-- | xmake/scripts/base/project.lua | 24 | ||||
| -rw-r--r-- | xmake/scripts/platform/windows/tools/cl.lua | 2 | ||||
| -rw-r--r-- | xmake/scripts/tools/gcc.lua | 2 |
4 files changed, 39 insertions, 22 deletions
diff --git a/xmake/scripts/base/compiler.lua b/xmake/scripts/base/compiler.lua index e8f2508de..0b58533e2 100644 --- a/xmake/scripts/base/compiler.lua +++ b/xmake/scripts/base/compiler.lua @@ -211,19 +211,26 @@ function compiler._addflags_from_target(module, flags, flagnames, target) })) -- add the language flags from the current project - table.join2(flags, compiler._getflags(module, target.language, { ansi = "-ansi" - , c89 = "-std=c89" - , gnu89 = "-std=gnu89" - , c99 = "-std=c99" - , gnu99 = "-std=gnu99" - , cxx98 = "-std=c++98" - , gnuxx98 = "-std=gnu++98" - , cxx11 = "-std=c++11" - , gnuxx11 = "-std=gnu++11" - , cxx14 = "-std=c++14" - , gnuxx14 = "-std=gnu++14" - })) - + local languages = {} + for _, flagname in ipairs(flagnames) do + if flagname == "cflags" or flagname == "mflags" then + table.join2(languages, { ansi = "-ansi" + , c89 = "-std=c89" + , gnu89 = "-std=gnu89" + , c99 = "-std=c99" + , gnu99 = "-std=gnu99" + }) + elseif flagname == "cxxflags" or flagname == "mxxflags" then + table.join2(languages, { cxx98 = "-std=c++98" + , gnuxx98 = "-std=gnu++98" + , cxx11 = "-std=c++11" + , gnuxx11 = "-std=gnu++11" + , cxx14 = "-std=c++14" + , gnuxx14 = "-std=gnu++14" + }) + end + end + table.join2(flags, compiler._getflags(module, target.languages, languages)) -- add the includedirs flags from the current project if module.flag_includedir then diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua index ba4b52cb4..c17060d9f 100644 --- a/xmake/scripts/base/project.lua +++ b/xmake/scripts/base/project.lua @@ -231,7 +231,7 @@ function project._filter(values) local newvals = {} for _, v in ipairs(utils.wrap(values)) do if type(v) == "string" then - v = v:gsub("%$%((.*)%)", function (w) + v = v:gsub("%$%((.-)%)", function (w) local r = config.get(w) if r and type(r) == "string" then return r elseif w == "projectdir" then return xmake._PROJECT_DIR @@ -265,7 +265,7 @@ function project._makeconf_for_target(target_name, target) end -- the prefix - local prefix = target_name:upper() .. "_CONFIG" + local prefix = (target.configprefix or target_name:upper()) .. "_CONFIG" -- open the file local file = project._CONFILES[configfile] or io.openmk(configfile) @@ -296,7 +296,9 @@ function project._makeconf_for_target(target_name, target) if target.undefines then file:write("// undefines\n") for _, undefine in ipairs(utils.wrap(target.undefines)) do - file:write(string.format("#undef %s\n", undefine)) + file:write(string.format("#ifdef %s\n", undefine)) + file:write(string.format("# undef %s\n", undefine)) + file:write("#endif\n") end file:write("\n") end @@ -305,7 +307,9 @@ function project._makeconf_for_target(target_name, target) if target.defines then file:write("// defines\n") for _, define in ipairs(utils.wrap(target.defines)) do - file:write(string.format("#define %s\n", define:gsub("=", " "))) + file:write(string.format("#ifndef %s\n", define:gsub("=.*", ""))) + file:write(string.format("# define %s\n", define:gsub("=", " "))) + file:write("#endif\n") end file:write("\n") end @@ -333,7 +337,9 @@ function project._makeconf_for_target(target_name, target) if #defines ~= 0 then file:write(string.format("// defines for %s\n", name)) for _, define in ipairs(defines) do - file:write(string.format("#define %s\n", define:gsub("=", " "))) + file:write(string.format("#ifndef %s\n", define:gsub("=.*", ""))) + file:write(string.format("# define %s\n", define:gsub("=", " "))) + file:write("#endif\n") end file:write("\n") end @@ -342,7 +348,9 @@ function project._makeconf_for_target(target_name, target) if #undefines ~= 0 then file:write(string.format("// undefines for %s\n", name)) for _, undefine in ipairs(undefines) do - file:write(string.format("#undef %s\n", undefine)) + file:write(string.format("#ifdef %s\n", undefine)) + file:write(string.format("# undef %s\n", undefine)) + file:write("#endif\n") end file:write("\n") end @@ -721,13 +729,14 @@ function project._load_targets(file) , "targetdir" , "objectdir" , "configfile" + , "configprefix" , "version" , "strip" , "options" , "symbols" , "warnings" , "optimize" - , "language"} + , "languages"} for _, interface in ipairs(interfaces) do newenv["set_" .. interface] = function (...) return project._api_set_values(newenv._TARGET or newenv._CONFIGS._SET, interface, ...) end @@ -751,6 +760,7 @@ function project._load_targets(file) , "options" , "defines" , "undefines" + , "languages" , "vectorexts"} for _, interface in ipairs(interfaces) do newenv["add_" .. interface] = function (...) return project._api_add_values(newenv._TARGET or newenv._CONFIGS._ADD, interface, ...) end diff --git a/xmake/scripts/platform/windows/tools/cl.lua b/xmake/scripts/platform/windows/tools/cl.lua index 5ede4a0b0..6a1b2fa37 100644 --- a/xmake/scripts/platform/windows/tools/cl.lua +++ b/xmake/scripts/platform/windows/tools/cl.lua @@ -90,7 +90,7 @@ end function cl.flag_define(self, define) -- make it - return "-D" .. define + return "-D" .. define:gsub("\"", "\\\"") end -- make the undefine flag diff --git a/xmake/scripts/tools/gcc.lua b/xmake/scripts/tools/gcc.lua index e54442f9a..be7abad9f 100644 --- a/xmake/scripts/tools/gcc.lua +++ b/xmake/scripts/tools/gcc.lua @@ -118,7 +118,7 @@ end function gcc.flag_define(self, define) -- make it - return "-D" .. define + return "-D" .. define:gsub("\"", "\\\"") end -- make the undefine flag |
