Question

I'm new to scons and I managed to figure out how to redirect the binaries (executables+objects) that one (con)script produces into another directory.

In my main project directory (root), I have a single SConstruct file, which contains the following line:

SConscript("source/SConscript", variant_dir="bin")

As evident, it sets the build (variant) directory of the source/SConscript script to be bin.

source/SConscript:

common = []

env = Environment()
env.Program("test", ["test.cpp"] + common)
env.Program("sdl-test", ["sdl_test.cpp"] + common, LIBS=["SDL2"])

My current setup is less than idea...

I'd like to have all the object files end up in object, keep all the source files in source, and have the final program binaries be built in bin directory.

How can I achieve that with scons? (Preferably without any messing with imperative (regular) Python, I hope that this is a built-in feature.)

Was it helpful?

Solution

You can do it by adding another SConscript script for the objects where you would set the variant_dir to a different directory, it would look something like this:

SConstruct

env = Environment()
SConscript('source/SConscript_obj', variant_dir='object',
           duplicate=0, exports='env')
SConscript('source/SConscript', variant_dir='bin',
           duplicate=0, exports='env')

source/SConscript_obj

Import('env')

env.Object("test.cpp")
env.Object("sdl_test.cpp")

source/SConscript

Import('env')

env.Program("test", ["#/object/test.o"])
env.Program("sdl-test", ["#/object/sdl_test.o"], LIBS=["SDL2"])

Or, in SConscript_obj, you could make a library instead of just compiling objects.

You could also consider adding calls to VariantDir in the existing SConscript, but Im not sure how well that would work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top