Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake dependencies add absolute paths to pkgconfig Libs #13965

Open
kone-tlammi opened this issue Nov 27, 2024 · 3 comments
Open

CMake dependencies add absolute paths to pkgconfig Libs #13965

kone-tlammi opened this issue Nov 27, 2024 · 3 comments

Comments

@kone-tlammi
Copy link

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

  • Is this a cross build or just a plain native build (for the same computer)?
    • Sample is for native builds but this also happens for cross builds
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.)
    • Manjaro Linux (Ubuntu 22.04 for Yocto)
  • what Python version are you using e.g. 3.8.0
    • Python 3.12.6 (3.10.14 in Yocto)
  • what meson --version
    • Native 1.6.0 (1.3.1 in Yocto)
  • what ninja --version if it's a Ninja build
    • Native 1.12.1 (1.10.2 in Yocto)
@eli-schwartz
Copy link
Member

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
Copy link
Author

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
Copy link
Member

Well, eclipse-paho/paho.mqtt.c#756 might help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants