Reputation: 413
This question is related to the meson build system, specifically how to add an external dependency (library) which is not found by pkg-config and / or cmake. This should be simple but it seems I am missing something (obvious?!).
Say I have a static library somewhere in a custom path /home/user/libraries/foo/lib/libfoo.a
with a corresponding include directory /home/user/libraries/foo/include/
. As this library is not found by pkg-config and / or cmake, doing something like
foo_dep = dependency('foo')
exe = executable('bar','bar.cpp', link_with: foo_dep)
will not work. So I am wondering what the meson way of doing things is, i.e. should I use declare_dependency()
(although I thought that this is more for subprojects), should I pass compiler and linker flags with -I
and -L -l
etc. (although that would mean specifying hard links which may be maintained manually which can't be the preferred way) or is there a better way out there for doing this?
Upvotes: 2
Views: 4091
Reputation: 2282
You use the find_library()
and has_header()
methods on the compiler object: https://mesonbuild.com/Reference-manual.html#compiler-object
Then pass that to whatever you are compiling.
cxx = meson.get_compiler('cpp')
libfoo = cxx.find_library('foo')
executable('foo', 'foo.cpp',
link_with: libfoo,
include_directories: ..., # Using has_header() find this path
)
Upvotes: 2