By default SCons goes to great lengths to give you an accurate and reproducible build. If you have a slow computer or a large build, there are various options that can make SCons faster by sacrificing accuracy:

The command 'scons --max-drift=1 --implicit-deps-unchanged' will execute your build as fast as possible.

Another trick to making things faster is to avoid relinking programs when a shared library has been modified but not rebuilt. See SharedLibrarySignatureOverride

---

The following was suggested by leanid nazdrynau in scons-users, May 2006:

   1 #Next line is important, it deactivates tools search for default variable, just note that now in SConscript you have 
   2 #to use env.Program(...) instead of simply Program().
   3 
   4 SCons.Defaults.DefaultEnvironment(tools = []) 

Note on the CPPPATH trick

The CPPPATH trick mentioned above made a great difference for me, because I have many libraries installed in non-standard directories (e.g. these from Fink), and these directories end up explicitly referenced in compiler command lines.

However, for this trick to work, CCFLAGS (CXXFLAGS) has to come *after* CPPFLAGS (which are in $_CCCOMCOM) in the compiler command line. If not, the compiler will typically include the installed headers from the library I am developing, instead of including the local headers referenced by, say, env.Prepend(CPPPATH = [ '#mylibheaders' ]).

Here is the code I use to put CCFLAGS after CPPFLAGS. It also imports software resource paths from env variables. (Any comments to make this easier would be welcome.)

   1 # CPPPATH trick, see http://www.scons.org/wiki/GoFastButton
   2 
   3 # For this to work, CCFLAGS (CXXFLAGS) have to come *after*
   4 # CPPFLAGS (which are in $_CCCOMCOM)
   5 if env['CXXCOM'] == "$CXX -o $TARGET -c $CXXFLAGS $_CCCOMCOM $SOURCES":
   6   # SCons 0.97
   7   env['CXXCOM'] = "$CXX -o $TARGET -c $_CCCOMCOM $CXXFLAGS $SOURCES"
   8 elif env['CXXCOM'] == "$CXX -o $TARGET -c $CXXFLAGS $CCFLAGS $_CCCOMCOM $SOURCES":
   9   # SCons 0.98
  10   env['CXXCOM'] = "$CXX -o $TARGET -c $_CCCOMCOM $CXXFLAGS $CCFLAGS $SOURCES"
  11 else:
  12   print "Unexpected default CXXCOM"
  13   Exit(1)
  14 
  15 if env['SHCXXCOM'] == "$SHCXX -o $TARGET -c $SHCXXFLAGS $_CCCOMCOM $SOURCES":
  16   # SCons 0.97
  17   env['SHCXXCOM'] = "$SHCXX -o $TARGET -c $_CCCOMCOM $SHCXXFLAGS $SOURCES"
  18 elif env['SHCXXCOM'] == "$SHCXX -o $TARGET -c $SHCXXFLAGS $SHCCFLAGS $_CCCOMCOM $SOURCES":
  19   # SCons 0.98
  20   env['SHCXXCOM'] = "$SHCXX -o $TARGET -c $_CCCOMCOM $SHCXXFLAGS $SHCCFLAGS $SOURCES"
  21 else:
  22   print "Unexpected default SHCXXCOM"
  23   Exit(1)
  24 
  25 # process env variables
  26 for K in ['CPPFLAGS', 'CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'CC', 'CXX']:
  27   if K in os.environ:
  28     dict = env.ParseFlags(os.environ[K])
  29     # These headers are supposed static. Don't check at each build.
  30     for i in dict['CPPPATH']: 
  31       dict['CCFLAGS'].append('-I' + i)
  32     dict['CPPPATH'] = []
  33     env.MergeFlags(dict)

Another solution was suggested by Roberto De Vecchi on scons-users:

After the env initialization, I'm overriding _CCINCFLAGS as follow:

env['_CPPINCFLAGS']='$( ${_concat(INCPREFIX, CPPPATH,         INCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)' +\
                    '$( ${_concat(INCPREFIX, CPP3RDPARTYPATH, INCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'

So I can selectively add an include path to CCPPATH or CPP3RDPARTYPATH and have both of them passed to the compiler but only having scons scan the CPPPATH dirs..

Caching the CPPDEFINES flags in the compiler command

c_defs = ['FOO1', 'FOO2'. ... , 'FOO100']
import copy
def_str = ' -D'.join(c_defs)

cccom = copy.copy(env['CCCOM'])
cccom = cccom.replace('CCFLAGS', 'CCFLAGS -D%s ' % def_str)

shcccom = copy.copy(env['SHCCCOM'])
shcccom = shcccom.replace('CCFLAGS', 'CCFLAGS -D%s ' % def_str)

cxxcom = copy.copy(env['CXXCOM'])
cxxcom = cxxcom.replace('CCFLAGS', 'CCFLAGS -D%s ' % def_str)

shcxxcom = copy.copy(env['SHCXXCOM'])
shcxxcom = shcxxcom.replace('CCFLAGS', 'CCFLAGS -D%s ' % def_str)

fasterEnv = env.Clone(
    CCCOM = cccom,
    CXXCOM = cxxcom,
    SHCCCOM = shcccom,
    SHCXXCOM = shcxxcom,
    )   

GoFastButton (last edited 2010-01-26 04:48:21 by Cs-32-131)