From bb843fc8d03649ac6ca86334100b5438b35b3005 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Tue, 13 Jun 2023 15:43:02 -0500
Subject: [PATCH v5 15/16] Clean up some usage of Meson features

With Meson features, you can skip the `if myopt.disabled()` dance.
Reduces the amount of indentation as a benefit.
---
 meson.build | 516 ++++++++++++++++++++++++----------------------------
 1 file changed, 236 insertions(+), 280 deletions(-)

diff --git a/meson.build b/meson.build
index 0e0bdaddc5..0ae82dee1e 100644
--- a/meson.build
+++ b/meson.build
@@ -591,13 +591,11 @@ endif
 
 docs_pdf_opt = get_option('docs_pdf')
 docs_pdf_dep = not_found_dep
-if not docs_pdf_opt.disabled()
-  fop = find_program(get_option('FOP'), native: true, required: docs_pdf_opt)
-  if xmllint_bin.found() and xsltproc_bin.found() and fop.found()
-    docs_pdf_dep = declare_dependency()
-  elif docs_pdf_opt.enabled()
-    error('missing required tools for docs in PDF format')
-  endif
+fop = find_program(get_option('FOP'), native: true, required: docs_pdf_opt)
+if xmllint_bin.found() and xsltproc_bin.found() and fop.found()
+  docs_pdf_dep = declare_dependency()
+elif docs_pdf_opt.enabled()
+  error('missing required tools for docs in PDF format')
 endif
 
 
@@ -609,45 +607,40 @@ endif
 gssapiopt = get_option('gssapi')
 krb_srvtab = ''
 have_gssapi = false
-if not gssapiopt.disabled()
-  gssapi = dependency('krb5-gssapi', required: gssapiopt)
-  have_gssapi = gssapi.found()
+gssapi = dependency('krb5-gssapi', required: gssapiopt)
+have_gssapi = gssapi.found()
 
-  if not have_gssapi
-  elif cc.check_header('gssapi/gssapi.h', dependencies: gssapi, required: false,
-      args: test_c_args, include_directories: postgres_inc)
-    cdata.set('HAVE_GSSAPI_GSSAPI_H', 1)
-  elif cc.check_header('gssapi.h', args: test_c_args, dependencies: gssapi, required: gssapiopt)
-    cdata.set('HAVE_GSSAPI_H', 1)
-  else
-    have_gssapi = false
-  endif
-
-  if not have_gssapi
-  elif cc.check_header('gssapi/gssapi_ext.h', dependencies: gssapi, required: false,
-      args: test_c_args, include_directories: postgres_inc)
-    cdata.set('HAVE_GSSAPI_GSSAPI_EXT_H', 1)
-  elif cc.check_header('gssapi_ext.h', args: test_c_args, dependencies: gssapi, required: gssapiopt)
-    cdata.set('HAVE_GSSAPI_EXT_H', 1)
-  else
-    have_gssapi = false
-  endif
-
-  if not have_gssapi
-  elif cc.has_function('gss_store_cred_into', dependencies: gssapi,
-      args: test_c_args, include_directories: postgres_inc)
-    cdata.set('ENABLE_GSS', 1)
+if not have_gssapi
+elif cc.check_header('gssapi/gssapi.h', dependencies: gssapi, required: false,
+    args: test_c_args, include_directories: postgres_inc)
+  cdata.set('HAVE_GSSAPI_GSSAPI_H', 1)
+elif cc.check_header('gssapi.h', args: test_c_args, dependencies: gssapi, required: gssapiopt)
+  cdata.set('HAVE_GSSAPI_H', 1)
+else
+  have_gssapi = false
+endif
 
