[gdk-pixbuf: 1/2] Meson: Change png/jpeg/tiff options from boolean to feature




commit 7305f1ee096f819b52118b179c06e3d868518689
Author: Xavier Claessens <xavier claessens collabora com>
Date:   Wed May 5 09:52:48 2021 -0400

    Meson: Change png/jpeg/tiff options from boolean to feature
    
    png/jpeg are essential and have a fallback subproject so they are
    enabled by default. tiff is not required by GTK and does not have a
    subproject so it's set to 'auto' by default.
    
    This fixes the case where tiff option was set to true by default but
    meson setup was not aborting if the dependency was not found. Instead it
    was failing at build time.

 .gitlab-ci.yml           |  2 +-
 .gitlab/ci/test-msys2.sh |  6 ++--
 meson.build              | 81 ++++++++++++++++++++++++++++++------------------
 meson_options.txt        | 12 +++----
 4 files changed, 60 insertions(+), 41 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7887596f0..17a9ba38e 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -8,7 +8,7 @@ stages:
 variables:
   CCACHE_DIR: _ccache
   COMMON_MESON_FLAGS: "-Dwerror=true -Dglib:werror=false"
-  LOADERS_FLAGS: "-Dpng=true -Djpeg=true -Dtiff=true"
+  LOADERS_FLAGS: "-Dpng=enabled -Djpeg=enabled -Dtiff=enabled"
   MESON_TEST_TIMEOUT_MULTIPLIER: 3
   FEDORA_IMAGE: "registry.gitlab.gnome.org/gnome/gdk-pixbuf/fedora:v3"
 
diff --git a/.gitlab/ci/test-msys2.sh b/.gitlab/ci/test-msys2.sh
index b5a94c946..f9ac9e639 100644
--- a/.gitlab/ci/test-msys2.sh
+++ b/.gitlab/ci/test-msys2.sh
@@ -21,9 +21,9 @@ pacman --noconfirm -S --needed \
     mingw-w64-$MSYS2_ARCH-toolchain
 
 meson setup --buildtype debug \
-    -Dpng=true \
-    -Djpeg=true \
-    -Dtiff=true \
+    -Dpng=enabled \
+    -Djpeg=enabled \
+    -Dtiff=enabled \
     _build
 
 meson compile -C _build
diff --git a/meson.build b/meson.build
index fde0e9ade..8dc3ea68b 100644
--- a/meson.build
+++ b/meson.build
@@ -253,7 +253,8 @@ endif
 enabled_loaders = []
 loaders_deps = []
 
-if get_option('png')
+png_opt = get_option('png')
+if not png_opt.disabled()
   png_dep = dependency('libpng', required: false)
 
   if not png_dep.found() and cc.has_header('png.h')
@@ -283,11 +284,16 @@ if get_option('png')
   # that will bypass --wrap-mode and cause issues for distro packagers.
   # See: https://mesonbuild.com/Reference-manual.html#dependency
   if not png_dep.found()
-    png_dep = dependency('libpng', fallback: ['libpng', 'png_dep'])
+    png_dep = dependency('libpng',
+      fallback: ['libpng', 'png_dep'],
+      required: png_opt,
+    )
   endif
 
-  enabled_loaders += 'png'
-  loaders_deps += png_dep
+  if png_dep.found()
+    enabled_loaders += 'png'
+    loaders_deps += png_dep
+  endif
 endif
 
 # On Windows, check whether we are building the native Windows loaders
@@ -307,7 +313,8 @@ if native_windows_loaders
 endif
 
 # Don't check and build the jpeg loader if native_windows_loaders is true
-if get_option('jpeg') and not native_windows_loaders
+jpeg_opt = get_option('jpeg')
+if not jpeg_opt.disabled() and not native_windows_loaders
   jpeg_dep = dependency('libjpeg', required: false)
 
   if not jpeg_dep.found() and cc.has_header('jpeglib.h')
@@ -321,43 +328,55 @@ if get_option('jpeg') and not native_windows_loaders
 
   # Finally, look for the dependency in a fallback
   if not jpeg_dep.found()
