This is the fifteenth post in my SCons
series. This post introduces a small enhancement to my SCons shortcuts system – nicer support for external libraries via the with_libs
keyword argument.
In recent episodes, I needed to link with the protobuf library to use the Protocol-Buffers-based AddressBook library. I did this by adding the LIBS=['protobuf']
argument to the Program target, which works just fine.
If this works “just fine”, why mess with it? Well, I already mentioned my OCD, haven’t I? I already have a nicer way to refer to libraries I use, so why can’t I write with_libs=['AddressBook::addressbook', 'protobuf']
? It looks a bit cleaner.
The reason this would not work as is, is because I lookup the with_libs
entries in a shared dictionary of project-specific libraries (more no that in the post that introduced the shortcuts system), and “protobuf” is not a project library.
This post extends the shortcuts system to support also external libraries. In addition to improved aesthetics, I add a couple of useful features:
- Support configuration-based list of “supported external libraries”. This allows for centralized control of external libraries used across the project, which can be very useful in projects that want to enforce policies about library-usage (e.g. licensing requirements etc.).
- Simpler support for libraries that are not installed system-wide, taking care of icky details, like CPPPATH and LIBPATH crap.
- Protection against potentially difficult troubleshooting due to library name typo’s.
- External library aliases and groups.
This episode picks up where the previous episode left off. Read on for the full details, or check out the final result on my GitHub scons-series repository.