-
Notifications
You must be signed in to change notification settings - Fork 992
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
[feature] Use PKG_CONFIG_LIBDIR and PKG_CONFIG_SYSROOT_DIR #15795
Comments
Have managed to reproduce some issues related to this - to see how we can best accommodate:
There are a few challenges, namely:
I have this working more or less but meson seems to be doing some additional path prefixing that makes this not work at all - investigating other comments:
My understanding is that
depending on how it is configured |
Probably worth noting that |
What is your suggestion?
Working on cross-compilation problems with
libselinux
in conan-io/conan-center-index#22952, I discovered that there's another pkg-config environment variable for configured the search pathsPKG_CONFIG_LIBDIR
. Apparently,PKG_CONFIG_LIBDIR
is for setting the primary search paths whilePKG_CONFIG_PATH
is for setting the secondary search paths. In the case oflibselinux
, it appears that settingPKG_CONFIG_LIBDIR
fixes issues with system directories being picked up for the build when cross-compiling.libselinux
uses an ad-hoc Makefiles-based build system.It locates the necessary compiler flags for the
pcre2
dependency by runningpkg-config --cflags libpcre2-8
.When cross-compiling and using the default
PKG_CONFIG_PATH
variable to point to Conan's generators directory,pkg-config
locates the system'spcre2
pkg-config file and adds-I/usr/include
to the compiler flags, breaking cross-compilation.The next thing I tried was to set
PKG_CONFIG_SYSROOT_DIR
to the path to my sysroot directory.This resulted in
pcre2
being picked up from my sysroot and compiling without error, although it still should have been using thepcre2
package from Conan.Finally, I set
PKG_CONFIG_LIBDIR
appropriately and viola, pkg-config found Conan'spcre2
package as expected.It occurred to me that Conan's handling of these environment variables could be greatly improved, especially since it only works with
PKG_CONFIG_PATH
. Here are the improvements I think that could be made. Note that handling of these variables might be better handled in the build system. Meson already makes several accommodations for these variables, such as:I think that it would make sense for Conan to follow suite for the pkg-config sysroot directory by doing the following:
sys_root
according to thesysroot
conf variable in the Meson cross file when it is defined.PKG_CONFIG_SYSROOT_DIR
automatically to the value of thesysroot
conf option.The handling of the
PKG_CONFIG_LIBDIR
variable is more complicated in that user's might want to incorporate system pkg-config files, especially when usingplatform_requires
. However, thePKG_CONFIG_LIBDIR
variable has a huge advantage overPKG_CONFIG_PATH
in that it has precedence. I think it makes more sense to use thePKG_CONFIG_LIBDIR
environment variable for AutotoolsToolchain andpkg_config_libdir
option for Meson to point to Conan's generated pkg-config files. This is important to ensure that the provided Conan packages are always preferred over external pkg-config files.This still leaves some gaps though, such as the fact that
PKG_CONFIG_LIBDIR
overwrites the the system pkg-config directories. This will break consumers relying on external pkg-config files. However, I think this is advantageous since it would require explicitly opting-in to using pkg-config files not provided by Conan which should improve reproducibility when creating Conan packages. To accommodate consumers and recipes wishing to use system packages, it would make sense to allow overriding the default behavior. For consumers, this would most likely be done via a conf value that allows adding paths toPKG_CONFIG_PATH
. Again, it's important that Conan packages are always preferred and usingplatform_requires
will ensure that Conan doesn't generate any pkg-config files for a given recipe, thus allowing the external pkg-config files to be picked up. System pkg-config search paths could also be added toPKG_CONFIG_PATH
so that consumers are not required to add this path explicitly.I'm pretty sure there are recipes that use system packages implicitly. If system include directories were to not be added to
PKG_CONFIG_PATH
, then recipes would probably want a convenience method to opt in to having the system pkg-config search paths added toPKG_CONFIG_PATH
.The
PKG_CONFIG_SYSROOT_DIR
is prepended to every path defined inPKG_CONFIG_PATH
, so handlingPKG_CONFIG_SYSROOT_DIR
with Conan will automatically correct system include directories, like/usr/include
, inPKG_CONFIG_PATH
for pkg-config.I think that better handling of these variables can significantly improve reproducibility while reducing the barrier of entry for those cross-compiling packages.
Have you read the CONTRIBUTING guide?
The text was updated successfully, but these errors were encountered: