@@ -935,10 +935,37 @@ def check(self):
935935 else :
936936 version = None
937937
938+ # Early versions of freetype grep badly inside freetype-config,
939+ # so catch those cases. (tested with 2.5.3).
940+ if 'No such file or directory\n grep:' in version :
941+ version = self .version_from_header ()
942+
938943 return self ._check_for_pkg_config (
939944 'freetype2' , 'ft2build.h' ,
940945 min_version = '2.4' , version = version )
941946
947+ def version_from_header (self ):
948+ version = 'Failed to identify version.'
949+ ext = self .get_extension ()
950+ if ext is None :
951+ return version
952+ # Return the first version found in the include dirs.
953+ for include_dir in ext .include_dirs :
954+ header_fname = os .path .join (include_dir , 'freetype.h' )
955+ if os .path .exists (header_fname ):
956+ major , minor , patch = 0 , 0 , 0
957+ with open (header_fname , 'r' ) as fh :
958+ for line in fh :
959+ if line .startswith ('#define FREETYPE_' ):
960+ value = line .rsplit (' ' , 1 )[1 ].strip ()
961+ if 'MAJOR' in line :
962+ major = value
963+ elif 'MINOR' in line :
964+ minor = value
965+ else :
966+ patch = value
967+ return '.' .join ([major , minor , patch ])
968+
942969 def add_flags (self , ext ):
943970 pkg_config .setup_extension (
944971 ext , 'freetype2' ,
0 commit comments