External libs and static libs.

877 views
Skip to first unread message

Matthieu Gautier

unread,
Dec 19, 2016, 10:28:41 AM12/19/16
to The Meson Build System
Hello everyone,

I'm pretty new in meson and I've few questions regarding libraries handling.

1. Discovering external libraries without pkg-config files.

Not all libraries have a libfoo.pc file.
I end to have custom meson code to find if the libfoo.(a|so) is
available (and associated include dir) using find_library and has_header
methods.

This ends to duplicated code with just the lib name changing. Is there a
way to factorize this code ? Is meson project is open to such a
functionality ?

2. Using external libraries without pkg-config

Dependency objects returned by dependency function are "full" : once
passed to a build target with the dependencies kword, everything work
correctly (link AND cflags are correctly set).

However, the object return by find_library set only the link flags and I
have to find another way to pass the cflags (include dir) to the build
target.

I currently use declare_dependency to create a custom dependency
specifying the lib I want to use but also the -I/my/dir flags.
But it seems that this is mainly for use in subprojects.

Is it safe to use declare_dependency this way ? Maybe a
external_dependency function may be more useful ?

(I know I could use the include_directories kwarg but I feel pity to
pass two values in two different ways as those values should be handled
together)


3. Build a static lib including the other static lib deps

My project is a lib and we have to create a static lib.

For now, the other dependency libraries are not included in the lib
itself. I have to generate a .pc files with the dependencies in the
requires fields.

This work well for libraries with pkg-config as pkg-config will find
them and add the correct flags at the binary compilation.
But for libraries without pkg-config, the binary meson.build file has to
duplicate the discovering and use of the library (point 1. and 2.) again.

However, we may want to distribute a archive containing everything and
not a "incomplete" library.

Is there a way to add a .a file to the list of objects of a static lib ?
I try to add the object return by find_library but meson refuse it
because it is not the right type. And if I want to pass a string, I have
to found the full path, and I don't know it (this why I use find_library).


Best regards,
Matthieu Gautier.

signature.asc

Jussi Pakkanen

unread,
Dec 23, 2016, 12:17:50 PM12/23/16
to Matthieu Gautier, The Meson Build System
On Mon, Dec 19, 2016 at 5:28 PM, Matthieu Gautier <d...@mgautier.fr> wrote:
> 1. Discovering external libraries without pkg-config files.
>
> Not all libraries have a libfoo.pc file.
> I end to have custom meson code to find if the libfoo.(a|so) is
> available (and associated include dir) using find_library and has_header
> methods.
>
> This ends to duplicated code with just the lib name changing. Is there a
> way to factorize this code ? Is meson project is open to such a
> functionality ?

You can use a foreach loop with an array that has your data. However
the best possible fix is to get upstream to add pkg-config files to
their projects. Anything else is fragile and just waiting to fail on
you unexpectedly.

> 2. Using external libraries without pkg-config
>
> I currently use declare_dependency to create a custom dependency
> specifying the lib I want to use but also the -I/my/dir flags.
> But it seems that this is mainly for use in subprojects.

That is exactly how to do it. It does not matter whether they contain
only external stuff or internal as well. It all works.

> Is there a way to add a .a file to the list of objects of a static lib ?
> I try to add the object return by find_library but meson refuse it
> because it is not the right type. And if I want to pass a string, I have
> to found the full path, and I don't know it (this why I use find_library).

Put it in dependencies. Meson will then use it automatically when you
use the self built library.
Reply all
Reply to author
Forward
0 new messages