GraphicsMagick: configure.ac: Use pkg-config for libheif

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.9649.1688236599.17685.graphicsmagick-commit@lists.sourceforge.net>
changeset cf9a42968e43 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=cf9a42968e43
summary: configure.ac: Use pkg-config for libheif

diffstat:

 ChangeLog          |   3 +
 Makefile.in        |   2 +
 configure          |  99 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 configure.ac       |  15 ++++++--
 www/Changelog.html |   2 +
 5 files changed, 113 insertions(+), 8 deletions(-)

diffs (218 lines):

diff -r 91b7f6b072d4 -r cf9a42968e43 ChangeLog
--- a/ChangeLog	Sat Jul 01 09:23:43 2023 -0500
+++ b/ChangeLog	Sat Jul 01 13:36:20 2023 -0500
@@ -1,5 +1,8 @@
 2023-07-01  Bob Friesenhahn  <[email protected]>
 
+	* configure.ac (LIB_HEIF): SourceForge patch #71 "Use pkg-config
+	for libheif in configure".
+
 	* TclMagick/{configure.ac, generic/Makefile.am,
 	generic/pkgIndex.tcl.in, pkgIndex.tcl}: SourceForge patch #74
 	"TclMagick: generate generic/pkgIndex.tcl automatically and change
diff -r 91b7f6b072d4 -r cf9a42968e43 Makefile.in
--- a/Makefile.in	Sat Jul 01 09:23:43 2023 -0500
+++ b/Makefile.in	Sat Jul 01 13:36:20 2023 -0500
@@ -2476,6 +2476,8 @@
 GSPSDevice = @GSPSDevice@
 GSPaletteDevice = @GSPaletteDevice@
 GSVersion = @GSVersion@
+HEIF_CFLAGS = @HEIF_CFLAGS@
+HEIF_LIBS = @HEIF_LIBS@
 HG_BRANCH_TAG = @HG_BRANCH_TAG@
 HPGLDecodeDelegate = @HPGLDecodeDelegate@
 HTMLDecodeDelegate = @HTMLDecodeDelegate@
diff -r 91b7f6b072d4 -r cf9a42968e43 configure
--- a/configure	Sat Jul 01 09:23:43 2023 -0500
+++ b/configure	Sat Jul 01 13:36:20 2023 -0500
@@ -739,6 +739,8 @@
 LIB_HEIF
 HasHEIF_FALSE
 HasHEIF_TRUE
+HEIF_LIBS
+HEIF_CFLAGS
 LIB_WEBP
 HasWEBP_FALSE
 HasWEBP_TRUE
@@ -1121,6 +1123,8 @@
 PKG_CONFIG_LIBDIR
 FT_CFLAGS
 FT_LIBS
+HEIF_CFLAGS
+HEIF_LIBS
 XML_CFLAGS
 XML_LIBS'
 
@@ -1855,6 +1859,8 @@
               path overriding pkg-config's built-in search path
   FT_CFLAGS   C compiler flags for FT, overriding pkg-config
   FT_LIBS     linker flags for FT, overriding pkg-config
+  HEIF_CFLAGS C compiler flags for HEIF, overriding pkg-config
+  HEIF_LIBS   linker flags for HEIF, overriding pkg-config
   XML_CFLAGS  C compiler flags for XML, overriding pkg-config
   XML_LIBS    linker flags for XML, overriding pkg-config
 
@@ -27616,7 +27622,69 @@
 $as_echo "" >&6; }
     failed=0
     passed=0
-    ac_fn_c_check_header_mongrel "$LINENO" "libheif/heif.h" "ac_cv_header_libheif_heif_h" "$ac_includes_default"
+    heif_libs=''
+    # Use pkg-config to handle different optional codec libs
+    # and if pkg-config is not available fallback to manual search.
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libheif" >&5
+$as_echo_n "checking for libheif... " >&6; }
+
+if test -n "$HEIF_CFLAGS"; then
+    pkg_cv_HEIF_CFLAGS="$HEIF_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libheif\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libheif") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_HEIF_CFLAGS=`$PKG_CONFIG --cflags "libheif" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$HEIF_LIBS"; then
+    pkg_cv_HEIF_LIBS="$HEIF_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libheif\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libheif") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_HEIF_LIBS=`$PKG_CONFIG --libs "libheif" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        HEIF_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libheif" 2>&1`
+        else
+	        HEIF_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libheif" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$HEIF_PKG_ERRORS" >&5
+
+	ac_fn_c_check_header_mongrel "$LINENO" "libheif/heif.h" "ac_cv_header_libheif_heif_h" "$ac_includes_default"
 if test "x$ac_cv_header_libheif_heif_h" = xyes; then :
   passed=`expr $passed + 1`
 else
