Skip to content

Commit

Permalink
Try harder to select ncurses if possible.
Browse files Browse the repository at this point in the history
Issue #19 reports that cmake's FindCurses doesn't do this in all
situations: an example is if you've set CMAKE_SYSTEM_PREFIX_PATH to
point to a location containing libncurses, then FindCurses will choose
the plain libcurses from the standard system directories in preference
to the extra featureful libncurses from the path you configured. But
we do want ncurses if we can get it.

The documentation for FindCurses says:

  Set CURSES_NEED_NCURSES to TRUE before the find_package(Curses) call
  if NCurses functionality is required.

which sounds as if it will cause a build failure if only vanilla
curses is available. So I've been cautious: we try to find a curses
library with that flag set, and then if that fails, fall back to
trying again without. That way we should get _some_ curses library if
cmake can find one at all, but prefer ncurses if one of those is
available.

(I'm not convinced that CURSES_NEED_NCURSES actually does this - in my
own testing, it appears to behave more like 'prefer ncurses' than
'fail if you don't get ncurses'. But given its documentation, that
might be accidental, and might get fixed in future. So I think what
I've done here is still the safer approach.)
  • Loading branch information
statham-arm committed Jul 26, 2024
1 parent fd7e9a3 commit 5444331
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmake/unix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@
# dependencies to be installed centrally by a package manager, so we
# can just run find_package in the obvious way.

find_package(Curses ${REQUIRED_PACKAGE})
# We'd rather use ncurses than vanilla curses, if we can get it. But
# we're happy to use vanilla curses if that's all that's available. So
# we set CURSES_NEED_NCURSES, and if that fails, try again without it.
set(CURSES_NEED_NCURSES TRUE)
find_package(Curses)
if(NOT CURSES_FOUND)
set(CURSES_NEED_NCURSES FALSE)
find_package(Curses ${REQUIRED_PACKAGE})
endif()

find_package(PkgConfig ${REQUIRED_PACKAGE})

include(GNUInstallDirs)
Expand Down

0 comments on commit 5444331

Please sign in to comment.