22

When building with Scons, I can configure it to use clang like so:

env["CXX"] = "clang++"

However, it doesn't seem to preserve the color information that clang outputs. How can I make scons preserve the color?

poolie
  • 9,289
  • 1
  • 47
  • 74
Verhogen
  • 27,221
  • 34
  • 90
  • 109

1 Answers1

40

According to the clang documentation, color is enabled only when a color-capable terminal is detected. SCons doesn't automatically pass on all environment variables to the process that runs the compiler, you have pass them explicitly. And TERM is not passed on to clang.

Add the following to your SConstruct and color should work again:

import os
env['ENV']['TERM'] = os.environ['TERM']
richq
  • 55,548
  • 20
  • 150
  • 144
  • For me it even fails to work for simple make (Makefile generated by qmake). It used to work before, no clue what could have changed (TERM=xterm) :/ – Trass3r Oct 18 '13 at 15:57
  • Is this still the recommended solution? I tried it but clang still will not produce color with my terminal and scons. TERM for me is 'xterm-256color'. When I try 'clang++ -fcolor-diagnostics' I see color. – jonr Dec 08 '15 at 00:27
  • This still works fine with clang 3.7 and scons 2.4.1 using those TERM settings (also works with TERM=screen inside tmux) must be something else that is causing your issues. – richq Dec 09 '15 at 07:18
  • Doesn't work when running scons in a docker container. I'm compiling with gcc and I've made sure the environment variables GCC_COLORS and TERM are set correctly in the container (by passing them to the docker command with -e option), but still, gcc for some strange reason thinks there isn't a proper terminal within the container. Any solutions? – AdmiralAdama Apr 09 '20 at 14:27