@@ -27624,14 +27692,37 @@
 fi
 
 
-    # heif always requires hwy no extra test needed
+        # Assume sensible default for codec; This will fail with a static
+        # libheif that contains a avif codec.
+        heif_libs="-lheif -lde265"
+elif test $pkg_failed = untried; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	ac_fn_c_check_header_mongrel "$LINENO" "libheif/heif.h" "ac_cv_header_libheif_heif_h" "$ac_includes_default"
+if test "x$ac_cv_header_libheif_heif_h" = xyes; then :
+  passed=`expr $passed + 1`
+else
+  failed=`expr $failed + 1`
+fi
+
+
+        # Assume sensible default for codec; This will fail with a static
+        # libheif that contains a avif codec.
+        heif_libs="-lheif -lde265"
+else
+	HEIF_CFLAGS=$pkg_cv_HEIF_CFLAGS
+	HEIF_LIBS=$pkg_cv_HEIF_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	heif_libs=$HEIF_LIBS; passed=1;
+fi
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for heif_context_alloc in -lheif" >&5
 $as_echo_n "checking for heif_context_alloc in -lheif... " >&6; }
 if ${ac_cv_lib_heif_heif_context_alloc+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-lheif -lde265 $LIBS"
+LIBS="-lheif $heif_libs $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -27677,7 +27768,7 @@
 $as_echo "no -- some components failed test" >&6; }
         have_heif='no (failed tests)'
     else
-        LIB_HEIF='-lheif -lde265'
+        LIB_HEIF="$heif_libs"
         LIBS="$LIB_HEIF $LIBS"
 
 $as_echo "#define HasHEIF 1" >>confdefs.h
diff -r 91b7f6b072d4 -r cf9a42968e43 configure.ac
--- a/configure.ac	Sat Jul 01 09:23:43 2023 -0500
+++ b/configure.ac	Sat Jul 01 13:36:20 2023 -0500
@@ -2649,9 +2649,16 @@
     AC_MSG_RESULT()
     failed=0
     passed=0
-    AC_CHECK_HEADER([libheif/heif.h],[passed=`expr $passed + 1`],[failed=`expr $failed + 1`])
-    # heif always requires hwy no extra test needed
-    AC_CHECK_LIB([heif],[heif_context_alloc],[passed=`expr $passed + 1`],[failed=`expr $failed + 1`],[-lde265])
+    heif_libs=''
+    # Use pkg-config to handle different optional codec libs
+    # and if pkg-config is not available fallback to manual search.
+    PKG_CHECK_MODULES([HEIF], [libheif],
+        [heif_libs=$HEIF_LIBS; passed=1;],
+        [AC_CHECK_HEADER([libheif/heif.h],[passed=`expr $passed + 1`],[failed=`expr $failed + 1`])
+        # Assume sensible default for codec; This will fail with a static
+        # libheif that contains a avif codec.
+        heif_libs="-lheif -lde265"])
+    AC_CHECK_LIB([heif],[heif_context_alloc],[passed=`expr $passed + 1`],[failed=`expr $failed + 1`],[$heif_libs])
     AC_MSG_CHECKING([if HEIF package is complete])
     if test $passed -gt 0
     then
@@ -2660,7 +2667,7 @@
         AC_MSG_RESULT([no -- some components failed test])
         have_heif='no (failed tests)'
     else
-        LIB_HEIF='-lheif -lde265'
+        LIB_HEIF="$heif_libs"
         LIBS="$LIB_HEIF $LIBS"
         AC_DEFINE([HasHEIF],[1],[Define if you have HEIF library])
         AC_MSG_RESULT([yes])
diff -r 91b7f6b072d4 -r cf9a42968e43 www/Changelog.html
--- a/www/Changelog.html	Sat Jul 01 09:23:43 2023 -0500
+++ b/www/Changelog.html	Sat Jul 01 13:36:20 2023 -0500
@@ -40,6 +40,8 @@
 <p>2023-07-01  Bob Friesenhahn  &lt;<a class="reference external" href="mailto:bfriesen&#37;&#52;&#48;simple&#46;dallas&#46;tx&#46;us">bfriesen<span>&#64;</span>simple<span>&#46;</span>dallas<span>&#46;</span>tx<span>&#46;</span>us</a>&gt;</p>
 <blockquote>
 <ul class="simple">
+<li><p>configure.ac (LIB_HEIF): SourceForge patch #71 &quot;Use pkg-config
+for libheif in configure&quot;.</p></li>
 <li><p>TclMagick/{configure.ac, generic/Makefile.am,
 generic/pkgIndex.tcl.in, pkgIndex.tcl}: SourceForge patch #74
 &quot;TclMagick: generate generic/pkgIndex.tcl automatically and change
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.