如何获取介子依赖的库路径?

问题描述 投票:0回答:2

用例: 我有一个依赖项可以回退到子项目:

./
./subprojects/
./subprojects/mylib.wrap

src/meson.build
包含:

mylib_dep = dependency('mylib')  # Searches for mylib with pkg-config then fall backs to mylib.wrap.
myexec_exe = executable ('myexec', 'myexec.c', dependencies : mylib_dep)

Dependency

mylib_dep
提供库,如果没有安装在系统上,会使我的项目的主要可执行文件无法使用:

$ meson build && cd build && meson compile src/my_exec
...snip'd...
$ src/my_exec
src/my_exec: error while loading shared libraries: libmylib.so: cannot open shared object file: No such file or directory

我的测试脚本

build/tests/mytests.sh
configure_file
d来自
tests/mytests.sh.in
以指示
myexec
的位置,我想将库路径传递给它,以便它可以调整
LD_LIBRARY_PATH
并运行可执行文件.例如,在
tests/meson.build

conf_data = configuration_data ()
conf_data.set_quoted ('MYEXEC_PATH', myexec_exe.full_path ())
conf_data.set_quoted ('MYLIB_PATH', mylib_dep.??????)
mytest_exe = configure_file (input : 'mytests.sh.in', output : 'mytests.sh', configuration : conf_data)

tests/mytests.sh.in

MYEXEC_PATH=@MYEXEC_PATH@
MYLIB_PATH=@MYLIB_PATH@
export LD_LIBRARY_PATH=$(dirname "$MYLIB_PATH"):$LD_LIBRARY_PATH
$MYEXEC_PATH

问题: 上面的

??????
应该去什么?换句话说,给定一个依赖对象,我如何提取其中的库,并获得它们的完整路径?

libraries meson-build build-dependencies
2个回答
0
投票

通常在介子中你不会 configure_file 这个,你会将库/可执行文件作为测试命令中的参数传递给脚本:

test(
  'mytest',
  find_program('mytest.sh')
  args : [executable_target, library_target, ...],
)

0
投票

试图从介子那里得到这类信息可能会令人沮丧。幸运的是,如果 Meson 使用 CMake 来查找依赖项,您可以从底层 CMake 变量中获取库路径,这些变量在 Meson 依赖项对象中可用。例如,以下内容对我有用:

mylib_dep = dependency('mylib')
if mylib_dep.found()
   mylib_path = mylib_dep.get_variable(default_value : '', cmake : 'PACKAGE_LIBRARIES')
   message('Library path is:', mylib_path)
endif
© www.soinside.com 2019 - 2024. All rights reserved.