mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.65k stars 1.64k forks source link

CMake dependencies add absolute paths to pkgconfig Libs #13965

Open kone-tlammi opened 5 days ago

kone-tlammi commented 5 days ago

Describe the bug When using pkgconfig module to generate .pc files for a project that depend on cmake projects the resulting .pc file has absolute paths to libraries.

This behavior causes issues with Yocto builds where resulting .pc files have absolute paths pointing to a different sysroot which might not exist when some other component is consuming the said .pc.

To Reproduce meson.build

project('sample', 'cpp')

dep = dependency('OpenSSL', modules: ['OpenSSL::SSL'], method: 'cmake')

lib = static_library('lib', 'lib.cpp', dependencies: dep)
pkgconf = import('pkgconfig')
pkgconf.generate(name: 'lib', filebase: 'lib', description: 'lib', libraries: lib)

Resulting lib.pc

prefix=/usr/local
includedir=${prefix}/include
libdir=${prefix}/lib

Name: lib
Description: lib
Version: undefined
Libs: -L${libdir} -llib /usr/lib/libcrypto.so /usr/lib/libssl.so
Cflags: -I${includedir} -I/usr/include

Expected behavior Libs field should have -lcrypto -lssl or there should be some more manual way to avoid the current behavior.

system parameters

eli-schwartz commented 5 days ago

IIRC the problem here is that cmake dependency lookup only exposes the absolute path to a library. Meson tries to avoid this whenever it can, but "whenever it can" means when using find_library or dependency.

For OpenSSL in particular meson has a method: 'system' that will probably in most cases yield a superior result rather than using cmake. The example only works because it hardcodes an (unlikely) method. Other dependencies especially where the upstream project doesn't provide pkgconfig files at all and the only dependency finder is cmake, would make a more useful example.

kone-tlammi commented 4 days ago

Yeah I thought this might be a cmake issue. In my actual use case the OpenSSL is not a direct dependency but acquired via paho-mqtt-c. I avoided the issue by replacing the dependencies with bunch of calls to cpp.find_library. I guess there is no better approach here?

eli-schwartz commented 4 days ago

Well, https://github.com/eclipse-paho/paho.mqtt.c/pull/756 might help.