FindCurses: toplevel ncursesw support, recover cflags
This addresses, to the best of my knowledge, two problems with the current FindCurses module.
(1) On current Arch Linux running CMake 3.15.3 with ncurses 6.1.20180127, CURSES_NEED_WIDE defined to TRUE results in
find_package(Curses REQUIRED) failing due to an inability to find the header files. We need look for ncursesw.h and/or cursesw.h in the toplevel as well as in subdirectories if we want to support Arch's layout (which does, by the way, use
cursesw.h. This is independent of whether CURSES_NEED_NCURSES is defined (it gets set to TRUE anyway if CURSES_NEED_WIDE is in play).
(2) The ncurses documentation mentions the need for _XOPEN_EXTENDED and/or _DEFAULT_SOURCE to be defined (the exact requirements change depending on ncurses version). These are also present in
pkg-config --cflags output; here are Debian and Arch examples (I also show
[schwarzgerat](1) $ pkg-config --cflags ncursesw -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 [schwarzgerat](0) $ ncurses6-config --cflags -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 [schwarzgerat](0) $ [grimes](0) $ pkg-config --cflags ncursesw -D_GNU_SOURCE -D_DEFAULT_SOURCE [grimes](0) $ ncursesw6-config --cflags -D_GNU_SOURCE -D_DEFAULT_SOURCE [grimes](0) $
Since these change based on local installation decisions, ncurses version, and whether wide characters are supported, there's no really good way to discover them save running
pkg-config --cflags (
ncursesX-config --cflags doesn't seem much better, and requires specifying an ncurses major version). So that's what we do, exporting the new variable CURSES_CFLAGS. Capturing CURSES_CFLAGS, I see my program use the correct flags for all builds.
Now, if we're going to use
pkg-config, it seems maybe we ought bite the bullet and just use it for everything, but I've left things unchanged here.
This was discovered and worked out as part of https://github.com/dankamongmen/outcurses/issues/2.