-    krb_srvtab = 'FILE:/@0@/krb5.keytab)'.format(get_option('sysconfdir'))
-    cdata.set_quoted('PG_KRB_SRVTAB', krb_srvtab)
-  elif gssapiopt.enabled()
-    error('''could not find function 'gss_store_cred_into' required for GSSAPI''')
-  else
-    have_gssapi = false
-  endif
+if not have_gssapi
+elif cc.check_header('gssapi/gssapi_ext.h', dependencies: gssapi, required: false,
+    args: test_c_args, include_directories: postgres_inc)
+  cdata.set('HAVE_GSSAPI_GSSAPI_EXT_H', 1)
+elif cc.check_header('gssapi_ext.h', args: test_c_args, dependencies: gssapi, required: gssapiopt)
+  cdata.set('HAVE_GSSAPI_EXT_H', 1)
+else
+  have_gssapi = false
 endif
+
 if not have_gssapi
-  gssapi = not_found_dep
+elif cc.has_function('gss_store_cred_into', dependencies: gssapi,
+    args: test_c_args, include_directories: postgres_inc)
+  cdata.set('ENABLE_GSS', 1)
+
+  krb_srvtab = 'FILE:/@0@/krb5.keytab)'.format(get_option('sysconfdir'))
+  cdata.set_quoted('PG_KRB_SRVTAB', krb_srvtab)
+elif gssapiopt.enabled()
+  error('''could not find function 'gss_store_cred_into' required for GSSAPI''')
+else
+  have_gssapi = false
 endif
 
 
@@ -766,17 +759,11 @@ endif
 ###############################################################
 
 icuopt = get_option('icu')
-if not icuopt.disabled()
-  icu = dependency('icu-uc', required: icuopt)
-  icu_i18n = dependency('icu-i18n', required: icuopt)
-
-  if icu.found()
-    cdata.set('USE_ICU', 1)
-  endif
+icu = dependency('icu-uc', required: icuopt)
+icu_i18n = dependency('icu-i18n', required: icuopt)
 
-else
-  icu = not_found_dep
-  icu_i18n = not_found_dep
+if icu.found()
+  cdata.set('USE_ICU', 1)
 endif
 
 
@@ -786,14 +773,10 @@ endif
 ###############################################################
 
 libxmlopt = get_option('libxml')
-if not libxmlopt.disabled()
-  libxml = dependency('libxml-2.0', required: libxmlopt, version: '>= 2.6.23')
+libxml = dependency('libxml-2.0', required: libxmlopt, version: '>= 2.6.23')
 
-  if libxml.found()
-    cdata.set('USE_LIBXML', 1)
-  endif
-else
-  libxml = not_found_dep
+if libxml.found()
+  cdata.set('USE_LIBXML', 1)
 endif
 
 
@@ -803,14 +786,10 @@ endif
 ###############################################################
 
 libxsltopt = get_option('libxslt')
-if not libxsltopt.disabled()
-  libxslt = dependency('libxslt', required: libxsltopt)
+libxslt = dependency('libxslt', required: libxsltopt)
 
-  if libxslt.found()
-    cdata.set('USE_LIBXSLT', 1)
-  endif
-else
-  libxslt = not_found_dep
+if libxslt.found()
+  cdata.set('USE_LIBXSLT', 1)
 endif
 
 
@@ -820,16 +799,11 @@ endif
 ###############################################################
 
 lz4opt = get_option('lz4')
-if not lz4opt.disabled()
-  lz4 = dependency('liblz4', required: lz4opt)
-
-  if lz4.found()
-    cdata.set('USE_LZ4', 1)
-    cdata.set('HAVE_LIBLZ4', 1)
-  endif
+lz4 = dependency('liblz4', required: lz4opt)
 
-else
-  lz4 = not_found_dep
+if lz4.found()
+  cdata.set('USE_LZ4', 1)
+  cdata.set('HAVE_LIBLZ4', 1)
 endif
 
 
@@ -846,20 +820,18 @@ endif
 tclopt = get_option('pltcl')
 tcl_version = get_option('tcl_version')
 tcl_dep = not_found_dep
-if not tclopt.disabled()
 
-  # via pkg-config
-  tcl_dep = dependency(tcl_version, required: false)
+# via pkg-config
+tcl_dep = dependency(tcl_version, required: false)
 
