This page demonstrates how to tell SCons to build multiple variants of your software all at the same time, for example:
- debug and release versions
- host and target versions
SConstruct:
src/SConscript:
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:
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.
