diff mbox series

meson: rewrite curses/iconv test

Message ID 20201019094534.1713842-1-pbonzini@redhat.com
State New
Headers show
Series meson: rewrite curses/iconv test | expand

Commit Message

Paolo Bonzini Oct. 19, 2020, 9:45 a.m. UTC
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.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 meson.build | 109 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 60 insertions(+), 49 deletions(-)

Comments

罗勇刚(Yonggang Luo) Oct. 19, 2020, 7:58 p.m. UTC | #1
On Mon, Oct 19, 2020 at 5:45 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>

> 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.

>

> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

> ---

>  meson.build | 109 +++++++++++++++++++++++++++++-----------------------

>  1 file changed, 60 insertions(+), 49 deletions(-)

>

> diff --git a/meson.build b/meson.build

> index 05fb59a00b..d1155aea65 100644

> --- a/meson.build

> +++ b/meson.build

> @@ -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']


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.

> +    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

> --

> 2.26.2

>


Reviewed-by: Yonggang Luo <l <f4bug@amsat.org>uoyonggang@gmail.com>



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
<div dir="ltr"><br><br>On Mon, Oct 19, 2020 at 5:45 PM Paolo Bonzini &lt;<a href="mailto:pbonzini@redhat.com">pbonzini@redhat.com</a>&gt; wrote:<br>&gt;<br>&gt; Redo the curses test to do the same tests that the configure<br>&gt; check used to do.  OpenBSD triggers the warning because<br>&gt; it does not support NCURSES_WIDECHAR and thus the cc.links<br>&gt; test fails.<br>&gt;<br>&gt; Signed-off-by: Paolo Bonzini &lt;<a href="mailto:pbonzini@redhat.com">pbonzini@redhat.com</a>&gt;<br>&gt; ---<br>&gt;  meson.build | 109 +++++++++++++++++++++++++++++-----------------------<br>&gt;  1 file changed, 60 insertions(+), 49 deletions(-)<br>&gt;<br>&gt; diff --git a/meson.build b/meson.build<br>&gt; index 05fb59a00b..d1155aea65 100644<br>&gt; --- a/meson.build<br>&gt; +++ b/meson.build<br>&gt; @@ -463,6 +463,59 @@ endif<br>&gt;  iconv = not_found<br>&gt;  curses = not_found<br>&gt;  if have_system and not get_option(&#39;curses&#39;).disabled()<br>&gt; +  curses_test = &#39;&#39;&#39;<br>&gt; +    #include &lt;locale.h&gt;<br>&gt; +    #include &lt;curses.h&gt;<br>&gt; +    #include &lt;wchar.h&gt;<br>&gt; +    int main(void) {<br>&gt; +      wchar_t wch = L&#39;w&#39;;<br>&gt; +      setlocale(LC_ALL, &quot;&quot;);<br>&gt; +      resize_term(0, 0);<br>&gt; +      addwstr(L&quot;wide chars\n&quot;);<br>&gt; +      addnwstr(&amp;wch, 1);<br>&gt; +      add_wch(WACS_DEGREE);<br>&gt; +      return 0;<br>&gt; +    }&#39;&#39;&#39;<br>&gt; +<br>&gt; +  curses = dependency((targetos == &#39;windows&#39; ? &#39;ncurses&#39; : &#39;ncursesw&#39;),<br>&gt; +                      required: false,<br>&gt; +                      method: &#39;pkg-config&#39;,<br>&gt; +                      static: enable_static)<br>&gt; +  msg = get_option(&#39;curses&#39;).enabled() ? &#39;curses library not found&#39; : &#39;&#39;<br>&gt; +  if curses.found()<br>&gt; +    if cc.links(curses_test, dependencies: [curses])<br>&gt; +      curses = declare_dependency(compile_args: &#39;-DNCURSES_WIDECHAR&#39;, dependencies: [curses])<br>&gt; +    else<br>&gt; +      msg = &#39;curses package not usable&#39;<br>&gt; +      curses = not_found<br>&gt; +    endif<br>&gt; +  endif<br>&gt; +  if not curses.found()<br>&gt; +    curses_compile_args = [&#39;-DNCURSES_WIDECHAR&#39;]<div><br></div><div>Here is what I think need improve in meson, when declare dependencies, we need a extra option compile_args</div><div>for easily testing extra compile args, and maybe also need link_args, and after suceed, these flags should as a </div><div>part of the dependencies.</div><div><br>&gt; +    has_curses_h = cc.has_header(&#39;curses.h&#39;, args: curses_compile_args)<br>&gt; +    if targetos != &#39;windows&#39; and not has_curses_h<br>&gt; +      message(&#39;Trying with /usr/include/ncursesw&#39;)<br>&gt; +      curses_compile_args += [&#39;-I/usr/include/ncursesw&#39;]<br>&gt; +      has_curses_h = cc.has_header(&#39;curses.h&#39;, args: curses_compile_args)<br>&gt; +    endif<br>&gt; +    if has_curses_h<br>&gt; +      curses_libname_list = (targetos == &#39;windows&#39; ? [&#39;pdcurses&#39;] : [&#39;ncursesw&#39;, &#39;cursesw&#39;])<br>&gt; +      foreach curses_libname : curses_libname_list<br>&gt; +        libcurses = cc.find_library(curses_libname,<br>&gt; +                                    required: false,<br>&gt; +                                    static: enable_static)<br>&gt; +        if libcurses.found()<br>&gt; +          if cc.links(curses_test, args: curses_compile_args, dependencies: libcurses)<br>&gt; +            curses = declare_dependency(compile_args: curses_compile_args,<br>&gt; +                                        dependencies: [libcurses])<br>&gt; +            break<br>&gt; +          else<br>&gt; +            msg = &#39;curses library not usable&#39;<br>&gt; +          endif<br>&gt; +        endif<br>&gt; +      endforeach<br>&gt; +    endif<br>&gt; +  endif<br>&gt;    if not get_option(&#39;iconv&#39;).disabled()<br>&gt;      libiconv = cc.find_library(&#39;iconv&#39;,<br>&gt;                                 required: false,<br>&gt; @@ -476,57 +529,15 @@ if have_system and not get_option(&#39;curses&#39;).disabled()<br>&gt;        iconv = declare_dependency(dependencies: [libiconv])<br>&gt;      endif<br>&gt;    endif<br>&gt; -  if get_option(&#39;iconv&#39;).enabled() and not iconv.found()<br>&gt; -    error(&#39;Cannot detect iconv API&#39;)<br>&gt; +  if curses.found() and not iconv.found()<br>&gt; +    msg = &#39;iconv required for curses UI but not available&#39;<br>&gt; +    curses = not_found<br>&gt;    endif<br>&gt; -  if iconv.found()<br>&gt; -    curses_libname_list = [&#39;ncursesw&#39;, &#39;ncurses&#39;, &#39;cursesw&#39;, &#39;pdcurses&#39;]<br>&gt; -    curses_test = &#39;&#39;&#39;<br>&gt; -      #include &lt;locale.h&gt;<br>&gt; -      #include &lt;curses.h&gt;<br>&gt; -      #include &lt;wchar.h&gt;<br>&gt; -      int main(void) {<br>&gt; -        wchar_t wch = L&#39;w&#39;;<br>&gt; -        setlocale(LC_ALL, &quot;&quot;);<br>&gt; -        resize_term(0, 0);<br>&gt; -        addwstr(L&quot;wide chars\n&quot;);<br>&gt; -        addnwstr(&amp;wch, 1);<br>&gt; -        add_wch(WACS_DEGREE);<br>&gt; -        return 0;<br>&gt; -      }&#39;&#39;&#39;<br>&gt; -    foreach curses_libname : curses_libname_list<br>&gt; -      libcurses = dependency(curses_libname,<br>&gt; -                             required: false,<br>&gt; -                             method: &#39;pkg-config&#39;,<br>&gt; -                             static: enable_static)<br>&gt; -<br>&gt; -      if not libcurses.found()<br>&gt; -        dirs = [&#39;/usr/include/ncursesw&#39;]<br>&gt; -        if targetos == &#39;windows&#39;<br>&gt; -          dirs = []<br>&gt; -        endif<br>&gt; -        libcurses = cc.find_library(curses_libname,<br>&gt; -                                    required: false,<br>&gt; -                                    dirs: dirs,<br>&gt; -                                    static: enable_static)<br>&gt; -      endif<br>&gt; -      if libcurses.found()<br>&gt; -        if cc.links(curses_test, dependencies: [libcurses])<br>&gt; -          curses = declare_dependency(compile_args: &#39;-DNCURSES_WIDECHAR&#39;, dependencies: [libcurses])<br>&gt; -          break<br>&gt; -        endif<br>&gt; -      endif<br>&gt; -    endforeach<br>&gt; -  endif<br>&gt; -  if not curses.found()<br>&gt; -    if iconv.found()<br>&gt; -      if get_option(&#39;curses&#39;).enabled()<br>&gt; -        error(&#39;Cannot find curses&#39;)<br>&gt; -      endif<br>&gt; -    elif get_option(&#39;curses&#39;).enabled()<br>&gt; -      error(&#39;iconv required for curses UI but not available&#39;)<br>&gt; +  if not curses.found() and msg != &#39;&#39;<br>&gt; +    if get_option(&#39;curses&#39;).enabled()<br>&gt; +      error(msg)<br>&gt;      else<br>&gt; -      warning(&#39;iconv required for curses UI but not available, disabling&#39;)<br>&gt; +      warning(msg + &#39;, disabling&#39;)<br>&gt;      endif<br>&gt;    endif<br>&gt;  endif<br>&gt; --<br>&gt; 2.26.2<br>&gt;</div><div></div><div><br></div><div>Reviewed-by: Yonggang Luo &lt;<a href="mailto:f4bug@amsat.org" target="_blank">l</a><a href="mailto:uoyonggang@gmail.com">uoyonggang@gmail.com</a>&gt;</div><div><br class="gmail-Apple-interchange-newline"><br>--<br>         此致<br>礼<br>罗勇刚<br>Yours<br>    sincerely,<br>Yonggang Luo</div></div>
Paolo Bonzini Oct. 20, 2020, 9:12 a.m. UTC | #2
On 19/10/20 21:58, 罗勇刚(Yonggang Luo) wrote:
> 

>> +  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.


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
diff mbox series

Patch

diff --git a/meson.build b/meson.build
index 05fb59a00b..d1155aea65 100644
--- a/meson.build
+++ b/meson.build
@@ -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