From d0c30b6dad4769e75cbf012f1387bb54c3447f8b Mon Sep 17 00:00:00 2001 From: Nazir Bilal Yavuz Date: Mon, 13 Feb 2023 15:22:05 +0300 Subject: [PATCH v1] meson: Refactor UUID option with uuid_library --- .cirrus.yml | 5 ++- meson.build | 67 ++++++++++++++++++++++++++------------- meson_options.txt | 9 ++++-- src/makefiles/meson.build | 2 +- 4 files changed, 54 insertions(+), 29 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..8f4bbc979b 100644 --- a/meson.build +++ b/meson.build @@ -1257,33 +1257,56 @@ endif # Library: uuid ############################################################### +uuid_type = 'none' 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 uuidopt.disabled() + uuid_library = get_option('uuid_library') + + 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 uuid_library == 'auto' or uuid_library == 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 + uuid_type = uuidname + 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 cc.has_header_symbol(uuidheader, uuidfunc, args: test_c_args, dependencies: uuid) + # if uuid is enabled or uuid_library is set other than auto, + # and couldn't found any library throw an error + if not uuidfound and (uuidopt.enabled() or uuid_library != '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..88493d5a9b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -133,9 +133,12 @@ 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', - description: 'build contrib/uuid-ossp using LIB') +option('uuid', type : 'feature', value : 'auto', + description: 'whether to use uuid') + +option('uuid_library', type : 'combo', choices : ['auto', 'bsd', 'e2fs', 'ossp'], + value : 'auto', + description: 'specify uuid library') option('zlib', type : 'feature', value: 'auto', description: 'whether to use zlib') diff --git a/src/makefiles/meson.build b/src/makefiles/meson.build index 2b73a9e5dd..e03b721b13 100644 --- a/src/makefiles/meson.build +++ b/src/makefiles/meson.build @@ -67,7 +67,7 @@ pgxs_kv = { # want the chosen option, rather than the library 'with_ssl' : ssl_type, - 'with_uuid': uuidopt, + 'with_uuid': uuid_type, 'default_port': get_option('pgport'), 'with_system_tzdata': get_option('system_tzdata'), -- 2.25.1