The &variant_dir; keyword argument of
the &SConscript; function provides everything
we need to show how easy it is to create
variant builds using &SCons;.
Suppose, for example, that we want to
build a program for both Windows and Linux platforms,
but that we want to build it in a shared directory
with separate side-by-side build directories
for the Windows and Linux versions of the program.
platform = ARGUMENTS.get('OS', Platform())
include = "#export/$PLATFORM/include"
lib = "#export/$PLATFORM/lib"
bin = "#export/$PLATFORM/bin"
env = Environment(PLATFORM = platform,
BINDIR = bin,
INCDIR = include,
LIBDIR = lib,
CPPPATH = [include],
LIBPATH = [lib],
LIBS = 'world')
Export('env')
env.SConscript('src/SConscript', variant_dir='build/$PLATFORM')
Import('env')
SConscript('hello/SConscript')
SConscript('world/SConscript')
Import('env')
hello = env.Program('hello.c')
env.Install('$BINDIR', hello)
#include "world.h"
int main(int argc, char *argv[]) { printf "hello.c\n"; world(); }
Import('env')
world = env.Library('world.c')
env.Install('$LIBDIR', world)
env.Install('$INCDIR', 'world.h')
#define STRING "world.h"
extern int world();
int world() { printf "world.c\n"; }
This SConstruct file,
when run on a Linux system, yields:
scons -Q OS=linux
The same SConstruct file on Windows would build:
scons -Q OS=windows