diff mbox series

meson.build: Support ncurses on MacOS

Message ID 20210612080358.61176-1-sw@weilnetz.de (mailing list archive)
State New, archived
Headers show
Series meson.build: Support ncurses on MacOS | expand

Commit Message

Stefan Weil June 12, 2021, 8:03 a.m. UTC
MacOS provides header files for curses 5.7 with support
for wide characters, but requires _XOPEN_SOURCE_EXTENDED=1
to activate that.

By default those old header files are used even if there
is a newer Homebrew installation of ncurses 6.2 available.

Change also the old macro definition of NCURSES_WIDECHAR
and set it to 1 like it is done in newer versions of
curses.h when _XOPEN_SOURCE_EXTENDED=1 is defined.

Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 meson.build | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Brad Smith June 13, 2021, 1:40 a.m. UTC | #1
This same problem also applies to OpenBSD as we have the same
version of ncurses with support for wide characters. I have a similar
patch in our QEMU port.

On 6/12/2021 4:03 AM, Stefan Weil wrote:
> MacOS provides header files for curses 5.7 with support
> for wide characters, but requires _XOPEN_SOURCE_EXTENDED=1
> to activate that.
>
> By default those old header files are used even if there
> is a newer Homebrew installation of ncurses 6.2 available.
>
> Change also the old macro definition of NCURSES_WIDECHAR
> and set it to 1 like it is done in newer versions of
> curses.h when _XOPEN_SOURCE_EXTENDED=1 is defined.
>
> Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>   meson.build | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/meson.build b/meson.build
> index d2a9ce91f5..3ca8faa264 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -606,7 +606,11 @@ if have_system and not get_option('curses').disabled()
>       endif
>     endforeach
>     msg = get_option('curses').enabled() ? 'curses library not found' : ''
> -  curses_compile_args = ['-DNCURSES_WIDECHAR']
> +  if host_machine.system() == 'darwin'
> +    curses_compile_args = [ '-D_XOPEN_SOURCE_EXTENDED=1']
> +  else
> +    curses_compile_args = ['-DNCURSES_WIDECHAR=1']
> +  endif
>     if curses.found()
>       if cc.links(curses_test, args: curses_compile_args, dependencies: [curses])
>         curses = declare_dependency(compile_args: curses_compile_args, dependencies: [curses])
Stefan Weil June 13, 2021, 6:33 a.m. UTC | #2
Am 13.06.21 um 03:40 schrieb Brad Smith:

> This same problem also applies to OpenBSD as we have the same
> version of ncurses with support for wide characters. I have a similar
> patch in our QEMU port.


Then we should either extend the conditional statement to handle OpenBSD 
as well, or simply define both macros unconditionally:

     # Newer versions of curses use NCURSES_WIDECHAR.
     # Older versions (e. g. on MacOS, OpenBSD) still require 
_XOPEN_SOURCE_EXTENDED.
     curses_compile_args = ['-DNCURSES_WIDECHAR=1', 
'-D_XOPEN_SOURCE_EXTENDED=1']

Defining only _XOPEN_SOURCE_EXTENDED would also work with old and new 
versions, so that's another option.

Stefan
Philippe Mathieu-Daudé June 14, 2021, 5:45 a.m. UTC | #3
On 6/13/21 8:33 AM, Stefan Weil wrote:
> Am 13.06.21 um 03:40 schrieb Brad Smith:
> 
>> This same problem also applies to OpenBSD as we have the same
>> version of ncurses with support for wide characters. I have a similar
>> patch in our QEMU port.
> 
> 
> Then we should either extend the conditional statement to handle OpenBSD
> as well, or simply define both macros unconditionally:
> 
>     # Newer versions of curses use NCURSES_WIDECHAR.
>     # Older versions (e. g. on MacOS, OpenBSD) still require
> _XOPEN_SOURCE_EXTENDED.
>     curses_compile_args = ['-DNCURSES_WIDECHAR=1',
> '-D_XOPEN_SOURCE_EXTENDED=1']
> 
> Defining only _XOPEN_SOURCE_EXTENDED would also work with old and new
> versions, so that's another option.

It is simpler to ask Brad to upstream the OpenBSD patch :)
Brad Smith June 15, 2021, 1:53 a.m. UTC | #4
On 6/14/2021 1:45 AM, Philippe Mathieu-Daudé wrote:
> On 6/13/21 8:33 AM, Stefan Weil wrote:
>> Am 13.06.21 um 03:40 schrieb Brad Smith:
>>
>>> This same problem also applies to OpenBSD as we have the same
>>> version of ncurses with support for wide characters. I have a similar
>>> patch in our QEMU port.
>>
>> Then we should either extend the conditional statement to handle OpenBSD
>> as well, or simply define both macros unconditionally:
>>
>>      # Newer versions of curses use NCURSES_WIDECHAR.
>>      # Older versions (e. g. on MacOS, OpenBSD) still require
>> _XOPEN_SOURCE_EXTENDED.
>>      curses_compile_args = ['-DNCURSES_WIDECHAR=1',
>> '-D_XOPEN_SOURCE_EXTENDED=1']
>>
>> Defining only _XOPEN_SOURCE_EXTENDED would also work with old and new
>> versions, so that's another option.
> It is simpler to ask Brad to upstream the OpenBSD patch :)

That doesn't answer his question and that's the part that actually matters.
diff mbox series

Patch

diff --git a/meson.build b/meson.build
index d2a9ce91f5..3ca8faa264 100644
--- a/meson.build
+++ b/meson.build
@@ -606,7 +606,11 @@  if have_system and not get_option('curses').disabled()
     endif
   endforeach
   msg = get_option('curses').enabled() ? 'curses library not found' : ''
-  curses_compile_args = ['-DNCURSES_WIDECHAR']
+  if host_machine.system() == 'darwin'
+    curses_compile_args = [ '-D_XOPEN_SOURCE_EXTENDED=1']
+  else
+    curses_compile_args = ['-DNCURSES_WIDECHAR=1']
+  endif
   if curses.found()
     if cc.links(curses_test, args: curses_compile_args, dependencies: [curses])
       curses = declare_dependency(compile_args: curses_compile_args, dependencies: [curses])