@@ -273,15 +273,19 @@ def set_pkgconfig_path(self):
273273 except KeyError :
274274 os .environ ['PKG_CONFIG_PATH' ] = pkgconfig_path
275275
276- def setup_extension (self , ext , package ,
277- alt_exec = None , default_libraries = ()):
276+ def setup_extension (
277+ self , ext , package ,
278+ atleast_version = None , alt_exec = None , default_libraries = ()):
278279 """Add parameters to the given *ext* for the given *package*."""
279280
280281 # First, try to get the flags from pkg-config.
281282
282283 cmd = ([self .pkg_config , package ] if self .pkg_config else alt_exec )
283284 if cmd is not None :
284285 try :
286+ if self .pkg_config and atleast_version :
287+ subprocess .check_call (
288+ [* cmd , f"--atleast-version={ atleast_version } " ])
285289 flags = shlex .split (subprocess .check_output (
286290 [* cmd , "--cflags" , "--libs" ], universal_newlines = True ))
287291 except (OSError , subprocess .CalledProcessError ):
@@ -312,19 +316,6 @@ def setup_extension(self, ext, package,
312316 # Default linked libs.
313317 ext .libraries .extend (default_libraries )
314318
315- def get_version (self , package ):
316- """
317- Get the version of the package from pkg-config.
318- """
319- if not self .has_pkgconfig :
320- return None
321-
322- status , output = subprocess .getstatusoutput (
323- self .pkg_config + " %s --modversion" % (package ))
324- if status == 0 :
325- return output
326- return None
327-
328319
329320# The PkgConfig class should be used through this singleton
330321pkg_config = PkgConfig ()
@@ -717,7 +708,11 @@ def add_flags(self, ext):
717708 ext .define_macros .append (('FREETYPE_BUILD_TYPE' , 'local' ))
718709 else :
719710 pkg_config .setup_extension (
711+ # FreeType 2.3 has libtool version 9.11.3 as can be checked
712+ # from the tarball. For FreeType>=2.4, there is a conversion
713+ # table in docs/VERSIONS.txt in the FreeType source tree.
720714 ext , 'freetype2' ,
715+ atleast_version = '9.11.3' ,
721716 alt_exec = ['freetype-config' , '--cflags' , '--libs' ],
722717 default_libraries = ['freetype' , 'z' ])
723718 ext .define_macros .append (('FREETYPE_BUILD_TYPE' , 'system' ))
@@ -862,6 +857,7 @@ def get_extension(self):
862857 ext = Extension ('matplotlib._png' , sources )
863858 pkg_config .setup_extension (
864859 ext , 'libpng' ,
860+ atleast_version = '1.2' ,
865861 alt_exec = ['libpng-config' , '--cflags' , '--ldflags' ],
866862 default_libraries = ['png' , 'z' ])
867863 Numpy ().add_flags (ext )
0 commit comments