summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-20 23:28:01 +0800
committerruki <[email protected]>2020-02-20 14:48:10 +0800
commit3a5c3f41d66dceb79fa4a61faaefce2421da8160 (patch)
tree4392e1beb0e001ddded114b598390ea241c53210
parent8079f41e1a5143cc31780a8763bb83b6bcf3c1c9 (diff)
enable color-diagnostics for gcc/clang
-rw-r--r--xmake/modules/core/tools/gcc.lua23
1 files changed, 22 insertions, 1 deletions
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 2872c88da..a32311454 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -20,6 +20,7 @@
-- imports
import("core.base.option")
+import("core.base.colors")
import("core.project.config")
import("core.project.project")
import("core.language.language")
@@ -355,6 +356,21 @@ function link(self, objectfiles, targetkind, targetfile, flags)
os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags))
end
+-- has color diagnostics?
+function _has_color_diagnostics(self)
+ local colors_diagnostics = _g._HAS_COLOR_DIAGNOSTICS
+ if colors_diagnostics == nil then
+ if io.isatty() and colors.color256() then
+ local theme = colors.theme()
+ if theme and theme:name() ~= "plain" then
+ colors_diagnostics = self:has_flags("-fcolor-diagnostics", "cxflags") or false
+ end
+ end
+ colors_diagnostics = colors_diagnostics or false
+ _g._HAS_COLOR_DIAGNOSTICS = colors_diagnostics
+ end
+ return colors_diagnostics
+end
-- make the compile arguments list for the precompiled header
function _compargv1_pch(self, pcheaderfile, pcoutputfile, flags)
@@ -414,7 +430,12 @@ function _compile1(self, sourcefile, objectfile, dependinfo, flags)
-- generate includes file
local compflags = flags
if depfile and _g._HAS_MMD_MF then
- compflags = table.join(flags, "-MMD", "-MF", depfile)
+ compflags = table.join(compflags, "-MMD", "-MF", depfile)
+ end
+
+ -- has color diagnostics?
+ if _has_color_diagnostics(self) then
+ compflags = table.join(compflags, "-fcolor-diagnostics")
end
-- do compile