@@ -161,15 +161,19 @@ def set_pkgconfig_path(self):
161
161
except KeyError :
162
162
os .environ ['PKG_CONFIG_PATH' ] = pkgconfig_path
163
163
164
- def setup_extension (self , ext , package ,
165
- alt_exec = None , default_libraries = ()):
164
+ def setup_extension (
165
+ self , ext , package ,
166
+ atleast_version = None , alt_exec = None , default_libraries = ()):
166
167
"""Add parameters to the given *ext* for the given *package*."""
167
168
168
169
# First, try to get the flags from pkg-config.
169
170
170
171
cmd = ([self .pkg_config , package ] if self .pkg_config else alt_exec )
171
172
if cmd is not None :
172
173
try :
174
+ if self .pkg_config and atleast_version :
175
+ subprocess .check_call (
176
+ [* cmd , f"--atleast-version={ atleast_version } " ])
173
177
flags = shlex .split (subprocess .check_output (
174
178
[* cmd , "--cflags" , "--libs" ], universal_newlines = True ))
175
179
except (OSError , subprocess .CalledProcessError ):
@@ -200,19 +204,6 @@ def setup_extension(self, ext, package,
200
204
# Default linked libs.
201
205
ext .libraries .extend (default_libraries )
202
206
203
- def get_version (self , package ):
204
- """
205
- Get the version of the package from pkg-config.
206
- """
207
- if not self .has_pkgconfig :
208
- return None
209
-
210
- status , output = subprocess .getstatusoutput (
211
- self .pkg_config + " %s --modversion" % (package ))
212
- if status == 0 :
213
- return output
214
- return None
215
-
216
207
217
208
# The PkgConfig class should be used through this singleton
218
209
pkg_config = PkgConfig ()
@@ -630,7 +621,11 @@ def add_flags(self, ext):
630
621
ext .define_macros .append (('FREETYPE_BUILD_TYPE' , 'local' ))
631
622
else :
632
623
pkg_config .setup_extension (
624
+ # FreeType 2.3 has libtool version 9.11.3 as can be checked
625
+ # from the tarball. For FreeType>=2.4, there is a conversion
626
+ # table in docs/VERSIONS.txt in the FreeType source tree.
633
627
ext , 'freetype2' ,
628
+ atleast_version = '9.11.3' ,
634
629
alt_exec = ['freetype-config' , '--cflags' , '--libs' ],
635
630
default_libraries = ['freetype' , 'z' ])
636
631
ext .define_macros .append (('FREETYPE_BUILD_TYPE' , 'system' ))
@@ -799,6 +794,7 @@ def get_extension(self):
799
794
ext = Extension ('matplotlib._png' , sources )
800
795
pkg_config .setup_extension (
801
796
ext , 'libpng' ,
797
+ atleast_version = '1.2' ,
802
798
alt_exec = ['libpng-config' , '--cflags' , '--ldflags' ],
803
799
default_libraries = ['png' , 'z' ])
804
800
Numpy ().add_flags (ext )
0 commit comments