Configuring the right options to build programs to work with
libraries--especially shared libraries--that are available
on POSIX systems can be complex.
To help this situation,
various utilies with names that end in
return the command-line options for the GNU Compiler Collection (GCC)
that are needed to build and link against those libraries;
for example, the command-line options
to use a library named
could be found by calling a utility named lib-config.
A more recent convention is that these options are available through the generic pkg-config program, providing a common framework, error handling, and the like, so that all the package creator has to do is provide the set of strings for his particular package.
SCons construction variables have a
method that asks the host system to execute a command
and then configures the appropriate construction variables based on
the output of that command.
This lets you run a program like pkg-config
or a more specific utility to help set up your build.
env = Environment() env['CPPPATH'] = ['/lib/compat'] env.ParseConfig("pkg-config x11 --cflags --libs") print("CPPPATH:", env['CPPPATH'])
SCons will execute the specified command string, parse the resultant flags, and add the flags to the appropriate environment variables.
scons -QCPPPATH: ['/lib/compat', '/usr/X11/include'] scons: `.' is up to date.
In the example above, SCons has added the include directory to
(Depending upon what other flags are emitted by the
other variables may have been extended as well.)
Note that the options are merged with existing options using
so that each option only occurs once in the construction variable.
env = Environment() env.ParseConfig("pkg-config x11 --cflags --libs") env.ParseConfig("pkg-config x11 --cflags --libs") print("CPPPATH:", "CPPPATH:", env['CPPPATH'])
scons -QCPPPATH: ['/usr/X11/include'] scons: `.' is up to date.