-  if not tcl_dep.found()
-    tcl_dep = cc.find_library(tcl_version,
-      required: tclopt,
-      dirs: test_lib_d)
-  endif
+if not tcl_dep.found()
+  tcl_dep = cc.find_library(tcl_version,
+    required: tclopt,
+    dirs: test_lib_d)
+endif
 
-  if not cc.has_header('tcl.h', dependencies: tcl_dep, required: tclopt)
-    tcl_dep = not_found_dep
-  endif
+if not cc.has_header('tcl.h', dependencies: tcl_dep, required: tclopt)
+  tcl_dep = not_found_dep
 endif
 
 
@@ -869,35 +841,32 @@ endif
 ###############################################################
 
 pamopt = get_option('pam')
-if not pamopt.disabled()
-  pam = dependency('pam', required: false)
+pam = not_found_dep
 
-  if not pam.found()
-    pam = cc.find_library('pam', required: pamopt, dirs: test_lib_d)
-  endif
+pam = dependency('pam', required: false)
+if not pam.found()
+  pam = cc.find_library('pam', required: pamopt, dirs: test_lib_d)
+endif
 
-  if pam.found()
-    pam_header_found = false
+if pam.found()
+  pam_header_found = false
 
-    # header file <security/pam_appl.h> or <pam/pam_appl.h> is required for PAM.
-    if cc.check_header('security/pam_appl.h', dependencies: pam, required: false,
-        args: test_c_args, include_directories: postgres_inc)
-      cdata.set('HAVE_SECURITY_PAM_APPL_H', 1)
-      pam_header_found = true
-    elif cc.check_header('pam/pam_appl.h', dependencies: pam, required: pamopt,
-        args: test_c_args, include_directories: postgres_inc)
-      cdata.set('HAVE_PAM_PAM_APPL_H', 1)
-      pam_header_found = true
-    endif
+  # header file <security/pam_appl.h> or <pam/pam_appl.h> is required for PAM.
+  if cc.check_header('security/pam_appl.h', dependencies: pam, required: false,
+      args: test_c_args, include_directories: postgres_inc)
+    cdata.set('HAVE_SECURITY_PAM_APPL_H', 1)
+    pam_header_found = true
+  elif cc.check_header('pam/pam_appl.h', dependencies: pam, required: pamopt,
+      args: test_c_args, include_directories: postgres_inc)
+    cdata.set('HAVE_PAM_PAM_APPL_H', 1)
+    pam_header_found = true
+  endif
 
-    if pam_header_found
-      cdata.set('USE_PAM', 1)
-    else
-      pam = not_found_dep
-    endif
+  if pam_header_found
+    cdata.set('USE_PAM', 1)
+  else
+    pam = not_found_dep
   endif
-else
-  pam = not_found_dep
 endif
 
 
@@ -908,111 +877,110 @@ endif
 
 perlopt = get_option('plperl')
 perl_dep = not_found_dep
-if not perlopt.disabled()
-  perl_may_work = true
-
-  # First verify that perl has the necessary dependencies installed
-  perl_mods = run_command(
-    [perl,
-     '-MConfig', '-MOpcode', '-MExtUtils::Embed', '-MExtUtils::ParseXS',
-     '-e', ''],
-    check: false)
-  if perl_mods.returncode() != 0
+perl_may_work = true
+
+# First verify that perl has the necessary dependencies installed
+perl_mods = run_command(
+  [perl,
+    '-MConfig', '-MOpcode', '-MExtUtils::Embed', '-MExtUtils::ParseXS',
+    '-e', ''],
+  check: false)
+if perl_mods.returncode() != 0
+  perl_may_work = false
+  perl_msg = 'perl installation does not have the required modules'
+endif
+
+# Then inquire perl about its configuration
+if perl_may_work
+  perl_conf_cmd = [perl, '-MConfig', '-e', 'print $Config{$ARGV[0]}']
+  perlversion = run_command(perl_conf_cmd, 'api_versionstring', check: true).stdout()
+  archlibexp = run_command(perl_conf_cmd, 'archlibexp', check: true).stdout()
+  privlibexp = run_command(perl_conf_cmd, 'privlibexp', check: true).stdout()
+  useshrplib = run_command(perl_conf_cmd, 'useshrplib', check: true).stdout()
+
+  perl_inc_dir = '@0@/CORE'.format(archlibexp)
+
+  if perlversion.version_compare('< 5.14')
+    perl_may_work = false
+    perl_msg = 'Perl version 5.14 or later is required, but this is @0@'.format(perlversion)
+  elif useshrplib != 'true'
     perl_may_work = false
