v1-0002-meson-Refactor-UUID-option.patch

text/plain

Filename: v1-0002-meson-Refactor-UUID-option.patch
Type: text/plain
Part: 1
Message: Re: meson: Non-feature feature options

Patch

Format: format-patch
Series: patch v1-0002
Subject: meson: Refactor UUID option
File+
.cirrus.yml 2 3
meson.build 39 21
meson_options.txt 2 2
From 0d94e30facc9e1bbd489afa563fd57c9ed002bba Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
Date: Mon, 13 Feb 2023 15:22:05 +0300
Subject: [PATCH v1 2/2] meson: Refactor UUID option

---
 .cirrus.yml       |  5 ++--
 meson.build       | 60 ++++++++++++++++++++++++++++++-----------------
 meson_options.txt |  4 ++--
 3 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index aaf4066366..d696d5dc48 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -181,7 +181,7 @@ task:
     su postgres <<-EOF
       meson setup \
         --buildtype=debug \
-        -Dcassert=true -Duuid=bsd -Dtcl_version=tcl86 -Ddtrace=auto \
+        -Dcassert=true -Dtcl_version=tcl86 -Ddtrace=auto \
         -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
         -Dextra_lib_dirs=/usr/local/lib -Dextra_include_dirs=/usr/local/include/ \
         build
@@ -243,7 +243,6 @@ LINUX_CONFIGURE_FEATURES: &LINUX_CONFIGURE_FEATURES >-
 
 LINUX_MESON_FEATURES: &LINUX_MESON_FEATURES >-
   -Dllvm=enabled
-  -Duuid=e2fs
 
 
 task:
@@ -496,7 +495,7 @@ task:
       -Dextra_include_dirs=${brewpath}/include \
       -Dextra_lib_dirs=${brewpath}/lib \
       -Dcassert=true \
-      -Duuid=e2fs -Ddtrace=auto \
+      -Ddtrace=auto \
       -Dsegsize_blocks=6 \
       -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
       build
diff --git a/meson.build b/meson.build
index 563589ac48..26f48a4c12 100644
--- a/meson.build
+++ b/meson.build
@@ -1259,31 +1259,49 @@ endif
 
 uuidopt = get_option('uuid')
 if uuidopt != 'none'
-  uuidname = uuidopt.to_upper()
-  if uuidopt == 'e2fs'
-    uuid = dependency('uuid', required: true)
-    uuidfunc = 'uuid_generate'
-    uuidheader = 'uuid/uuid.h'
-  elif uuidopt == 'bsd'
-    # libc should have uuid function
-    uuid = declare_dependency()
-    uuidfunc = 'uuid_to_string'
-    uuidheader = 'uuid.h'
-  elif uuidopt == 'ossp'
-    uuid = dependency('ossp-uuid', required: true)
-    uuidfunc = 'uuid_export'
-    uuidheader = 'ossp/uuid.h'
-  else
-    error('huh')
-  endif
 
-  if not cc.has_header_symbol(uuidheader, uuidfunc, args: test_c_args, dependencies: uuid)
+  uuidtypes = {
+    'e2fs': {
+      'uuiddep': 'uuid',
+      'uuidfunc': 'uuid_generate',
+      'uuidheader': 'uuid/uuid.h',
+    },
+    'bsd': {
+      # libc should have uuid function
+      'uuiddep': '',
+      'uuidfunc': 'uuid_to_string',
+      'uuidheader': 'uuid.h',
+    },
+    'ossp': {
+      'uuiddep':'ossp-uuid',
+      'uuidfunc': 'uuid_export',
+      'uuidheader': 'ossp/uuid.h',
+    },
+  }
+
+  uuidfound = false
+  foreach uuidname, uuidelements : uuidtypes
+    if uuidopt == 'auto' or uuidopt == uuidname
+      uuiddep = uuidelements['uuiddep']
+      uuid = uuiddep != '' ? dependency(uuiddep, required: false) : declare_dependency()
+      uuidfunc = uuidelements['uuidfunc']
+      uuidheader = uuidelements['uuidheader']
+
+      if cc.has_header_symbol(uuidheader, uuidfunc, args: test_c_args, dependencies: uuid)
+        uuidfound = true
+        uuidname = uuidname.to_upper()
+        cdata.set('HAVE_@0@'.format(uuidheader.underscorify().to_upper()), 1)
+        cdata.set('HAVE_UUID_@0@'.format(uuidname), 1,
+                description: 'Define to 1 if you have @0@ UUID support.'.format(uuidname))
+        break
+      endif
+    endif
+  endforeach
+
+  if not uuidfound and uuidopt != 'auto'
     error('uuid library @0@ missing required function @1@'.format(uuidopt, uuidfunc))
   endif
-  cdata.set('HAVE_@0@'.format(uuidheader.underscorify().to_upper()), 1)
 
-  cdata.set('HAVE_UUID_@0@'.format(uuidname), 1,
-           description: 'Define to 1 if you have @0@ UUID support.'.format(uuidname))
 else
   uuid = not_found_dep
 endif
diff --git a/meson_options.txt b/meson_options.txt
index 9c74cc6512..9b7768a8e2 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -133,8 +133,8 @@ option('ssl', type : 'feature', value : 'auto',
 option('systemd', type : 'feature', value: 'auto',
   description: 'build with systemd support')
 
-option('uuid', type : 'combo', choices : ['none', 'bsd', 'e2fs', 'ossp'],
-  value : 'none',
+option('uuid', type : 'combo', choices : ['auto', 'none', 'bsd', 'e2fs', 'ossp'],
+  value : 'auto',
   description: 'build contrib/uuid-ossp using LIB')
 
 option('zlib', type : 'feature', value: 'auto',
-- 
2.25.1