build/meson: cleanup handling of libreadline build option

- add "required:false" to dependency() and find_library(),
  otherwise autodetection will fail.

- rename variable "enable_readline" to "with_readline" for
  consistency with autotools.

- with -Dlibreadline=auto, once we detect a library, update
  "with_readline" variable to reflect the detected choice.
  This will also be printed in the summary output.
  This is also important for the nmcli check
  `assert(with_readline != 'none', 'readline ...`.
This commit is contained in:
Thomas Haller 2021-07-15 17:33:09 +02:00
parent bf86f51c9e
commit 55fa00f05b
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -735,31 +735,34 @@ config_h.set10('WITH_CONCHECK', enable_concheck)
config_h.set10('HAVE_READLINE_HISTORY', false)
config_h.set10('HAVE_EDITLINE_READLINE', false)
enable_readline = get_option('readline')
if enable_readline != 'none'
if enable_readline == 'libreadline' or enable_readline == 'auto'
readline = cc.find_library('readline')
with_readline = get_option('readline')
if with_readline != 'none'
if with_readline == 'libreadline' or with_readline == 'auto'
readline = cc.find_library('readline', required: false)
if readline.found()
readline_dep = declare_dependency(link_args: '-lreadline')
config_h.set10('HAVE_READLINE_HISTORY', true)
with_readline = 'libreadline'
else
assert(enable_readline == 'auto', 'libreadline was not found')
assert(with_readline == 'auto', 'libreadline was not found')
endif
endif
if enable_readline == 'libedit' or (enable_readline == 'auto' and not readline.found())
edit = dependency('libedit')
if with_readline == 'libedit' or with_readline == 'auto'
edit = dependency('libedit', required: false)
if edit.found()
readline_dep = declare_dependency(link_args: '-ledit')
config_h.set10('HAVE_EDITLINE_READLINE', true)
with_readline = 'libedit'
else
assert(enable_readline == 'auto', 'libedit was not found')
assert(with_readline == 'auto', 'libedit was not found')
with_readline = 'none'
endif
endif
endif
enable_nmcli = get_option('nmcli')
if enable_nmcli
assert(enable_readline != 'none', 'readline library with terminfo support is required (one of readline, edit, or editline, AND one of ncurses, curses, or termcap)')
assert(with_readline != 'none', 'nmcli requires readline library (-Dnmcli=false or -Dreadline=auto|libreadline|libedit|none)')
endif
enable_nmtui = get_option('nmtui')
@ -1095,5 +1098,5 @@ output += ' sanitizers: ' + get_option('b_sanitize') + '\n'
output += ' Mozilla Public Suffix List: ' + enable_libpsl.to_string() + '\n'
output += ' vapi: ' + enable_vapi.to_string() + '\n'
output += ' ebpf: ' + enable_ebpf.to_string() + '\n'
output += ' readline: ' + enable_readline + '\n'
output += ' readline: ' + with_readline + '\n'
message(output)