@@ -814,6 +814,13 @@ def add_flags(self, ext, add_sources=True):
814
814
for x in agg_sources )
815
815
816
816
817
+ # For FreeType2 and libpng, we add a separate checkdep_foo.c source to at the
818
+ # top of the extension sources. This file is compiled first and immediately
819
+ # aborts the compilation either with "foo.h: No such file or directory" if the
820
+ # header is not found, or an appropriate error message if the header indicates
821
+ # a too-old version.
822
+
823
+
817
824
class FreeType (SetupPackage ):
818
825
name = "freetype"
819
826
pkg_names = {
@@ -825,59 +832,8 @@ class FreeType(SetupPackage):
825
832
"windows_url" : "http://gnuwin32.sourceforge.net/packages/freetype.htm"
826
833
}
827
834
828
- def check (self ):
829
- if options .get ('local_freetype' ):
830
- return "Using local version for testing"
831
-
832
- if sys .platform == 'win32' :
833
- try :
834
- check_include_file (get_include_dirs (), 'ft2build.h' , 'freetype' )
835
- except CheckFailed :
836
- check_include_file (get_include_dirs (), os .path .join ('freetype2' , 'ft2build.h' ), 'freetype' )
837
- return 'Using unknown version found on system.'
838
-
839
- status , output = subprocess .getstatusoutput (
840
- "freetype-config --ftversion" )
841
- if status == 0 :
842
- version = output
843
- else :
844
- version = None
845
-
846
- # Early versions of freetype grep badly inside freetype-config,
847
- # so catch those cases. (tested with 2.5.3).
848
- if version is None or 'No such file or directory\n grep:' in version :
849
- version = self .version_from_header ()
850
-
851
- # pkg_config returns the libtool version rather than the
852
- # freetype version so we need to explicitly pass the version
853
- # to _check_for_pkg_config
854
- return self ._check_for_pkg_config (
855
- 'freetype2' , 'ft2build.h' ,
856
- min_version = '2.3' , version = version )
857
-
858
- def version_from_header (self ):
859
- version = 'unknown'
860
- ext = self .get_extension ()
861
- if ext is None :
862
- return version
863
- # Return the first version found in the include dirs.
864
- for include_dir in ext .include_dirs :
865
- header_fname = os .path .join (include_dir , 'freetype.h' )
866
- if os .path .exists (header_fname ):
867
- major , minor , patch = 0 , 0 , 0
868
- with open (header_fname , 'r' ) as fh :
869
- for line in fh :
870
- if line .startswith ('#define FREETYPE_' ):
871
- value = line .rsplit (' ' , 1 )[1 ].strip ()
872
- if 'MAJOR' in line :
873
- major = value
874
- elif 'MINOR' in line :
875
- minor = value
876
- else :
877
- patch = value
878
- return '.' .join ([major , minor , patch ])
879
-
880
835
def add_flags (self , ext ):
836
+ ext .sources .insert (0 , 'src/checkdep_freetype2.c' )
881
837
if options .get ('local_freetype' ):
882
838
src_path = os .path .join (
883
839
'build' , 'freetype-{0}' .format (LOCAL_FREETYPE_VERSION ))
@@ -1058,30 +1014,11 @@ class Png(SetupPackage):
1058
1014
"windows_url" : "http://gnuwin32.sourceforge.net/packages/libpng.htm"
1059
1015
}
1060
1016
1061
- def check (self ):
1062
- if sys .platform == 'win32' :
1063
- check_include_file (get_include_dirs (), 'png.h' , 'png' )
1064
- return 'Using unknown version found on system.'
1065
-
1066
- status , output = subprocess .getstatusoutput ("libpng-config --version" )
1067
- if status == 0 :
1068
- version = output
1069
- else :
1070
- version = None
1071
-
1072
- try :
1073
- return self ._check_for_pkg_config (
1074
- 'libpng' , 'png.h' ,
1075
- min_version = '1.2' , version = version )
1076
- except CheckFailed as e :
1077
- if has_include_file (get_include_dirs (), 'png.h' ):
1078
- return str (e ) + ' Using unknown version found on system.'
1079
- raise
1080
-
1081
1017
def get_extension (self ):
1082
1018
sources = [
1019
+ 'src/checkdep_libpng.c' ,
1083
1020
'src/_png.cpp' ,
1084
- 'src/mplutils.cpp'
1021
+ 'src/mplutils.cpp' ,
1085
1022
]
1086
1023
ext = make_extension ('matplotlib._png' , sources )
1087
1024
pkg_config .setup_extension (
0 commit comments