meson: cleanup curses/iconv test

Skip the test if it is system emulation is not requested, and
differentiate errors for lack of iconv and lack of curses.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2020-10-15 13:26:50 -04:00
parent ac0c8351ab
commit 30fe76b17c

View File

@ -455,40 +455,40 @@ if targetos == 'linux' and have_tools and not get_option('mpath').disabled()
endif endif
iconv = not_found iconv = not_found
if not get_option('iconv').disabled()
libiconv = cc.find_library('iconv',
required: false,
static: enable_static)
if cc.links('''
#include <iconv.h>
int main(void) {
iconv_t conv = iconv_open("WCHAR_T", "UCS-2");
return conv != (iconv_t) -1;
}''', dependencies: [libiconv])
iconv = declare_dependency(dependencies: [libiconv])
endif
endif
if get_option('iconv').enabled() and not iconv.found()
error('Cannot detect iconv API')
endif
curses = not_found curses = not_found
if iconv.found() and not get_option('curses').disabled() if have_system and not get_option('curses').disabled()
curses_libname_list = ['ncursesw', 'ncurses', 'cursesw', 'pdcurses'] if not get_option('iconv').disabled()
curses_test = ''' libiconv = cc.find_library('iconv',
#include <locale.h> required: false,
#include <curses.h> static: enable_static)
#include <wchar.h> if cc.links('''
int main(void) { #include <iconv.h>
wchar_t wch = L'w'; int main(void) {
setlocale(LC_ALL, ""); iconv_t conv = iconv_open("WCHAR_T", "UCS-2");
resize_term(0, 0); return conv != (iconv_t) -1;
addwstr(L"wide chars\n"); }''', dependencies: [libiconv])
addnwstr(&wch, 1); iconv = declare_dependency(dependencies: [libiconv])
add_wch(WACS_DEGREE); endif
return 0; endif
}''' if get_option('iconv').enabled() and not iconv.found()
foreach curses_libname : curses_libname_list error('Cannot detect iconv API')
endif
if iconv.found()
curses_libname_list = ['ncursesw', 'ncurses', 'cursesw', 'pdcurses']
curses_test = '''
#include <locale.h>
#include <curses.h>
#include <wchar.h>
int main(void) {
wchar_t wch = L'w';
setlocale(LC_ALL, "");
resize_term(0, 0);
addwstr(L"wide chars\n");
addnwstr(&wch, 1);
add_wch(WACS_DEGREE);
return 0;
}'''
foreach curses_libname : curses_libname_list
libcurses = dependency(curses_libname, libcurses = dependency(curses_libname,
required: false, required: false,
method: 'pkg-config', method: 'pkg-config',
@ -510,13 +510,18 @@ if iconv.found() and not get_option('curses').disabled()
break break
endif endif
endif endif
endforeach endforeach
endif endif
if get_option('curses').enabled() and not curses.found() if not curses.found()
if not iconv.found() if iconv.found()
error('Cannot detect iconv API') if get_option('curses').enabled()
else error('Cannot find curses')
error('Cannot detect curses API') endif
elif get_option('curses').enabled()
error('iconv required for curses UI but not available')
else
warning('iconv required for curses UI but not available, disabling')
endif
endif endif
endif endif