1

In Makefile, I can write something like below to get the dependencies libs.

LIBS:= $(shell pkg-config --libs $(PKGS))

But in meson.build, I don't know how to write simply like this.

I can use run_command to get libs like below,

r = run_command('pkg-config', '--cflags', 'gstreamer-1.0 gstreamer-video-1.0')
if r.returncode() != 0
  # it failed
  errortxt = r.stderr().strip()
  message(errortxt)
endif
output = r.stdout().strip().split(' ')
message(output)
foreach inc : output
    add_global_arguments(inc, language : 'c')
endforeach

so what is best practice to use pkg-config ?

---- UPDATE ----

Using

dependency('gstreamer-video-1.0', 'pkg-config') 

will take all effects on build.ninja

 LINK_ARGS = -Wl,--as-needed -Wl,--no-undefined -Wl,--start-group -lm -Wl,-rpath,/opt/nvidia/deepstream/deepstream-5.1/lib:/usr/local/cuda-10.2/lib64 -Wl,-rpath-link,/opt/nvidia/deepstream/deepstream-5.1/lib -Wl,-rpath-link,/usr/local/cuda-10.2/lib64 /opt/nvidia/deepstream/deepstream-5.1/lib/libnvdsgst_meta.so /opt/nvidia/deepstream/deepstream-5.1/lib/libnvds_meta.so /opt/nvidia/deepstream/deepstream-5.1/lib/libnvdsgst_helper.so /usr/lib/aarch64-linux-gnu/libgstreamer-1.0.so /usr/lib/aarch64-linux-gnu/libgobject-2.0.so /usr/lib/aarch64-linux-gnu/libglib-2.0.so /usr/lib/gcc/aarch64-linux-gnu/7/../../../aarch64-linux-gnu/libcuda.so /usr/local/cuda-10.2/lib64/libcudart.so /usr/lib/aarch64-linux-gnu/libgstrtspserver-1.0.so /usr/lib/aarch64-linux-gnu/libgstvideo-1.0.so /usr/lib/aarch64-linux-gnu/libgstbase-1.0.so -Wl,--end-group

but not on compile_commands.json

[
  {
    "directory": "/home/ubuntu/work/deepstream-5.1/sources/apps/sample_apps/test3_meson/build",
    "command": "cc -Itest1.p -I. -I.. -I/usr/local/cuda-10.2/include -I../../../../includes -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include -I/usr/include/orc-0.4 -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -g -DPLATFORM_TEGRA -pthread -MD -MQ test1.p/deepstream_test3_app.c.o -MF test1.p/deepstream_test3_app.c.o.d -o test1.p/deepstream_test3_app.c.o -c ../deepstream_test3_app.c",
    "file": "../deepstream_test3_app.c"
  }
]

So if changes meson.build, should better see effects in build.ninja.

alen
  • 111
  • 1
  • 3
  • 14
  • I believe that's just the commands to compile that .c intro a .o file, there should be another entry in compile_commands.json to link the various .o files where the link arguments show up – dcbaker Aug 26 '21 at 15:47
  • But in my compile_commands.json, there is only one entry. – alen Aug 27 '21 at 07:38
  • I see the includes for your dependencies in there, so the dependencies are registering – dcbaker Aug 28 '21 at 01:41

1 Answers1

2

Meson provides the dependency() abstraction for working with pkg-config, cmake, various *-config tools, and a few built in dependencies that Meson has to save everyone reimplementing them, you would simply write:

dep_gstreamer = dependency('gstreamer-1.0')
dep_gsreamer_video = dependency('gstreamer-video-1.0')
# note that each dependency call finds 1 dependency

then you'd pass them to your targets:

build_target(
  'name',
  sources,
  dependencies : [dep_gstreamer, dep_gstreamer_video]
)

Under the hood Meson will call pkg-config, parse the outputs, and create dependency objects that hold the various arguments to be passed. It can also fall back to using cmake or other even building those projects from source if necessary.

If you only want to pass the compiler flags, and not the linker flags as well, then you can do this:

dep_gstreamer = dependency('gstreamer-1.0').partial_dependency(compile_args : true)

You then pass that as a dependency like normal, as it is a dependency, but one that only passes compiler flags, and not link flags.

As an aside, you really shouldn't use add_global_arguments(), it affects all subprojects as well, instead use add_project_arguments().

dcbaker
  • 643
  • 2
  • 7