@@ -273,15 +273,19 @@ def set_pkgconfig_path(self):
273
273
except KeyError :
274
274
os .environ ['PKG_CONFIG_PATH' ] = pkgconfig_path
275
275
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 = ()):
278
279
"""Add parameters to the given *ext* for the given *package*."""
279
280
280
281
# First, try to get the flags from pkg-config.
281
282
282
283
cmd = ([self .pkg_config , package ] if self .pkg_config else alt_exec )
283
284
if cmd is not None :
284
285
try :
286
+ if self .pkg_config and atleast_version :
287
+ subprocess .check_call (
288
+ [* cmd , f"--atleast-version={ atleast_version } " ])
285
289
flags = shlex .split (subprocess .check_output (
286
290
[* cmd , "--cflags" , "--libs" ], universal_newlines = True ))
287
291
except (OSError , subprocess .CalledProcessError ):
@@ -312,19 +316,6 @@ def setup_extension(self, ext, package,
312
316
# Default linked libs.
313
317
ext .libraries .extend (default_libraries )
314
318
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
-
328
319
329
320
# The PkgConfig class should be used through this singleton
330
321
pkg_config = PkgConfig ()
@@ -717,7 +708,11 @@ def add_flags(self, ext):
717
708
ext .define_macros .append (('FREETYPE_BUILD_TYPE' , 'local' ))
718
709
else :
719
710
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.
720
714
ext , 'freetype2' ,
715
+ atleast_version = '9.11.3' ,
721
716
alt_exec = ['freetype-config' , '--cflags' , '--libs' ],
722
717
default_libraries = ['freetype' , 'z' ])
723
718
ext .define_macros .append (('FREETYPE_BUILD_TYPE' , 'system' ))
@@ -862,6 +857,7 @@ def get_extension(self):
862
857
ext = Extension ('matplotlib._png' , sources )
863
858
pkg_config .setup_extension (
864
859
ext , 'libpng' ,
860
+ atleast_version = '1.2' ,
865
861
alt_exec = ['libpng-config' , '--cflags' , '--ldflags' ],
866
862
default_libraries = ['png' , 'z' ])
867
863
Numpy ().add_flags (ext )
0 commit comments