The default behavior of SCons is to print the raw build commands being executed. This can cause a lot of text to fly across the screen and make it difficult to see what is going on.

CMake has nice colored output messages displaying the current source being built or the library/program being linked.

Here is something you can add to your scripts to get some nice colored output.

   1 import sys
   2 import os
   3 
   4 colors = {}
   5 colors['cyan']   = '\033[96m'
   6 colors['purple'] = '\033[95m'
   7 colors['blue']   = '\033[94m'
   8 colors['green']  = '\033[92m'
   9 colors['yellow'] = '\033[93m'
  10 colors['red']    = '\033[91m'
  11 colors['end']    = '\033[0m'
  12 
  13 #If the output is not a terminal, remove the colors
  14 if not sys.stdout.isatty():
  15    for key, value in colors.iteritems():
  16       colors[key] = ''
  17 
  18 compile_source_message = '%sCompiling %s==> %s$SOURCE%s' % \
  19    (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
  20 
  21 compile_shared_source_message = '%sCompiling shared %s==> %s$SOURCE%s' % \
  22    (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
  23 
  24 link_program_message = '%sLinking Program %s==> %s$TARGET%s' % \
  25    (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  26 
  27 link_library_message = '%sLinking Static Library %s==> %s$TARGET%s' % \
  28    (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  29 
  30 ranlib_library_message = '%sRanlib Library %s==> %s$TARGET%s' % \
  31    (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  32 
  33 link_shared_library_message = '%sLinking Shared Library %s==> %s$TARGET%s' % \
  34    (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  35 
  36 java_library_message = '%sCreating Java Archive %s==> %s$TARGET%s' % \
  37    (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  38 
  39 env = Environment(
  40   CXXCOMSTR = compile_source_message,
  41   CCCOMSTR = compile_source_message,
  42   SHCCCOMSTR = compile_shared_source_message,
  43   SHCXXCOMSTR = compile_shared_source_message,
  44   ARCOMSTR = link_library_message,
  45   RANLIBCOMSTR = ranlib_library_message,
  46   SHLINKCOMSTR = link_shared_library_message,
  47   LINKCOMSTR = link_program_message,
  48   JARCOMSTR = java_library_message,
  49   JAVACCOMSTR = compile_source_message
  50 )
  51 
  52 Export('env')

ColorBuildMessages (last edited 2009-03-22 03:35:50 by davidsawyer)