pkgconfig: Handle library names starting with 'lib'

Sometimes people want the library to start with 'lib' everywhere, which
is achieved by setting name_prefix to '' and the target name to
'libfoo'. In that case, try to get the pkg-config '-lfoo' arg right.

Also, don't warn about anything on Windows

Fixes https://github.com/mesonbuild/meson/issues/889
pull/899/head
Nirbheek Chauhan 8 years ago
parent f194914b9f
commit 814f4909f9
  1. 35
      mesonbuild/modules/pkgconfig.py

@ -19,6 +19,24 @@ import os
class PkgConfigModule: class PkgConfigModule:
def _get_lname(self, l, msg, pcfile):
# Nothing special
if not l.name_prefix_set:
return l.name
# Sometimes people want the library to start with 'lib' everywhere,
# which is achieved by setting name_prefix to '' and the target name to
# 'libfoo'. In that case, try to get the pkg-config '-lfoo' arg correct.
if l.prefix == '' and l.name.startswith('lib'):
return l.name[3:]
# If the library is imported via an import library which is always
# named after the target name, '-lfoo' is correct.
if l.import_filename:
return l.name
# In other cases, we can't guarantee that the compiler will be able to
# find the library via '-lfoo', so tell the user that.
mlog.log(mlog.red('WARNING:'), msg.format(l.name, 'name_prefix', l.name, pcfile))
return l.name
def generate_pkgconfig_file(self, state, libraries, subdirs, name, description, version, pcfile, def generate_pkgconfig_file(self, state, libraries, subdirs, name, description, version, pcfile,
pub_reqs, priv_reqs, priv_libs): pub_reqs, priv_reqs, priv_libs):
coredata = state.environment.get_coredata() coredata = state.environment.get_coredata()
@ -45,20 +63,17 @@ class PkgConfigModule:
'Libraries.private: {}\n'.format(' '.join(priv_libs))) 'Libraries.private: {}\n'.format(' '.join(priv_libs)))
ofile.write('Libs: -L${libdir} ') ofile.write('Libs: -L${libdir} ')
msg = 'Library target {0!r} has {1!r} set. Compilers ' \ msg = 'Library target {0!r} has {1!r} set. Compilers ' \
'may not find it from its \'-l{0}\' linker flag in the ' \ 'may not find it from its \'-l{2}\' linker flag in the ' \
'{2!r} pkg-config file.' '{3!r} pkg-config file.'
for l in libraries: for l in libraries:
if l.custom_install_dir: if l.custom_install_dir:
ofile.write('-L${prefix}/%s ' % l.custom_install_dir) ofile.write('-L${prefix}/%s ' % l.custom_install_dir)
# Warn, but not if the filename starts with 'lib'. This can lname = self._get_lname(l, msg, pcfile)
# happen, for instance, if someone really wants to use the # If using a custom suffix, the compiler may not be able to
# 'lib' prefix on all systems, not just on UNIX, or if the the # find the library
# target name itself starts with 'lib'.
if l.name_prefix_set and not l.filename.startswith('lib'):
mlog.log(mlog.red('WARNING:'), msg.format(l.name, 'name_prefix', pcfile))
if l.name_suffix_set: if l.name_suffix_set:
mlog.log(mlog.red('WARNING:'), msg.format(l.name, 'name_suffix', pcfile)) mlog.log(mlog.red('WARNING:'), msg.format(l.name, 'name_suffix', lname, pcfile))
ofile.write('-l%s ' % l.name) ofile.write('-l{} '.format(lname))
ofile.write('\n') ofile.write('\n')
ofile.write('CFlags: ') ofile.write('CFlags: ')
for h in subdirs: for h in subdirs:

Loading…
Cancel
Save