-    jpeg_dep = dependency('libjpeg', fallback: ['libjpeg-turbo', 'jpeg_dep'])
+    jpeg_dep = dependency('libjpeg',
+      fallback: ['libjpeg-turbo', 'jpeg_dep'],
+      required: jpeg_opt,
+    )
   endif
 
-  enabled_loaders += 'jpeg'
-  loaders_deps += jpeg_dep
+  if jpeg_dep.found()
+    enabled_loaders += 'jpeg'
+    loaders_deps += jpeg_dep
 
-  if jpeg_dep.type_name() == 'internal'
-    has_destroy_decompress = true
-    has_simple_progression = true
-  else
-    has_destroy_decompress = cc.has_function('jpeg_destroy_decompress', dependencies: jpeg_dep)
-    has_simple_progression = cc.has_function('jpeg_simple_progression', dependencies: jpeg_dep)
-  endif
+    if jpeg_dep.type_name() == 'internal'
+      has_destroy_decompress = true
+      has_simple_progression = true
+    else
+      has_destroy_decompress = cc.has_function('jpeg_destroy_decompress', dependencies: jpeg_dep)
+      has_simple_progression = cc.has_function('jpeg_simple_progression', dependencies: jpeg_dep)
+    endif
 
-  if has_destroy_decompress and has_simple_progression
-    gdk_pixbuf_conf.set('HAVE_PROGRESSIVE_JPEG', has_simple_progression)
+    if has_destroy_decompress and has_simple_progression
+      gdk_pixbuf_conf.set('HAVE_PROGRESSIVE_JPEG', has_simple_progression)
+    endif
   endif
 endif
 
 # Don't check and build the tiff loader if native_windows_loaders is true
-if get_option('tiff') and not native_windows_loaders
+tiff_opt = get_option('tiff')
+if not tiff_opt.disabled() and not native_windows_loaders
   tiff_dep = dependency('libtiff-4', required: false)
-  if not tiff_dep.found()
-    # Fallback when no pkg-config file is found for libtiff on MSVC, which is quite normal
-    if cc.get_id() == 'msvc' and cc.has_header('tiff.h')
-      # First look for the DLL builds of libtiff, then the static builds
-      tiff_dep = cc.find_library('libtiff_i', required: false)
-
-      if not tiff_dep.found()
-        # For the static lib, zlib and libjpeg .lib's have been looked for first, and
-        # they are optional for libtiff
-        tiff_dep = cc.find_library('libtiff')
-      endif
+  if not tiff_dep.found() and cc.has_header('tiff.h')
+    # First look for the DLL builds of libtiff, then the static builds
+    tiff_dep = cc.find_library('libtiff_i', required: false)
+
+    if not tiff_dep.found()
+      # For the static lib, zlib and libjpeg .lib's have been looked for first, and
+      # they are optional for libtiff
+      tiff_dep = cc.find_library('libtiff', required: false)
     endif
   endif
-  enabled_loaders += 'tiff'
-  loaders_deps += tiff_dep
+
+  # We currently don't have a fallback subproject, but this handles error
+  # reporting if tiff_opt is enabled.
+  if not tiff_dep.found()
+    tiff_dep = dependency('libtiff-4', required: tiff_opt)
+  endif
+
+  if tiff_dep.found()
+    enabled_loaders += 'tiff'
+    loaders_deps += tiff_dep
+  endif
 endif
 
 # Determine whether we enable application bundle relocation support, and we use
diff --git a/meson_options.txt b/meson_options.txt
index 0ee6718bf..c12179c5e 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,15 +1,15 @@
 option('png',
        description: 'Enable PNG loader (requires libpng)',
-       type: 'boolean',
-       value: true)
+       type: 'feature',
+       value: 'enabled')
 option('tiff',
        description: 'Enable TIFF loader (requires libtiff), disabled on Windows if "native_windows_loaders" 
is used',
-       type: 'boolean',
-       value: true)
+       type: 'feature',
+       value: 'auto')
 option('jpeg',
        description: 'Enable JPEG loader (requires libjpeg), disabled on Windows if "native_windows_loaders" 
is used',
-       type: 'boolean',
-       value: true)
+       type: 'feature',
+       value: 'enabled')
 option('builtin_loaders',
        description: 'Comma-separated list of loaders to build into gdk-pixbuf',
        type: 'array',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]