PkgConfig
Warning
These tools are still experimental (so subject to breaking changes) but with very stable syntax. We encourage their usage to be prepared for Conan 2.0.
Available since: 1.45.0
This tool can execute pkg_config
executable to extract information from existing .pc
files.
This can be useful for example to create a “system” package recipe over some system installed library,
as a way to automatically extract the .pc
information from the system. Or if some proprietary package
has a build system that only outputs .pc
files.
The constructor is:
def __init__(self, conanfile, library, pkg_config_path=None):
conanfile
: The currentself
instance of the conanfile using the toollibrary
: The library which.pc
file is to be parsed. It must exist in the pkg_config pathpkg_config_path
: If defined it will be prepended toPKG_CONFIG_PATH
environment variable, so the execution finds the required files.
It can be used as:
pkg_config = PkgConfig(conanfile, "libastral", pkg_config_path=<somedir>)
print(pkg_config.provides) # something like"libastral = 6.6.6"
print(pkg_config.version) # something like"6.6.6"
print(pkg_config.includedirs) # something like['/usr/local/include/libastral']
print(pkg_config.defines) # something like['_USE_LIBASTRAL']
print(pkg_config.libs) # something like['astral', 'm']
print(pkg_config.libdirs) # something like['/usr/local/lib/libastral']
print(pkg_config.linkflags) # something like['-Wl,--whole-archive']
print(pkg_config.variables['prefix']) # something like'/usr/local'
There is a convenience method fill_cpp_info()
, that can be used in the package_info()
method as:
def package_info(self):
pkg_config = PkgConfig(conanfile, "libastral", pkg_config_path=tmp_dir)
pkg_config.fill_cpp_info(self.cpp_info, is_system=False, system_libs=["m", "rt"])
Where:
cpp_info
first argument could be the global one or a component one.is_system
: ifTrue
, all detected libraries will be assigned tocpp_info.system_libs
, and none tocpp_info.libs
.system_libs
: Ifis_system=False
, this argument allows defining some potential system libraries found that would be assigned tocpp_info.system_libs
. The remaining detected libs will be assigned tocpp_info.libs
.
conf
This helper will listen to tools.gnu:pkg_config
configuration to define the pkg_config
executable name or full path.
It will by default it is pkg-config
.