meson: rewrite curses/iconv test
PATCH 1/1 meson: rewrite curses/iconv test
Redo the curses test to do the same tests that the configure check used to do. OpenBSD triggers the warning because it does not support NCURSES_WIDECHAR and thus the cc.links test fails.
--- meson.build | 109 +++++++++++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 49 deletions(-)
meson.build +60 -49
@@ -463,6 +463,59 @@ endif iconv = not_found curses = not_found if have_system and not get_option('curses').disabled() + 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; + }''' + + curses = dependency((targetos == 'windows' ? 'ncurses' : 'ncursesw'), + required: false, + method: 'pkg-config', + static: enable_static) + msg = get_option('curses').enabled() ? 'curses library not found' : '' + if curses.found() + if cc.links(curses_test, dependencies: [curses]) + curses = declare_dependency(compile_args: '-DNCURSES_WIDECHAR', dependencies: [curses]) + else + msg = 'curses package not usable' + curses = not_found + endif + endif + if not curses.found() + curses_compile_args = ['-DNCURSES_WIDECHAR'] + has_curses_h = cc.has_header('curses.h', args: curses_compile_args) + if targetos != 'windows' and not has_curses_h + message('Trying with /usr/include/ncursesw') + curses_compile_args += ['-I/usr/include/ncursesw'] + has_curses_h = cc.has_header('curses.h', args: curses_compile_args) + endif + if has_curses_h + curses_libname_list = (targetos == 'windows' ? ['pdcurses'] : ['ncursesw', 'cursesw']) + foreach curses_libname : curses_libname_list + libcurses = cc.find_library(curses_libname, + required: false, + static: enable_static) + if libcurses.found() + if cc.links(curses_test, args: curses_compile_args, dependencies: libcurses) + curses = declare_dependency(compile_args: curses_compile_args, + dependencies: [libcurses]) + break + else + msg = 'curses library not usable' + endif + endif + endforeach + endif + endif if not get_option('iconv').disabled() libiconv = cc.find_library('iconv', required: false,
@@ -476,57 +529,15 @@ if have_system and not get_option('curses').disabled() iconv = declare_dependency(dependencies: [libiconv]) endif endif - if get_option('iconv').enabled() and not iconv.found() - error('Cannot detect iconv API') + if curses.found() and not iconv.found() + msg = 'iconv required for curses UI but not available' + curses = not_found 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, - required: false, - method: 'pkg-config', - static: enable_static) - - if not libcurses.found() - dirs = ['/usr/include/ncursesw'] - if targetos == 'windows' - dirs = [] - endif - libcurses = cc.find_library(curses_libname, - required: false, - dirs: dirs, - static: enable_static) - endif - if libcurses.found() - if cc.links(curses_test, dependencies: [libcurses]) - curses = declare_dependency(compile_args: '-DNCURSES_WIDECHAR', dependencies: [libcurses]) - break - endif - endif - endforeach - endif - if not curses.found() - if iconv.found() - if get_option('curses').enabled() - error('Cannot find curses') - endif - elif get_option('curses').enabled() - error('iconv required for curses UI but not available') + if not curses.found() and msg != '' + if get_option('curses').enabled() + error(msg) else - warning('iconv required for curses UI but not available, disabling') + warning(msg + ', disabling') endif endif endif
Signature · 1 line
2.26.2
Quoted 31 lines · Paolo Bonzini
Redo the curses test to do the same tests that the configure check used to do. OpenBSD triggers the warning because it does not support
NCURSES_WIDECHARand thus the cc.links test fails.Signed-off-by Paolo Bonzini <[email protected]>--- meson.build | 109 +++++++++++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 49 deletions(-)meson.build +12
-0@@ -463,6 +463,59 @@ endif iconv = not_found curses = not_found if have_system and not get_option('curses').disabled() + 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;
meson.build endif · line 487
Quoted 10 lines
meson.build +10
-0+ }''' + + curses = dependency((targetos == 'windows' ? 'ncurses' : 'ncursesw'), + required: false, + method: 'pkg-config', + static: enable_static) + msg = get_option('curses').enabled() ? 'curses library not found' : '' + if curses.found() + if cc.links(curses_test, dependencies: [curses]) + curses = declare_dependency(compile_args: '-DNCURSES_WIDECHAR',
dependencies: [curses])
meson.build endif · line 494
Quoted 7 lines
meson.build +7
-0+ else + msg = 'curses package not usable' + curses = not_found + endif + endif + if not curses.found() + curses_compile_args = ['-DNCURSES_WIDECHAR']
Here is what I think need improve in meson, when declare dependencies, we need a extra option compile_args
for easily testing extra compile args, and maybe also need link_args, and after suceed, these flags should as a
part of the dependencies.
meson.build endif
Quoted 8 lines
meson.build +8
-0+ has_curses_h = cc.has_header('curses.h', args: curses_compile_args) + if targetos != 'windows' and not has_curses_h + message('Trying with /usr/include/ncursesw') + curses_compile_args += ['-I/usr/include/ncursesw'] + has_curses_h = cc.has_header('curses.h', args: curses_compile_args) + endif + if has_curses_h + curses_libname_list = (targetos == 'windows' ? ['pdcurses'] :
['ncursesw', 'cursesw'])
meson.build endif
Quoted 6 lines
meson.build +6
-0+ foreach curses_libname : curses_libname_list + libcurses = cc.find_library(curses_libname, + required: false, + static: enable_static) + if libcurses.found() + if cc.links(curses_test, args: curses_compile_args,
dependencies: libcurses)
meson.build endif · line 509
Quoted 1 line
meson.build +1
-0+ curses = declare_dependency(compile_args:
curses_compile_args,
meson.build if have_system and not
Quoted 13 lines
meson.build +9
-0+ dependencies: [libcurses]) + break + else + msg = 'curses library not usable' + endif + endif + endforeach + endif + endif if not get_option('iconv').disabled() libiconv = cc.find_library('iconv', required: false,@@ -476,57 +529,15 @@ if have_system and not
get_option('curses').disabled()
Quoted 33 lines
meson.build +3
-26iconv = declare_dependency(dependencies: [libiconv]) endif endif - if get_option('iconv').enabled() and not iconv.found() - error('Cannot detect iconv API') + if curses.found() and not iconv.found() + msg = 'iconv required for curses UI but not available' + curses = not_found 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, - required: false, - method: 'pkg-config', - static: enable_static) - - if not libcurses.found() - dirs = ['/usr/include/ncursesw'] - if targetos == 'windows'
meson.build if have_system and not get_option('curses').disabled()
Quoted 10 lines
meson.build +0
-10- dirs = [] - endif - libcurses = cc.find_library(curses_libname, - required: false, - dirs: dirs, - static: enable_static) - endif - if libcurses.found() - if cc.links(curses_test, dependencies: [libcurses]) - curses = declare_dependency(compile_args:
'-DNCURSES_WIDECHAR', dependencies: [libcurses])
Quoted 7 lines
meson.build +0
-7- break - endif - endif - endforeach - endif - if not curses.found() - if iconv.found()
meson.build if have_system and not get_option('curses').disabled()
Quoted 10 lines
meson.build +3
-6- if get_option('curses').enabled() - error('Cannot find curses') - endif - elif get_option('curses').enabled() - error('iconv required for curses UI but not available') + if not curses.found() and msg != '' + if get_option('curses').enabled() + error(msg) else - warning('iconv required for curses UI but not available,
disabling')
Quoted 7 lines
meson.build +1
-1+ warning(msg + ', disabling') endif endif endif --2.26.2
--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo
Quoted 8 lines · 罗勇刚(Yonggang Luo)
Quoted 3 lines
+ if not
curses.found()+curses_compile_args=
['-DNCURSES_WIDECHAR']Here is what I think need improve in meson, when declare dependencies, we need a extra option
compile_argsfor easily testing extra compile args, and maybe also needlink_args, and after suceed, these flags should as a part of the dependencies.
I think it would make sense if cc.find_library had extra arguments that would be added to the dependency and, in case of compile_args, to the has_headers check. It's a tradeoff between keeping the language simple and making the users' code smaller.
Another possible extension is for cc.links to allow internal dependencies, as long as they do not depend on sources.
Paolo