@@ -43,6 +43,7 @@ cc = meson.get_compiler('c')
4343
4444not_found_dep = dependency ('' , required : false )
4545thread_dep = dependency (' threads' )
46+ auto_features = get_option (' auto_features' )
4647
4748
4849
@@ -1171,7 +1172,16 @@ cdata.set('USE_SYSTEMD', systemd.found() ? 1 : false)
11711172# Library: SSL
11721173###############################################################
11731174
1174- if get_option (' ssl' ) == ' openssl'
1175+ ssl = not_found_dep
1176+ ssl_library = ' none'
1177+ sslopt = get_option (' ssl' )
1178+
1179+ if sslopt == ' auto' and auto_features.disabled()
1180+ sslopt = ' none'
1181+ endif
1182+
1183+ if sslopt in [' auto' , ' openssl' ]
1184+ openssl_required = (sslopt == ' openssl' )
11751185
11761186 # Try to find openssl via pkg-config et al, if that doesn't work
11771187 # (e.g. because it's provided as part of the OS, like on FreeBSD), look for
@@ -1193,58 +1203,70 @@ if get_option('ssl') == 'openssl'
11931203
11941204 ssl = declare_dependency (dependencies : ssl_int,
11951205 include_directories : postgres_inc)
1196- else
1197- cc.has_header(' openssl/ssl.h' , args : test_c_args, dependencies : ssl, required : true )
1198- cc.has_header(' openssl/err.h' , args : test_c_args, dependencies : ssl, required : true )
1199-
1206+ elif cc.has_header(' openssl/ssl.h' , args : test_c_args, dependencies : ssl, required : openssl_required) and \
1207+ cc.has_header(' openssl/err.h' , args : test_c_args, dependencies : ssl, required : openssl_required)
12001208 ssl_int = [ssl]
12011209 endif
12021210
1203- check_funcs = [
1204- [' CRYPTO_new_ex_data' , {' required' : true }],
1205- [' SSL_new' , {' required' : true }],
1206-
1207- # Function introduced in OpenSSL 1.0.2.
1208- [' X509_get_signature_nid' ],
1209-
1210- # Functions introduced in OpenSSL 1.1.0. We used to check for
1211- # OPENSSL_VERSION_NUMBER, but that didn't work with 1.1.0, because LibreSSL
1212- # defines OPENSSL_VERSION_NUMBER to claim version 2.0.0, even though it
1213- # doesn't have these OpenSSL 1.1.0 functions. So check for individual
1214- # functions.
1215- [' OPENSSL_init_ssl' ],
1216- [' BIO_get_data' ],
1217- [' BIO_meth_new' ],
1218- [' ASN1_STRING_get0_data' ],
1219- [' HMAC_CTX_new' ],
1220- [' HMAC_CTX_free' ],
1221-
1222- # OpenSSL versions before 1.1.0 required setting callback functions, for
1223- # thread-safety. In 1.1.0, it's no longer required, and CRYPTO_lock()
1224- # function was removed.
1225- [' CRYPTO_lock' ],
1226-
1227- # Function introduced in OpenSSL 1.1.1
1228- [' X509_get_signature_info' ],
1229- ]
1211+ if ssl.found()
1212+ check_funcs = [
1213+ [' CRYPTO_new_ex_data' , {' required' : true }],
1214+ [' SSL_new' , {' required' : true }],
1215+
1216+ # Function introduced in OpenSSL 1.0.2.
1217+ [' X509_get_signature_nid' ],
1218+
1219+ # Functions introduced in OpenSSL 1.1.0. We used to check for
1220+ # OPENSSL_VERSION_NUMBER, but that didn't work with 1.1.0, because LibreSSL
1221+ # defines OPENSSL_VERSION_NUMBER to claim version 2.0.0, even though it
1222+ # doesn't have these OpenSSL 1.1.0 functions. So check for individual
1223+ # functions.
1224+ [' OPENSSL_init_ssl' ],
1225+ [' BIO_get_data' ],
1226+ [' BIO_meth_new' ],
1227+ [' ASN1_STRING_get0_data' ],
1228+ [' HMAC_CTX_new' ],
1229+ [' HMAC_CTX_free' ],
1230+
1231+ # OpenSSL versions before 1.1.0 required setting callback functions, for
1232+ # thread-safety. In 1.1.0, it's no longer required, and CRYPTO_lock()
1233+ # function was removed.
1234+ [' CRYPTO_lock' ],
1235+
1236+ # Function introduced in OpenSSL 1.1.1
1237+ [' X509_get_signature_info' ],
1238+ ]
1239+
1240+ are_openssl_funcs_complete = true
1241+ foreach c : check_funcs
1242+ func = c.get(0 )
1243+ val = cc.has_function(func, args : test_c_args, dependencies : ssl_int)
1244+ required = c.get(1 , {}).get(' required' , false )
1245+ if required and not val
1246+ are_openssl_funcs_complete = false
1247+ if openssl_required
1248+ error (' openssl function @0@ is required' .format(func))
1249+ endif
1250+ break
1251+ elif not required
1252+ cdata.set(' HAVE_' + func.to_upper(), val ? 1 : false )
1253+ endif
1254+ endforeach
12301255
1231- foreach c : check_funcs
1232- func = c.get( 0 )
1233- val = cc.has_function(func, args : test_c_args, dependencies : ssl_int )
1234- required = c.get( 1 , {}).get( ' required ' , false )
1235- if required and not val
1236- error ( ' openssl function @0@ is required ' .format(func))
1237- elif not required
1238- cdata.set( ' HAVE_ ' + func.to_upper(), val ? 1 : false )
1256+ if are_openssl_funcs_complete
1257+ cdata.set( ' USE_OPENSSL ' , 1 ,
1258+ description : ' Define to 1 to build with OpenSSL support. (-Dssl=openssl) ' )
1259+ cdata.set( ' OPENSSL_API_COMPAT ' , ' 0x10001000L ' ,
1260+ description : ''' Define to the OpenSSL API version in use. This avoids deprecation warnings from newer OpenSSL versions. ''' )
1261+ ssl_library = ' openssl '
1262+ else
1263+ ssl = not_found_dep
12391264 endif
1240- endforeach
1265+ endif
1266+ endif
12411267
1242- cdata.set(' USE_OPENSSL' , 1 ,
1243- description : ' Define to 1 to build with OpenSSL support. (-Dssl=openssl)' )
1244- cdata.set(' OPENSSL_API_COMPAT' , ' 0x10001000L' ,
1245- description : ''' Define to the OpenSSL API version in use. This avoids deprecation warnings from newer OpenSSL versions.''' )
1246- else
1247- ssl = not_found_dep
1268+ if sslopt == ' auto' and auto_features.enabled() and not ssl.found()
1269+ error (' no SSL library found' )
12481270endif
12491271
12501272
@@ -3266,13 +3288,13 @@ if meson.version().version_compare('>=0.57')
32663288 ' llvm' : llvm,
32673289 ' lz4' : lz4,
32683290 ' nls' : libintl,
3291+ ' openssl' : ssl,
32693292 ' pam' : pam,
32703293 ' plperl' : perl_dep,
32713294 ' plpython' : python3_dep,
32723295 ' pltcl' : tcl_dep,
32733296 ' readline' : readline,
32743297 ' selinux' : selinux,
3275- ' ssl' : ssl,
32763298 ' systemd' : systemd,
32773299 ' uuid' : uuid,
32783300 ' zlib' : zlib,
0 commit comments