From 4ddb9ccbf3223c0393bfc61781a322a45a21aa34 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Mon, 28 Oct 2024 19:25:07 +0800 Subject: [PATCH] build: Add a test for whether curses.h works. The main thing I intended to test is "stdscr", but it is also useful to test ncurses functions that might be implemented as macros, such as refresh() and mvadd_wchnstr(). Signed-off-by: Kang-Che Sung --- ProvideCurses.h | 4 ++++ configure.ac | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/ProvideCurses.h b/ProvideCurses.h index 7ae99e620..4594e3baf 100644 --- a/ProvideCurses.h +++ b/ProvideCurses.h @@ -8,7 +8,11 @@ in the source distribution for its full text. */ +// This header is also used in tests by configure, thus conditionally +// including "config.h". +#if defined(HAVE_CONFIG_H) #include "config.h" // IWYU pragma: keep +#endif // IWYU pragma: begin_exports diff --git a/configure.ac b/configure.ac index 9c8b1d1b7..6a7926dee 100644 --- a/configure.ac +++ b/configure.ac @@ -666,6 +666,7 @@ esac htop_save_CFLAGS=$CFLAGS CFLAGS="$AM_CFLAGS $CFLAGS" + if test "x$enable_unicode" = xyes; then AC_CHECK_HEADERS([ncursesw/curses.h], [], [AC_CHECK_HEADERS([ncurses/ncurses.h], [], @@ -688,6 +689,31 @@ else [AC_CHECK_HEADERS([term.h], [], [AC_MSG_ERROR([can not find required term header file])])]) fi + +CFLAGS="-I$srcdir $CFLAGS" + +# Check for things that might be macros. +# "stdscr" is a macro in ncursest (reentrant version of ncurses). +AC_MSG_CHECKING([whether the curses header works]) +AC_LINK_IFELSE([AC_LANG_PROGRAM([[ +#include "ProvideCurses.h" + ]], [[ +keypad(stdscr, 0); + +refresh(); + +#if defined(HAVE_LIBNCURSESW) +{ + static cchar_t dummy; + mvadd_wchnstr(0, 0, &dummy, 0); +} +#endif + ]])], + [AC_MSG_RESULT(yes)], + [AC_MSG_RESULT(no) + AC_MSG_FAILURE([there are problems with the curses header])] +) + CFLAGS=$htop_save_CFLAGS if test "$enable_static" = yes; then