[PATCH weston v2 2/2] configure: Make jpeglib an optional dependency.

Emmanuel Gil Peyrot linkmauve at linkmauve.fr
Tue Feb 16 01:57:52 UTC 2016


It doesn’t make sense to fail the entire build when jpeglib isn’t
present, so this commit makes it optional just like libwebp in the
previous one, disabled with --without-jpeg and forced with --with-jpeg.

Signed-off-by: Emmanuel Gil Peyrot <linkmauve at linkmauve.fr>
---
Changes since v1:
- Added a --without-jpeg and a --with-jpeg options
- Added an error message when trying to load a JPEG file with jpeglig
  disabled.

I also chose to use auto by default instead of yes, as it makes the
most sense when building anywhere, the other option of having the build
fail with a message asking the user to pass --without-jpeg didn’t seem
appealing.

 configure.ac          | 23 ++++++++++++++---------
 shared/image-loader.c | 30 +++++++++++++++++++++++-------
 2 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/configure.ac b/configure.ac
index 878b30a..e8689bd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -294,6 +294,19 @@ fi
 PKG_CHECK_MODULES(PIXMAN, [pixman-1])
 PKG_CHECK_MODULES(PNG, [libpng])
 
+AC_ARG_WITH([jpeg],
+            AS_HELP_STRING([--without-jpeg],
+                           [Use jpeglib for JPEG decoding support [default=auto]]))
+AS_IF([test "x$with_jpeg" != "xno"],
+      [AC_CHECK_LIB([jpeg], [jpeg_CreateDecompress], [have_jpeglib=yes], [have_jpeglib=no])],
+      [have_jpeglib=no])
+AS_IF([test "x$have_jpeglib" = "xyes"],
+      [JPEG_LIBS="-ljpeg"
+       AC_SUBST([JPEG_LIBS])
+       AC_DEFINE([HAVE_JPEG], [1], [Have jpeglib])],
+      [AS_IF([test "x$with_jpeg" = "xyes"],
+             [AC_MSG_ERROR([JPEG support explicitly requested, but jpeglib couldn't be found])])])
+
 AC_ARG_WITH([webp],
             AS_HELP_STRING([--without-webp],
                            [Use libwebp for WebP decoding support [default=auto]]))
@@ -318,15 +331,6 @@ if test x$enable_vaapi_recorder != xno; then
 fi
 AM_CONDITIONAL(ENABLE_VAAPI_RECORDER, test "x$have_libva" = xyes)
 
-
-AC_CHECK_LIB([jpeg], [jpeg_CreateDecompress], have_jpeglib=yes)
-if test x$have_jpeglib = xyes; then
-  JPEG_LIBS="-ljpeg"
-else
-  AC_ERROR([libjpeg not found])
-fi
-AC_SUBST(JPEG_LIBS)
-
 PKG_CHECK_MODULES(CAIRO, [cairo])
 
 PKG_CHECK_MODULES(TEST_CLIENT, [wayland-client >= 1.9.91])
@@ -684,6 +688,7 @@ AC_MSG_RESULT([
 
 	Colord Support			${have_colord}
 	LCMS2 Support			${have_lcms}
+	libjpeg Support			${have_jpeglib}
 	libwebp Support			${have_webp}
 	libunwind Support		${have_libunwind}
 	VA H.264 encoding Support	${have_libva}
diff --git a/shared/image-loader.c b/shared/image-loader.c
index 050f067..f477dfd 100644
--- a/shared/image-loader.c
+++ b/shared/image-loader.c
@@ -30,13 +30,16 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <jpeglib.h>
 #include <png.h>
 #include <pixman.h>
 
 #include "shared/helpers.h"
 #include "image-loader.h"
 
+#ifdef HAVE_JPEG
+#include <jpeglib.h>
+#endif
+
 #ifdef HAVE_WEBP
 #include <webp/decode.h>
 #endif
@@ -48,6 +51,14 @@ stride_for_width(int width)
 }
 
 static void
+pixman_image_destroy_func(pixman_image_t *image, void *data)
+{
+	free(data);
+}
+
+#ifdef HAVE_JPEG
+
+static void
 swizzle_row(JSAMPLE *row, JDIMENSION width)
 {
 	JSAMPLE *s;
@@ -68,12 +79,6 @@ error_exit(j_common_ptr cinfo)
 	longjmp(cinfo->client_data, 1);
 }
 
-static void
-pixman_image_destroy_func(pixman_image_t *image, void *data)
-{
-	free(data);
-}
-
 static pixman_image_t *
 load_jpeg(FILE *fp)
 {
@@ -132,6 +137,17 @@ load_jpeg(FILE *fp)
 	return pixman_image;
 }
 
+#else
+
+static pixman_image_t *
+load_jpeg(FILE *fp)
+{
+	fprintf(stderr, "JPEG support disabled at compile-time\n");
+	return NULL;
+}
+
+#endif
+
 static inline int
 multiply_alpha(int alpha, int color)
 {
-- 
2.7.1



More information about the wayland-devel mailing list