[Scons-users] Pass multiple build flags on the command line

Dirk Bächle tshortik at gmx.de
Sat Aug 9 19:22:55 EDT 2014


Hi Bertrand,

On 09.08.2014 16:00, Bertrand Marc wrote:
> Dear Scons users,
>
> I am trying to build pingus with custom build flags. I'd like to pass
> two flags to g++ (-g -O2), so I launch the following:
> scons CXXFLAGS='-g -O2'
>
> Unfortunately it fails because the Sconstruct file appends
> ["-std=c++0x"] after CXXFLAGS and env.Append doesn't mix well lists and
> strings.

in your SConstruct the Variable "CXXFLAGS" gets initialized as:

           self.opts.Add('CXXFLAGS', 'C++ Compiler flags', ['-O2', '-s'])

, which means that it's set either to a string (when set on the command 
line) or a list by default. SCons offers a special variable type named 
CLVar, which is able to handle strings and lists interchangeably. What 
makes this interesting for your case is, that it automatically Split()s 
strings in the constructor, so

   CLVar("key1 key2")

is then internally handled as list ['key1', 'key2']. The Variable's 
Add() function offers a special keyword "converter", where you can 
specify a wrapper method that gets applied to the given value, before 
assigning it to the Environment.

So, if you instead use:

           self.opts.Add('CXXFLAGS', 'C++ Compiler flags', ['-O2', 
'-s'], converter=SCons.Util.CLVar)

, the single options should get passed without additional "quotes" to 
the compiler.

Best regards,

Dirk



More information about the Scons-users mailing list