-    perl_msg = 'perl installation does not have the required modules'
+    perl_msg = 'need a shared perl'
   endif
+endif
 
-  # Then inquire perl about its configuration
-  if perl_may_work
-    perl_conf_cmd = [perl, '-MConfig', '-e', 'print $Config{$ARGV[0]}']
-    perlversion = run_command(perl_conf_cmd, 'api_versionstring', check: true).stdout()
-    archlibexp = run_command(perl_conf_cmd, 'archlibexp', check: true).stdout()
-    privlibexp = run_command(perl_conf_cmd, 'privlibexp', check: true).stdout()
-    useshrplib = run_command(perl_conf_cmd, 'useshrplib', check: true).stdout()
-
-    perl_inc_dir = '@0@/CORE'.format(archlibexp)
-
-    if perlversion.version_compare('< 5.14')
-      perl_may_work = false
-      perl_msg = 'Perl version 5.14 or later is required, but this is @0@'.format(perlversion)
-    elif useshrplib != 'true'
-      perl_may_work = false
-      perl_msg = 'need a shared perl'
-    endif
+if perl_may_work
+  # On most platforms, archlibexp is also where the Perl include files live ...
+  perl_ccflags = ['-I@0@'.format(perl_inc_dir)]
+  # ... but on newer macOS versions, we must use -iwithsysroot to look
+  # under sysroot
+  if not fs.is_file('@0@/perl.h'.format(perl_inc_dir)) and \
+      fs.is_file('@0@@1@/perl.h'.format(pg_sysroot, perl_inc_dir))
+    perl_ccflags = ['-iwithsysroot', perl_inc_dir]
   endif
 
-  if perl_may_work
-    # On most platforms, archlibexp is also where the Perl include files live ...
-    perl_ccflags = ['-I@0@'.format(perl_inc_dir)]
-    # ... but on newer macOS versions, we must use -iwithsysroot to look
-    # under sysroot
-    if not fs.is_file('@0@/perl.h'.format(perl_inc_dir)) and \
-       fs.is_file('@0@@1@/perl.h'.format(pg_sysroot, perl_inc_dir))
-      perl_ccflags = ['-iwithsysroot', perl_inc_dir]
-    endif
-
-    # check compiler finds header
-    if not cc.has_header('perl.h', required: false,
-        args: test_c_args + perl_ccflags, include_directories: postgres_inc)
-      perl_may_work = false
-      perl_msg = 'missing perl.h'
-    endif
+  # check compiler finds header
+  if not cc.has_header('perl.h', required: false,
+      args: test_c_args + perl_ccflags, include_directories: postgres_inc)
+    perl_may_work = false
+    perl_msg = 'missing perl.h'
   endif
+endif
 
-  if perl_may_work
-    perl_ccflags_r = run_command(perl_conf_cmd, 'ccflags', check: true).stdout()
+if perl_may_work
+  perl_ccflags_r = run_command(perl_conf_cmd, 'ccflags', check: true).stdout()
 
-    # See comments for PGAC_CHECK_PERL_EMBED_CCFLAGS in perl.m4
-    foreach flag : perl_ccflags_r.split(' ')
-      if flag.startswith('-D') and \
-          (not flag.startswith('-D_') or flag == '_USE_32BIT_TIME_T')
-        perl_ccflags += flag
-      endif
-    endforeach
+  # See comments for PGAC_CHECK_PERL_EMBED_CCFLAGS in perl.m4
+  foreach flag : perl_ccflags_r.split(' ')
+    if flag.startswith('-D') and \
+        (not flag.startswith('-D_') or flag == '_USE_32BIT_TIME_T')
+      perl_ccflags += flag
+    endif
+  endforeach
 
