Please note:The SCons wiki is in read-only mode due to ongoing spam/DoS issues. Also, new account creation is currently disabled. We are looking into alternative wiki hosts.

This page demonstrates how to tell SCons to build multiple variants of your software all at the same time, for example:

SConstruct:

   1 release_env = Environment(CCFLAGS = ['-O2'])
   2 debug_env = release_env.Copy(CCFLAGS = ['-g'])
   3 
   4 SConscript('src/SConscript', build_dir='release', exports={'env':release_env})
   5 SConscript('src/SConscript', build_dir='debug', exports={'env':debug_env})

src/SConscript:

   1 Import('env')
   2 env.Program('hello', ['hello.c'])

Output:

$ scons
gcc -g -c -o debug/hello.o debug/hello.c
gcc -o debug/hello debug/hello.o
gcc -O2 -c -o release/hello.o release/hello.c
gcc -o release/hello release/hello.o

Here's the same sort of thing for windows using the Microsoft C++ compiler. In the SConstruct:

   1 base_env = Environment(tools = ["msvc", "mslink"])
   2 
   3 # Build different variants:
   4 for flavour in ["Debug", "Release"]:
   5     env = base_env.Copy()
   6     
   7     # Set up compiler and linker flags:
   8     if flavour == "Debug":
   9         # Use debug multithreaded DLL runtime, and no optimization
  10         env.Append(CCFLAGS = ["/MDd", "/Od"])
  11         # Each object has its own pdb, so -jN works
  12         env.Append(CCFLAGS = ["/Zi", "/Fd${TARGET}.pdb"])
  13         env.Append(LINKFLAGS = ["/DEBUG"])
  14     else:
  15         # Use multithreaded DLL runtime, and some sensible amount of optimization
  16         env.Append(CCFLAGS = ["/MD", "/Ox"])
  17 
  18     # Call the SConstruct for each subproject.
  19     SConscript(
  20             "hello/SConscript",
  21             exports = ["env"],
  22             build_dir = flavour + "/hello",
  23             duplicate = 0,
  24             )
  25     SConscript(
  26             "world/SConscript",
  27             exports = ["env"],
  28             build_dir = flavour + "/world",
  29             duplicate = 0,
  30             )

And this is the contents of hello/SConscript:

   1 # Make sure we don't change the imported environment by mistake:
   2 Import("env")
   3 imported_env = env
   4 env = env.Copy()
   5 
   6 # Set up things for this project
   7 env.AppendUnique(CPPPATH = ["."])
   8 
   9 hello_t = env.Program(
  10         target = "hello",
  11         source = ["hello.c"],
  12         )

And the output:

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cl /nologo /MDd /Od /Zi /FdDebug\hello\hello.obj.pdb /IDebug\hello /Ihello /c hello\hello.c /FoDebug\hello\hello.obj hello.c
link /nologo /DEBUG /OUT:Debug\hello\hello.exe Debug\hello\hello.obj
cl /nologo /MD /Ox /IRelease\hello /Ihello /c hello\hello.c /FoRelease\hello\hello.obj hello.c
link /nologo /OUT:Release\hello\hello.exe Release\hello\hello.obj
...
scons: done building targets.

Thanks to Werner Schiendl for posting this solution to the mailing list.

SimultaneousVariantBuilds (last edited 2009-09-16 11:37:51 by IanVaughan)