[Scons-users] [Scons-dev] Checking for a library or header and fail

Bill Deegan bill at baddogconsulting.com
Thu Aug 25 16:23:23 EDT 2016


Florian,

I'm going to cc the scons users mailing list as this email is about using
SCons and not about the internal development of SCons (the purpose of the
scons-dev mailing list).

Please move the remaining discussion there.

See further comments below.

On Thu, Aug 25, 2016 at 2:07 AM, Florian Lindner <mailinglists at xgm.de>
wrote:

> Hello,
>
> in almost all of my scons projects, I have a piece of code like that one:
>
> def uniqueCheckLib(conf, lib, header = None):
>     if header:
>         if not conf.CheckLibWithHeader(lib, header = header, autoadd=0,
> language="C++"):
>             print "ERROR: Library '" + lib + "' or header '" + header + "'
> not found."
>             Exit(1)
>     else:
>         if not conf.CheckLib(lib, autoadd=0, language="C++"):
>             print "ERROR: Library '" + lib + "' not found!"
>             Exit(1)
>
>     conf.env.AppendUnique(LIBS = [lib])
>
> This is needed because of some shortcommings of CheckLib /
> CheckLibWithHeader.
>
> 1) CheckLib adds the library to LIBS, even if it is already present. That
> can cause problem. What is the use case for that?
>

In the case when linking against static libraries, it can be necessary to
list libraries more than once.
Barring that need (assuming all shared libraries), you could do something
like:
env['LIBS'] = list(set(env['LIBS']))


>
> 2) In almost all cases, if a library is not found, I want the build to
> terminate. CheckLib should (optionally) print a nice error message and
> aborts the build, if the check fails.
>

It would seem that would just be a convenience change, as you can check the
return value from CheckLib (as you are already doing), and exit if
required.  To be consistant it would be necessary to also provide this to
all the other Configure checkers, and also (perhaps) make that a mandatory
part of custom checkers.

If you'd like to make such a change and send a pull request, please feel
free.

>
> Why not having a function:
>
> AssureLibOrHeader(context,
>   library = None,
>   header = None,
>   [...])
>
> If tests for library and the header, if given. If the check fails, it
> prints a nice error messages and fails.
>
> Another idea what be to enhance the existings checks with a flag,
> abortOnFail, which prints an error messages and exists.
>
> If such a change would have any chance of inclusion, I would try to
> implement it into scons.
>
> What do you think? Are there alternatives I overlooked?
>

see above.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20160825/b5b3b501/attachment.html>


More information about the Scons-users mailing list