With the change "[RFC] add prefer_static built-in option" (9603)
from https://github.com/mesonbuild/meson
Also: 6697 and 6629
It is now possible to have meson call pkg-config with the
--static flag and bring in the Requires.private dependent
libaries when linking. There is no further need to modify
the .pc files (or the linker flags.)
The use of the -Dprefer_static=true will cause the linker
to prefer and use the static library if it is available,
which might not be intended if the shared library is also
available.
This option will force the static linkage, whereas passing
the libraries from pkg-config --static to ld would pick
the shared libraries over the static libraries. With the
linker options removing any unnecessary libraries:
-Wl,--as-needed, -Wl,-dead_strip_dylibs
The example below is how to force the linker to use the
foo static library when a foo shared library is available.
gcc main.o -Wl,-Bstatic -lfoo -Wl,-Bdynamic
Which is what this meson option `prefer_static=true` will
do for all static libaries that it finds (regardless of
if shared libraries are available.)
ref: https://stackoverflow.com/questions/71078862/prefer-static-libraries-but-fallback-to-shared-if-not-found