aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorFredrik Salomonsson <plattfot@posteo.net>2022-04-12 18:16:59 -0700
committerEli Schwartz <eschwartz93@gmail.com>2022-04-19 17:35:08 -0400
commit2e31330fe6126a024be72901286f9ff7e76ea904 (patch)
treeac9e4bd9284acb83222abf8bf50414fd05b93733 /mesonbuild
parent09ad4e28f1a59ab3d87de6f36540a108e836cfe5 (diff)
downloadmeson-2e31330fe6126a024be72901286f9ff7e76ea904.zip
meson-2e31330fe6126a024be72901286f9ff7e76ea904.tar.gz
meson-2e31330fe6126a024be72901286f9ff7e76ea904.tar.bz2
pkgconfig: Add relocatable module option
If set to true it will generate the pkgconfig files as relocatable i.e the prefix variable will be relative to the install_dir. By default this is false. Will generate a MesonException if the pkgconfig file is installed outside of the package and pkgconfig.relocatable=true.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/coredata.py4
-rw-r--r--mesonbuild/modules/pkgconfig.py16
2 files changed, 18 insertions, 2 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 74033a8..cf06ac6 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -1225,6 +1225,10 @@ BUILTIN_CORE_OPTIONS: 'MutableKeyedOptionDictType' = OrderedDict([
(OptionKey('wrap_mode'), BuiltinOption(UserComboOption, 'Wrap mode', 'default', choices=['default', 'nofallback', 'nodownload', 'forcefallback', 'nopromote'])),
(OptionKey('force_fallback_for'), BuiltinOption(UserArrayOption, 'Force fallback for those subprojects', [])),
+ # Pkgconfig module
+ (OptionKey('relocatable', module='pkgconfig'),
+ BuiltinOption(UserBooleanOption, 'Generate pkgconfig files as relocatable', False)),
+
# Python module
(OptionKey('install_env', module='python'),
BuiltinOption(UserComboOption, 'Which python environment to install to', 'prefix', choices=['auto', 'prefix', 'system', 'venv'])),
diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py
index 0eac360..bbd3d07 100644
--- a/mesonbuild/modules/pkgconfig.py
+++ b/mesonbuild/modules/pkgconfig.py
@@ -328,7 +328,8 @@ class PkgConfigModule(ExtensionModule):
def _generate_pkgconfig_file(self, state, deps, subdirs, name, description,
url, version, pcfile, conflicts, variables,
- unescaped_variables, uninstalled=False, dataonly=False):
+ unescaped_variables, uninstalled=False, dataonly=False,
+ pkgroot=None):
coredata = state.environment.get_coredata()
referenced_vars = set()
optnames = [x.name for x in BUILTIN_DIR_OPTIONS.keys()]
@@ -374,6 +375,15 @@ class PkgConfigModule(ExtensionModule):
else:
outdir = state.environment.scratch_dir
prefix = PurePath(coredata.get_option(mesonlib.OptionKey('prefix')))
+ if pkgroot:
+ pkgroot = PurePath(pkgroot)
+ if not pkgroot.is_absolute():
+ pkgroot = prefix / pkgroot
+ elif prefix not in pkgroot.parents:
+ raise mesonlib.MesonException('Pkgconfig prefix cannot be outside of the prefix '
+ 'when pkgconfig.relocatable=true. '
+ f'Pkgconfig prefix is {pkgroot.as_posix()}.')
+ prefix = PurePath('${pcfiledir}', os.path.relpath(prefix, pkgroot))
fname = os.path.join(outdir, pcfile)
with open(fname, 'w', encoding='utf-8') as ofile:
for optname in optnames:
@@ -591,9 +601,11 @@ class PkgConfigModule(ExtensionModule):
pkgroot_name = os.path.join('{libdir}', 'pkgconfig')
if not isinstance(pkgroot, str):
raise mesonlib.MesonException('Install_dir must be a string.')
+ relocatable = state.get_option('relocatable', module='pkgconfig')
self._generate_pkgconfig_file(state, deps, subdirs, name, description, url,
version, pcfile, conflicts, variables,
- unescaped_variables, False, dataonly)
+ unescaped_variables, False, dataonly,
+ pkgroot=pkgroot if relocatable else None)
res = build.Data([mesonlib.File(True, state.environment.get_scratch_dir(), pcfile)], pkgroot, pkgroot_name, None, state.subproject, install_tag='devel')
variables = self.interpreter.extract_variables(kwargs, argname='uninstalled_variables', dict_new=True)
variables = parse_variable_list(variables)