@@ -922,6 +922,13 @@ def add_flags(self, ext, add_sources=True):
922
922
os .path .join ('extern' , 'agg24-svn' , 'src' , x ) for x in agg_sources )
923
923
924
924
925
+ # For FreeType2 and libpng, we add a separate checkdep_foo.c source to at the
926
+ # top of the extension sources. This file is compiled first and immediately
927
+ # aborts the compilation either with "foo.h: No such file or directory" if the
928
+ # header is not found, or an appropriate error message if the header indicates
929
+ # a too-old version.
930
+
931
+
925
932
class FreeType (SetupPackage ):
926
933
name = "freetype"
927
934
pkg_names = {
@@ -933,59 +940,8 @@ class FreeType(SetupPackage):
933
940
"windows_url" : "http://gnuwin32.sourceforge.net/packages/freetype.htm"
934
941
}
935
942
936
- def check (self ):
937
- if options .get ('local_freetype' ):
938
- return "Using local version for testing"
939
-
940
- if sys .platform == 'win32' :
941
- try :
942
- check_include_file (get_include_dirs (), 'ft2build.h' , 'freetype' )
943
- except CheckFailed :
944
- check_include_file (get_include_dirs (), 'freetype2\\ ft2build.h' , 'freetype' )
945
- return 'Using unknown version found on system.'
946
-
947
- status , output = subprocess .getstatusoutput (
948
- "freetype-config --ftversion" )
949
- if status == 0 :
950
- version = output
951
- else :
952
- version = None
953
-
954
- # Early versions of freetype grep badly inside freetype-config,
955
- # so catch those cases. (tested with 2.5.3).
956
- if version is None or 'No such file or directory\n grep:' in version :
957
- version = self .version_from_header ()
958
-
959
- # pkg_config returns the libtool version rather than the
960
- # freetype version so we need to explicitly pass the version
961
- # to _check_for_pkg_config
962
- return self ._check_for_pkg_config (
963
- 'freetype2' , 'ft2build.h' ,
964
- min_version = '2.3' , version = version )
965
-
966
- def version_from_header (self ):
967
- version = 'unknown'
968
- ext = self .get_extension ()
969
- if ext is None :
970
- return version
971
- # Return the first version found in the include dirs.
972
- for include_dir in ext .include_dirs :
973
- header_fname = os .path .join (include_dir , 'freetype.h' )
974
- if os .path .exists (header_fname ):
975
- major , minor , patch = 0 , 0 , 0
976
- with open (header_fname , 'r' ) as fh :
977
- for line in fh :
978
- if line .startswith ('#define FREETYPE_' ):
979
- value = line .rsplit (' ' , 1 )[1 ].strip ()
980
- if 'MAJOR' in line :
981
- major = value
982
- elif 'MINOR' in line :
983
- minor = value
984
- else :
985
- patch = value
986
- return '.' .join ([major , minor , patch ])
987
-
988
943
def add_flags (self , ext ):
944
+ ext .sources .insert (0 , 'src/checkdep_freetype2.c' )
989
945
if options .get ('local_freetype' ):
990
946
src_path = os .path .join (
991
947
'build' , 'freetype-{0}' .format (LOCAL_FREETYPE_VERSION ))
@@ -1166,30 +1122,11 @@ class Png(SetupPackage):
1166
1122
"windows_url" : "http://gnuwin32.sourceforge.net/packages/libpng.htm"
1167
1123
}
1168
1124
1169
- def check (self ):
1170
- if sys .platform == 'win32' :
1171
- check_include_file (get_include_dirs (), 'png.h' , 'png' )
1172
- return 'Using unknown version found on system.'
1173
-
1174
- status , output = subprocess .getstatusoutput ("libpng-config --version" )
1175
- if status == 0 :
1176
- version = output
1177
- else :
1178
- version = None
1179
-
1180
- try :
1181
- return self ._check_for_pkg_config (
1182
- 'libpng' , 'png.h' ,
1183
- min_version = '1.2' , version = version )
1184
- except CheckFailed as e :
1185
- if has_include_file (get_include_dirs (), 'png.h' ):
1186
- return str (e ) + ' Using unknown version found on system.'
1187
- raise
1188
-
1189
1125
def get_extension (self ):
1190
1126
sources = [
1127
+ 'src/checkdep_libpng.c' ,
1191
1128
'src/_png.cpp' ,
1192
- 'src/mplutils.cpp'
1129
+ 'src/mplutils.cpp' ,
1193
1130
]
1194
1131
ext = make_extension ('matplotlib._png' , sources )
1195
1132
pkg_config .setup_extension (
0 commit comments