Search code examples
fileobjectdirectoryscons

How to specify a directory for scons to store all the .o(intermediate) files?


How to specify a directory for scons to store all the .o(intermediate) files?

My question is: what's the way to set something like a global flag, so that each 'Object' command will generate .o files in a solid directory, and 'Program' command will generate in some other directory? I don't wish to have some variables so that each 'Object' and 'Program' command will explicitly use this variable: it's ugly and coupled. I just wish to have something like a compile hook.

For example, I've got a testSystem.cpp, and in SConstruct I have:

Program('testSystem.cpp')

Then scons will first compile a testSystem.o file, and link to a testSystem executible.

I know I can explicitly specify where where the binary file is stored:

Program('bin/testSystem','testSystem.cpp')

Well, the object file is still under current directory. I can do this:

testSystem_obj=Object('obj/testSystem.o','testSystem.cpp')
Program('bin/testSystem',testSystem_obj)

Now I have .o under ./obj and executible under ./bin. No problem.

But, this means for each file, I've to manually write 2 lines, 1 line to tell scons to generate the object file under ./obj, another line to generate the file under ./bin. If I wish to reorganize my whole project, I've to modify all my SConstruct/SConscript files. I've got a big project and don't want to do this.

Any hints? How to do this with scons?


Solution

  • Sort of.

    SCons supports VariantDir's which allow separating the source from the build product.

    Take a look at:

    http://scons.org/doc/production/HTML/scons-user/ch15.html