How to force Scons output (exe, obj, lib & dll) to specific build directory?

Waldo Bronchart picture Waldo Bronchart · Sep 15, 2010 · Viewed 9.6k times · Source

I've been trying to get scons to output exe, obj, lib and dll files to a specific build directory.

My file structure looks like this:

/projectdir
  /build
    /bin
    /obj
  /source
    /subdirs
    /..
  SConstruct

Basically, what I get now is my source directory is getting polluted with obj files. I'd rather have it all in one place.

The SConstruct file looks like this:

env.VariantDir('build', 'source', duplicate = 0)
env.Program('Hierarchy', source = ['source/sconstest.cpp', 'source/utils/IntUtil.cpp'])

Answer

richq picture richq · Sep 15, 2010

The easiest way I've found is to use 2 files, a SConstruct file and a separate SConscript.

In the SConstruct you simply call the other file and specify the directory for the build output:

# content SConstruct
SConscript('main.scons', variant_dir='build', duplicate=0)

Then in 'main.scons' you do the meat of your build. You can forget about variant directories in this file.

# content of main.scons
env = Environment()
env.Program('Hierarchy',
            source = ['source/sconstest.cpp', 'source/utils/IntUtil.cpp'])