-    if host_system == 'windows'
-      perl_ccflags += ['-DPLPERL_HAVE_UID_GID']
+  if host_system == 'windows'
+    perl_ccflags += ['-DPLPERL_HAVE_UID_GID']
 
-      if cc.get_id() == 'msvc'
-        # prevent binary mismatch between MSVC built plperl and Strawberry or
-        # msys ucrt perl libraries
-        perl_ccflags += ['-DNO_THREAD_SAFE_LOCALE']
-      endif
+    if cc.get_id() == 'msvc'
+      # prevent binary mismatch between MSVC built plperl and Strawberry or
+      # msys ucrt perl libraries
+      perl_ccflags += ['-DNO_THREAD_SAFE_LOCALE']
     endif
+  endif
 
-    message('CCFLAGS recommended by perl: @0@'.format(perl_ccflags_r))
-    message('CCFLAGS for embedding perl: @0@'.format(' '.join(perl_ccflags)))
+  message('CCFLAGS recommended by perl: @0@'.format(perl_ccflags_r))
+  message('CCFLAGS for embedding perl: @0@'.format(' '.join(perl_ccflags)))
 
-    # We are after Embed's ldopts, but without the subset mentioned in
-    # Config's ccdlflags and ldflags.  (Those are the choices of those who
-    # built the Perl installation, which are not necessarily appropriate
-    # for building PostgreSQL.)
-    ldopts = run_command(perl, '-MExtUtils::Embed', '-e', 'ldopts', check: true).stdout().strip()
-    undesired = run_command(perl_conf_cmd, 'ccdlflags', check: true).stdout().split()
-    undesired += run_command(perl_conf_cmd, 'ldflags', check: true).stdout().split()
+  # We are after Embed's ldopts, but without the subset mentioned in
+  # Config's ccdlflags and ldflags.  (Those are the choices of those who
+  # built the Perl installation, which are not necessarily appropriate
+  # for building PostgreSQL.)
+  ldopts = run_command(perl, '-MExtUtils::Embed', '-e', 'ldopts', check: true).stdout().strip()
+  undesired = run_command(perl_conf_cmd, 'ccdlflags', check: true).stdout().split()
+  undesired += run_command(perl_conf_cmd, 'ldflags', check: true).stdout().split()
 
-    perl_ldopts = []
-    foreach ldopt : ldopts.split(' ')
-      if ldopt == '' or ldopt in undesired
-        continue
-      endif
+  perl_ldopts = []
+  foreach ldopt : ldopts.split(' ')
+    if ldopt == '' or ldopt in undesired
+      continue
+    endif
 
-      perl_ldopts += ldopt.strip('"')
-    endforeach
+    perl_ldopts += ldopt.strip('"')
+  endforeach
 
-    message('LDFLAGS recommended by perl: "@0@"'.format(ldopts))
-    message('LDFLAGS for embedding perl: "@0@"'.format(' '.join(perl_ldopts)))
+  message('LDFLAGS recommended by perl: "@0@"'.format(ldopts))
+  message('LDFLAGS for embedding perl: "@0@"'.format(' '.join(perl_ldopts)))
 
-    perl_dep_int = declare_dependency(
-      compile_args: perl_ccflags,
-      link_args: perl_ldopts,
-      version: perlversion,
-    )
+  perl_dep_int = declare_dependency(
+    compile_args: perl_ccflags,
+    link_args: perl_ldopts,
+    version: perlversion,
+  )
 
-    # While we're at it, check that we can link to libperl.
-    # On most platforms, if perl.h is there then libperl.so will be too, but
-    # at this writing Debian packages them separately.
-    perl_link_test = '''
+  # While we're at it, check that we can link to libperl.
+  # On most platforms, if perl.h is there then libperl.so will be too, but
+  # at this writing Debian packages them separately.
+  perl_link_test = '''
 /* see plperl.h */
 #ifdef _MSC_VER
 #define __inline__ inline
