문제

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.)

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top