Search code examples
scons

How can I append to a construction variable in a Program() call?


I have a custom environment set up for my tests:

test_env = env.Clone()
test_env.Append(LIBS=['boost_unit_test_framework'])

But for one of my tests, I want to link against an additional library:

test_env.Program('foo_tests',
                 source='foo/tests.cpp',
                 LIBS=['extralib'],
                 LIBPATH=['.'])

Sadly this overrides the LIBS from the environment, when I'd like it to just add to it. Is there a better (i.e. more canonical) way to do this than LIBS=test_env['LIBS'] + ['extralib']?


Solution

  • Specifying a new value for an environment variable in a Builder call (like Program) is always interpreted as an "override". So there is no way around compiling the full replacement value, as you did in your example above. The other option would be to Clone the environment "test_env" again, and then use Append to add the "extralib" to LIBS...