@@ -1023,23 +991,22 @@ int main(void)
 {
 perl_alloc();
 }'''
-    if not cc.links(perl_link_test, name: 'libperl',
-          args: test_c_args + perl_ccflags + perl_ldopts,
-          include_directories: postgres_inc)
-      perl_may_work = false
-      perl_msg = 'missing libperl'
-    endif
+  if not cc.links(perl_link_test, name: 'libperl',
+        args: test_c_args + perl_ccflags + perl_ldopts,
+        include_directories: postgres_inc)
+    perl_may_work = false
+    perl_msg = 'missing libperl'
+  endif
 
-  endif # perl_may_work
+endif # perl_may_work
 
-  if perl_may_work
-    perl_dep = perl_dep_int
+if perl_may_work
+  perl_dep = perl_dep_int
+else
+  if perlopt.enabled()
+    error('dependency plperl failed: @0@'.format(perl_msg))
   else
-    if perlopt.enabled()
-      error('dependency plperl failed: @0@'.format(perl_msg))
-    else
-      message('disabling optional dependency plperl: @0@'.format(perl_msg))
-    endif
+    message('disabling optional dependency plperl: @0@'.format(perl_msg))
   endif
 endif
 
@@ -1051,15 +1018,13 @@ endif
 
 pyopt = get_option('plpython')
 python3_dep = not_found_dep
-if not pyopt.disabled()
-  pm = import('python')
-  python3_inst = pm.find_installation(required: pyopt)
-  if python3_inst.found()
-    python3_dep = python3_inst.dependency(embed: true, required: pyopt)
-    # Remove this check after we depend on Meson >= 1.1.0
-    if not cc.check_header('Python.h', dependencies: python3_dep, required: pyopt)
-      python3_dep = not_found_dep
-    endif
+pm = import('python')
+python3_inst = pm.find_installation(required: pyopt)
+if python3_inst.found()
+  python3_dep = python3_inst.dependency(embed: true, required: pyopt)
+  # Remove this check after we depend on Meson >= 1.1.0
+  if not cc.check_header('Python.h', dependencies: python3_dep, required: pyopt)
+    python3_dep = not_found_dep
   endif
 endif
 
@@ -1069,7 +1034,9 @@ endif
 # Library: Readline
 ###############################################################
 
-if not get_option('readline').disabled()
+readlineopt = get_option('readline')
+readline = not_found_dep
+if not readlineopt.disabled()
   libedit_preferred = get_option('libedit_preferred')
   # Set the order of readline dependencies
   check_readline_deps = libedit_preferred ? \
@@ -1079,7 +1046,7 @@ if not get_option('readline').disabled()
     readline = dependency(readline_dep, required: false)
     if not readline.found()
       readline = cc.find_library(readline_dep,
-        required: get_option('readline'),
+        required: readlineopt,
         dirs: test_lib_d)
     endif
     if readline.found()
@@ -1180,8 +1147,6 @@ Use -Dreadline=disabled to disable readline support.'''.format(readline_dep))
   endif
 
   # XXX: Figure out whether to implement mingw warning equivalent
-else
-  readline = not_found_dep
 endif
 
 
@@ -1368,34 +1333,32 @@ endif
 
 zlibopt = get_option('zlib')
 zlib = not_found_dep
