简体   繁体   中英

declare library dependency in meson not found by pkg-config and cmake

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, ie 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?

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
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM