@@ -234,11 +234,18 @@ def _find_include_file(self: pil_build_ext, include: str) -> int:
234
234
235
235
236
236
def _find_library_file (self : pil_build_ext , library : str ) -> str | None :
237
- ret = self .compiler .find_library_file (self .compiler .library_dirs , library )
237
+ ret = self .compiler .find_library_file (
238
+ self .compiler .library_dirs , library , debug = debug_build ()
239
+ )
238
240
if ret :
239
241
_dbg ("Found library %s at %s" , (library , ret ))
240
- else :
241
- _dbg ("Couldn't find library %s in %s" , (library , self .compiler .library_dirs ))
242
+ # we are only interested in the library name including a possible debug suffix
243
+ lib_name_base = os .path .basename (ret ).split ("." )[0 ]
244
+ # as the library prefix differs depending on library type and platform,
245
+ # we ignore it by looking for the actual library name
246
+ start_index = lib_name_base .find (library )
247
+ return lib_name_base [start_index :]
248
+ _dbg ("Couldn't find library %s in %s" , (library , self .compiler .library_dirs ))
242
249
return ret
243
250
244
251
@@ -695,20 +702,24 @@ def build_extensions(self) -> None:
695
702
if feature .want ("zlib" ):
696
703
_dbg ("Looking for zlib" )
697
704
if _find_include_file (self , "zlib.h" ):
698
- if _find_library_file (self , "z" ):
699
- feature .set ("zlib" , "z" )
700
- elif sys .platform == "win32" and _find_library_file (self , "zlib" ):
701
- feature .set ("zlib" , "zlib" ) # alternative name
702
- elif sys .platform == "win32" and _find_library_file (self , "zdll" ):
703
- feature .set ("zlib" , "zdll" ) # dll import library
705
+ lib_zlib = _find_library_file (self , "z" )
706
+ if lib_zlib is None and sys .platform == "win32" :
707
+ # alternative name
708
+ lib_zlib = _find_library_file (self , "zlib" )
709
+ if lib_zlib is None :
710
+ # dll import library
711
+ lib_zlib = _find_library_file (self , "zdll" )
712
+ feature .set ("zlib" , lib_zlib )
704
713
705
714
if feature .want ("jpeg" ):
706
715
_dbg ("Looking for jpeg" )
707
716
if _find_include_file (self , "jpeglib.h" ):
708
- if _find_library_file (self , "jpeg" ):
709
- feature .set ("jpeg" , "jpeg" )
710
- elif sys .platform == "win32" and _find_library_file (self , "libjpeg" ):
711
- feature .set ("jpeg" , "libjpeg" ) # alternative name
717
+ if _find_include_file (self , "jpeglib.h" ):
718
+ lib_jpeg = _find_library_file (self , "jpeg" )
719
+ if lib_jpeg is None and sys .platform == "win32" :
720
+ # alternative name
721
+ lib_jpeg = _find_library_file (self , "libjpeg" )
722
+ feature .set ("jpeg" , lib_jpeg )
712
723
713
724
feature .set ("openjpeg_version" , None )
714
725
if feature .want ("jpeg2000" ):
@@ -738,35 +749,40 @@ def build_extensions(self) -> None:
738
749
(best_version , best_path ),
739
750
)
740
751
741
- if best_version and _find_library_file (self , "openjp2" ):
742
- # Add the directory to the include path so we can include
743
- # <openjpeg.h> rather than having to cope with the versioned
744
- # include path
745
- _add_directory (self .compiler .include_dirs , best_path , 0 )
746
- feature .set ("jpeg2000" , "openjp2" )
752
+ if best_version :
753
+ lib_jpeg2k = _find_library_file (self , "openjp2" )
754
+ if lib_jpeg2k is not None :
755
+ # Add the directory to the include path so we can include
756
+ # <openjpeg.h> rather than having to cope with the versioned
757
+ # include path
758
+ _add_directory (self .compiler .include_dirs , best_path , 0 )
759
+ feature .set ("jpeg2000" , lib_jpeg2k )
747
760
feature .set ("openjpeg_version" , "." .join (str (x ) for x in best_version ))
748
761
749
762
if feature .want ("imagequant" ):
750
763
_dbg ("Looking for imagequant" )
751
764
if _find_include_file (self , "libimagequant.h" ):
752
- if _find_library_file (self , "imagequant" ):
753
- feature .set ("imagequant" , "imagequant" )
754
- elif _find_library_file (self , "libimagequant" ):
755
- feature .set ("imagequant" , "libimagequant" )
765
+ lib_imagequant = _find_library_file (
766
+ self , "imagequant"
767
+ ) or _find_library_file (self , "libimagequant" )
768
+ if lib_imagequant is not None :
769
+ feature .set ("imagequant" , lib_imagequant )
756
770
757
771
if feature .want ("tiff" ):
758
772
_dbg ("Looking for tiff" )
759
773
if _find_include_file (self , "tiff.h" ):
760
- if _find_library_file (self , "tiff" ):
761
- feature .set ("tiff" , "tiff" )
762
- if sys .platform in ["win32" , "darwin" ] and _find_library_file (
763
- self , "libtiff"
764
- ):
765
- feature .set ("tiff" , "libtiff" )
774
+ lib_tiff = None
775
+ if sys .platform in ["win32" , "darwin" ]:
776
+ lib_tiff = _find_library_file (self , "libtiff" )
777
+ if lib_tiff is None :
778
+ lib_tiff = _find_library_file (self , "tiff" )
779
+ if lib_tiff is not None :
780
+ feature .set ("tiff" , lib_tiff )
766
781
767
782
if feature .want ("freetype" ):
768
783
_dbg ("Looking for freetype" )
769
- if _find_library_file (self , "freetype" ):
784
+ lib_freetype = _find_library_file (self , "freetype" )
785
+ if lib_freetype is not None :
770
786
# look for freetype2 include files
771
787
freetype_version = 0
772
788
for subdir in self .compiler .include_dirs :
@@ -783,27 +799,29 @@ def build_extensions(self) -> None:
783
799
freetype_version = 21
784
800
break
785
801
if freetype_version :
786
- feature .set ("freetype" , "freetype" )
802
+ feature .set ("freetype" , lib_freetype )
787
803
if subdir :
788
804
_add_directory (self .compiler .include_dirs , subdir , 0 )
789
805
790
806
if feature .get ("freetype" ) and feature .want ("raqm" ):
791
807
if not feature .want_vendor ("raqm" ): # want system Raqm
792
808
_dbg ("Looking for Raqm" )
793
809
if _find_include_file (self , "raqm.h" ):
794
- if _find_library_file (self , "raqm" ):
795
- feature .set ("raqm" , "raqm" )
796
- elif _find_library_file (self , "libraqm" ):
797
- feature .set ("raqm" , "libraqm" )
810
+ lib_raqm = _find_library_file (self , "raqm" ) or _find_library_file (
811
+ self , "libraqm"
812
+ )
813
+ if lib_raqm is not None :
814
+ feature .set ("raqm" , lib_raqm )
798
815
else : # want to build Raqm from src/thirdparty
799
816
_dbg ("Looking for HarfBuzz" )
800
817
feature .set ("harfbuzz" , None )
801
818
hb_dir = _find_include_dir (self , "harfbuzz" , "hb.h" )
802
819
if hb_dir :
803
820
if isinstance (hb_dir , str ):
804
821
_add_directory (self .compiler .include_dirs , hb_dir , 0 )
805
- if _find_library_file (self , "harfbuzz" ):
806
- feature .set ("harfbuzz" , "harfbuzz" )
822
+ lib_harfbuzz = _find_library_file (self , "harfbuzz" )
823
+ if lib_harfbuzz is not None :
824
+ feature .set ("harfbuzz" , lib_harfbuzz )
807
825
if feature .get ("harfbuzz" ):
808
826
if not feature .want_vendor ("fribidi" ): # want system FriBiDi
809
827
_dbg ("Looking for FriBiDi" )
@@ -814,20 +832,21 @@ def build_extensions(self) -> None:
814
832
_add_directory (
815
833
self .compiler .include_dirs , fribidi_dir , 0
816
834
)
817
- if _find_library_file (self , "fribidi" ):
818
- feature .set ("fribidi" , "fribidi" )
835
+ lib_fribidi = _find_library_file (self , "fribidi" )
836
+ if lib_fribidi is not None :
837
+ feature .set ("fribidi" , lib_fribidi )
819
838
feature .set ("raqm" , True )
820
839
else : # want to build FriBiDi shim from src/thirdparty
821
840
feature .set ("raqm" , True )
822
841
823
842
if feature .want ("lcms" ):
824
843
_dbg ("Looking for lcms" )
825
844
if _find_include_file (self , "lcms2.h" ):
826
- if _find_library_file (self , "lcms2" ):
827
- feature . set ( "lcms" , "lcms2" )
828
- elif _find_library_file ( self , "lcms2_static" ):
829
- # alternate Windows name.
830
- feature .set ("lcms" , "lcms2_static" )
845
+ lib_lcms2 = _find_library_file (self , "lcms2" ) or _find_library_file (
846
+ self , "lcms2_static" # alternate Windows name
847
+ )
848
+ if lib_lcms2 is not None :
849
+ feature .set ("lcms" , lib_lcms2 )
831
850
832
851
if feature .want ("webp" ):
833
852
_dbg ("Looking for webp" )
@@ -841,20 +860,22 @@ def build_extensions(self) -> None:
841
860
_find_library_file (self , prefix + library )
842
861
for library in ("webp" , "webpmux" , "webpdemux" )
843
862
):
844
- feature .set ("webp" , prefix + "webp" )
863
+ feature .set ("webp" , _find_library_file ( self , prefix + "webp" ) )
845
864
break
846
865
847
866
if feature .want ("xcb" ):
848
867
_dbg ("Looking for xcb" )
849
868
if _find_include_file (self , "xcb/xcb.h" ):
850
- if _find_library_file (self , "xcb" ):
851
- feature .set ("xcb" , "xcb" )
869
+ lib_xcb = _find_library_file (self , "xcb" )
870
+ if lib_xcb is not None :
871
+ feature .set ("xcb" , lib_xcb )
852
872
853
873
if feature .want ("avif" ):
854
874
_dbg ("Looking for avif" )
855
875
if _find_include_file (self , "avif/avif.h" ):
856
- if _find_library_file (self , "avif" ):
857
- feature .set ("avif" , "avif" )
876
+ lib_avif = _find_library_file (self , "avif" )
877
+ if lib_avif is not None :
878
+ feature .set ("avif" , lib_avif )
858
879
859
880
for f in feature :
860
881
if not feature .get (f ) and feature .require (f ):
@@ -908,7 +929,7 @@ def build_extensions(self) -> None:
908
929
909
930
if feature .get ("freetype" ):
910
931
srcs = []
911
- libs = ["freetype" ]
932
+ libs = [feature . get ( "freetype" ) ]
912
933
defs = []
913
934
if feature .get ("raqm" ):
914
935
if not feature .want_vendor ("raqm" ): # using system Raqm
0 commit comments