From 85f3030e4b9c41435143fd4d157fc9f95d6fbcac Mon Sep 17 00:00:00 2001 From: Lukasz Majewski Date: Mon, 5 Apr 2021 16:07:53 +0200 Subject: [PATCH] cli: meson: Support building nmcli with libedit After this change the nmcli program built with meson will have the possibility to use libedit (BSD license) instead of libreadline (GPLv3). Meson configuration line: meson configure -Dreadline=libedit -C ../nm-build/ or meson --reconfigure -Dreadline=libedit ../nm-build/ ninja -C ../nm-build/ The new 'readline' option is set to 'auto' by default, so the current behavior shall be preserved (and the libreadline is used). Two new config.h flags (always defined) have been introduced - HAVE_EDITLINE_READLINE and HAVE_READLINE_HISTORY. --- config.h.meson | 6 ++++++ meson.build | 42 ++++++++++++++++++++++++++---------------- meson_options.txt | 1 + 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/config.h.meson b/config.h.meson index 432402d5b4..5979793e5c 100644 --- a/config.h.meson +++ b/config.h.meson @@ -255,3 +255,9 @@ #mesondefine HAVE_PIDFD_OPEN #mesondefine HAVE_PIDFD_SEND_SIGNAL #mesondefine HAVE_RT_SIGQUEUEINFO + +/* Define to 1 if you want to use -ledit, otherwise 0 for default -lreadline. */ +#mesondefine HAVE_EDITLINE_READLINE + +/* Define to 1 if you have history support from -lreadline. */ +#mesondefine HAVE_READLINE_HISTORY diff --git a/meson.build b/meson.build index 6082828194..0c5a28fbc6 100644 --- a/meson.build +++ b/meson.build @@ -733,24 +733,33 @@ if enable_concheck endif 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') + if readline.found() + readline_dep = declare_dependency(link_args: '-lreadline') + config_h.set10('HAVE_READLINE_HISTORY', true) + else + assert(enable_readline == 'auto', 'libreadline was not found') + endif + endif + if enable_readline == 'libedit' or (enable_readline == 'auto' and not readline.found()) + edit = dependency('libedit') + if edit.found() + readline_dep = declare_dependency(link_args: '-ledit') + config_h.set10('HAVE_EDITLINE_READLINE', true) + else + assert(enable_readline == 'auto', 'libedit was not found') + endif + endif +endif + enable_nmcli = get_option('nmcli') if enable_nmcli - # FIXME: check for readline - # AX_LIB_READLINE - readline_dep = declare_dependency(link_args: '-lreadline') - ''' - foreach readline_lib: ['-lreadline', '-ledit', '-leditline'] - if not is_variable('readline_dep') - foreach termcap_lib: ['', '-lncurses', '-ltermcap', '-lcurses'] - test_dep = declare_dependency(link_args: ' '.join([readline_lib, termcap_lib])) - if cc.has_function('readline', dependencies: test_dep) and cc.has_header('readline', dependencies: test_dep) - readline_dep = test_dep - endif - endforeach - endif - endforeach - ''' - assert(readline_dep.found(), 'readline library with terminfo support is required (one of readline, edit, or editline, AND one of ncurses, curses, or termcap)') + assert(enable_readline != 'none', 'readline library with terminfo support is required (one of readline, edit, or editline, AND one of ncurses, curses, or termcap)') endif enable_nmtui = get_option('nmtui') @@ -1086,4 +1095,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' message(output) diff --git a/meson_options.txt b/meson_options.txt index 14ed4077a0..76a131ad05 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -72,3 +72,4 @@ option('ld_gc', type: 'boolean', value: true, description: 'Enable garbage colle option('libpsl', type: 'boolean', value: true, description: 'Link against libpsl') option('crypto', type: 'combo', choices: ['nss', 'gnutls'], value: 'nss', description: 'Cryptography library to use for certificate and key operations') option('qt', type: 'boolean', value: true, description: 'enable Qt examples') +option('readline', type: 'combo', choices: ['auto', 'libreadline', 'libedit', 'none'], description: 'Using readline (auto) or libedit)')