Skip to content

Commit af7a69b

Browse files
authored
build(meson): add non_blocking_getaddrinfo option (#2174)
This new option automatically enables the new non-blocking name resolution when the appropriate libraries are found, automatically adding them to the list of required dependencies. It will gracefully fall back to the old behaviour when no library is found. This complements commit ea850cb.
1 parent 145fc8b commit af7a69b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

meson.build

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ project(
1616
meson_version: '>=0.62.0'
1717
)
1818

19+
cxx = meson.get_compiler('cpp')
20+
1921
# Check just in case downstream decides to edit the source
2022
# and add a project version
2123
version = meson.project_version()
2224
if version == 'undefined'
23-
cxx = meson.get_compiler('cpp')
2425
version = cxx.get_define('CPPHTTPLIB_VERSION',
2526
prefix: '#include <httplib.h>',
2627
include_directories: include_directories('.')).strip('"')
@@ -65,6 +66,21 @@ if brotli_found_all
6566
args += '-DCPPHTTPLIB_BROTLI_SUPPORT'
6667
endif
6768

69+
async_ns_opt = get_option('cpp-httplib_non_blocking_getaddrinfo')
70+
71+
if host_machine.system() == 'windows'
72+
async_ns_dep = cxx.find_library('ws2_32', required: async_ns_opt)
73+
elif host_machine.system() == 'darwin'
74+
async_ns_dep = dependency('appleframeworks', modules: ['CFNetwork'], required: async_ns_opt)
75+
else
76+
async_ns_dep = cxx.find_library('anl', required: async_ns_opt)
77+
endif
78+
79+
if async_ns_dep.found()
80+
deps += async_ns_dep
81+
args += '-DCPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO'
82+
endif
83+
6884
cpp_httplib_dep = dependency('', required: false)
6985

7086
if get_option('cpp-httplib_compile')

meson_options.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ option('cpp-httplib_openssl', type: 'feature', value: 'auto', description: 'Enab
66
option('cpp-httplib_zlib', type: 'feature', value: 'auto', description: 'Enable zlib support')
77
option('cpp-httplib_brotli', type: 'feature', value: 'auto', description: 'Enable Brotli support')
88
option('cpp-httplib_macosx_keychain', type: 'feature', value: 'auto', description: 'Enable loading certs from the Keychain on Apple devices')
9+
option('cpp-httplib_non_blocking_getaddrinfo', type: 'feature', value: 'auto', description: 'Enable asynchronous name lookup')
910
option('cpp-httplib_compile', type: 'boolean', value: false, description: 'Split the header into a compilable header & source file (requires python3)')
1011
option('cpp-httplib_test', type: 'boolean', value: false, description: 'Build tests')

0 commit comments

Comments
 (0)