-if not zlibopt.disabled()
-  zlib_t = dependency('zlib', required: zlibopt)
-
-  if zlib_t.type_name() == 'internal'
-    # if fallback was used, we don't need to test if headers are present (they
-    # aren't built yet, so we can't test)
-    zlib = zlib_t
-  elif not zlib_t.found()
-    warning('did not find zlib')
-  elif not cc.has_header('zlib.h',
-      args: test_c_args, include_directories: postgres_inc,
-      dependencies: [zlib_t], required: zlibopt.enabled())
-    warning('zlib header not found')
-  elif not cc.has_type('z_streamp',
-      dependencies: [zlib_t], prefix: '#include <zlib.h>',
-      args: test_c_args, include_directories: postgres_inc)
-    if zlibopt.enabled()
-      error('zlib version is too old')
-    else
-      warning('zlib version is too old')
-    endif
+
+zlib_t = dependency('zlib', required: zlibopt)
+if zlib_t.found() and zlib_t.type_name() == 'internal'
+  # if fallback was used, we don't need to test if headers are present (they
+  # aren't built yet, so we can't test)
+  zlib = zlib_t
+elif not zlib_t.found()
+  warning('did not find zlib')
+elif not cc.has_header('zlib.h',
+    args: test_c_args, include_directories: postgres_inc,
+    dependencies: [zlib_t], required: zlibopt)
+  warning('zlib header not found')
+elif not cc.has_type('z_streamp',
+    dependencies: [zlib_t], prefix: '#include <zlib.h>',
+    args: test_c_args, include_directories: postgres_inc)
+  if zlibopt.enabled()
+    error('zlib version is too old')
   else
-    zlib = zlib_t
+    warning('zlib version is too old')
   endif
+else
+  zlib = zlib_t
+endif
 
-  if zlib.found()
-    cdata.set('HAVE_LIBZ', 1)
-  endif
+if zlib.found()
+  cdata.set('HAVE_LIBZ', 1)
 endif
 
 
@@ -1429,16 +1392,11 @@ endif
 ###############################################################
 
 zstdopt = get_option('zstd')
-if not zstdopt.disabled()
-  zstd = dependency('libzstd', required: zstdopt, version: '>=1.4.0')
-
-  if zstd.found()
-    cdata.set('USE_ZSTD', 1)
-    cdata.set('HAVE_LIBZSTD', 1)
-  endif
+zstd = dependency('libzstd', required: zstdopt, version: '>=1.4.0')
 
-else
-  zstd = not_found_dep
+if zstd.found()
+  cdata.set('USE_ZSTD', 1)
+  cdata.set('HAVE_LIBZSTD', 1)
 endif
 
 
@@ -2534,32 +2492,30 @@ cdata.set('ENABLE_THREAD_SAFETY', 1)
 nlsopt = get_option('nls')
 libintl = not_found_dep
 
-if not nlsopt.disabled()
-  # otherwise there'd be lots of
-  # "Gettext not found, all translation (po) targets will be ignored."
-  # warnings if not found.
-  msgfmt = find_program('msgfmt', required: nlsopt, native: true)
+# otherwise there'd be lots of
+# "Gettext not found, all translation (po) targets will be ignored."
+# warnings if not found.
+msgfmt = find_program('msgfmt', required: nlsopt, native: true)
 
-  # meson 0.59 has this wrapped in dependency('int')
-  if (msgfmt.found() and
-      cc.check_header('libintl.h', required: nlsopt,
-        args: test_c_args, include_directories: postgres_inc))
+# meson 0.59 has this wrapped in dependency('int')
+if (msgfmt.found() and
+    cc.check_header('libintl.h', required: nlsopt,
+      args: test_c_args, include_directories: postgres_inc))
 
-    # in libc
-    if cc.has_function('ngettext')
-      libintl = declare_dependency()
-    else
-      libintl = cc.find_library('intl',
-        has_headers: ['libintl.h'], required: nlsopt,
-        header_include_directories: postgres_inc,
-        dirs: test_lib_d)
-    endif
+  # in libc
+  if cc.has_function('ngettext')
+    libintl = declare_dependency()
+  else
+    libintl = cc.find_library('intl',
+      has_headers: ['libintl.h'], required: nlsopt,
+      header_include_directories: postgres_inc,
+      dirs: test_lib_d)
   endif
+endif
 
-  if libintl.found()
-    i18n = import('i18n')
-    cdata.set('ENABLE_NLS', 1)
-  endif
+if libintl.found()
+  i18n = import('i18n')
+  cdata.set('ENABLE_NLS', 1)
 endif
 
 
-- 
Tristan Partin
Neon (https://neon.tech)

