Search code examples
buildenvironment-variablesscons

How to build in different environments with SCons?


I just discovered SCons, a great build tool.

I need to build my project in multiple environments, i.e. with different library paths and include paths depending on the machine.

Since SConstruct has all of Python available, I can imagine various ways to accomplish this. One possibility would be to have a single SConstruct script and instantiate multiple Environment objects.

envFoo = Environment()
envFoo.Append(CPPPATH = [...])

envBar = Environment()
envBar.Append(CPPPATH = [...])

Then select one of these Environment objects somehow, possibly with a command line parameter to scons.

A question for experienced scons users: Is this the way to go? What is the most convenient way of doing this?


Solution

  • This would definitely work, and would probably be a good solution for simpler situations. I have a more complex situation where I actually create an EnvironmentFactory using Python classes, something like this:

    env = EnvironmentFactory.createEnv(cmdLineArgs)
    

    Another useful SCons tool would be to "automatically" populate the Environment from the command line options using the ParseFlags(), ParseConfig(), and MergeFlags() as described in this chapter.