7

I'm trying to modify my SCons files so that they put the generated files into a build directory. Initially I though VariantDir could be an option but judging from all I read and the examples it does not do what I want.

Is there any easy way to force SCons to put the output in a certain directory without having to rewrite all the sources and scripts?

3
  • What's the problem with VariantDir? Did you try using duplicate=0? Nov 12, 2011 at 18:36
  • For use of VariantDir you have to sell your whole soul. Which means you either have to do everything in the VariantDir or nothing. The thing I and a lot of others want is to put only generated stuff into the build dir and not everything.
    – abergmeier
    Nov 13, 2011 at 16:37
  • Isn't that what duplicate=0 does? From the docs: Duplicating the source tree may be disabled by setting the duplicate argument to 0 (zero). This will cause scons to invoke Builders using the path names of source files in src_dir and the path names of derived files within variant_dir. Nov 14, 2011 at 6:22

4 Answers 4

3

After struggling with VariantDir for a while (it wasn't doing anything at all), I ended up using variant_dir parameter in the top level SConscript call, which causes all downstream build outputs end up in a parallel 'build' tree: SConscript(['subdirs/SConscript'], variant_dir='build', duplicate=0) My build structure is a hierarchy of SConscripts in subdirs/sub-subdirs, etc. With this call the outputs end up in build/sub-subdirs at the same level as they would in the source.

This eats up one level, though (subdirs), and using "../build" does not help. The solution is to have a SConscript file at the same level as SConstruct and call SConscript(['SConscript'], variant_dir='build', duplicate=0)

See also Force Scons output (exe, obj, lib & dll) to specific build directory - it has a similar answer

1

Using VariantDir with duplicate=0 should work.

1
  • This would require me to rewrite the majority of build scripts.
    – abergmeier
    Nov 13, 2011 at 16:35
0

Facing similar frustration, I added a site_scons that added replacement builders (e.g. "Exe" instead of "Program") and specified an emitter for that builder that replaced the path portion with the build directory. This requires the use of the alternate builder throughout your SConscripts though.

Alternatively you could try to subclass Environment and rewrite the main targets to use target rewrites. Then you specify your Environment as the default (modifying Scons.Script.DefaultEnvironment or something like that). This approach kept the SConscripts static but got very messy and requires more maintenance over time as scons internals change.

0

You might use Install or InstallAs on target output. It works for me.

lib = env.SharedLibrary(target = "some_target", source = sources);
env.InstallAs( target = "folder/output_name.ext", source = lib );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.