Skip to content

Commit

Permalink
Fix accidental ncurses dependence on Unix.
Browse files Browse the repository at this point in the history
This should allow tarmac-browser to build on a Unix system which has a
curses library that is not ncurses. Previously it would have failed
when browser/curses.cpp tried to `#include <ncurses.h>` and didn't
find it.

The curses-based browser was always intended to work with vanilla
curses, not just ncurses. (Proof: it compiles against pdcurses on
Windows.) So it _should_ work with any curses library that cmake's
FindCurses module can put its hands on. But I hard-coded the directive
`#include <ncurses.h>` in the source file long before I wrote this
cmake setup, and was ignoring the variables retured by FindCurses that
says which curses header file name it found.

Now we use those variables, instead of the OS type, to decide which
header to include. Therefore I also have to manually define one of
them for the pdcurses Windows build, which doesn't run cmake's
FindCurses at all.
  • Loading branch information
statham-arm committed Jul 19, 2024
1 parent 6969ad9 commit 9a9cf4c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions browser/curses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@
#include <string>
#include <vector>

#ifdef WIN32
#include <curses.h>
#else
#if CURSES_HAVE_NCURSES_H
#include <ncurses.h>
#elif CURSES_HAVE_NCURSES_NCURSES_H
#include <ncurses/ncurses.h>
#elif CURSES_HAVE_NCURSES_CURSES_H
#include <ncurses/curses.h>
#elif CURSES_HAVE_CURSES_H
#include <curses.h>
#endif

using std::invalid_argument;
Expand Down
4 changes: 4 additions & 0 deletions cmake/cmake.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#cmakedefine01 HAVE_APPDATAPROGRAMDATA
#cmakedefine01 HAVE_LIBINTL
#cmakedefine01 HAVE_WCSWIDTH
#cmakedefine01 CURSES_HAVE_CURSES_H
#cmakedefine01 CURSES_HAVE_NCURSES_H
#cmakedefine01 CURSES_HAVE_NCURSES_NCURSES_H
#cmakedefine01 CURSES_HAVE_NCURSES_CURSES_H

#if HAVE_LIBINTL
#define PACKAGE "@PROJECT_NAME@"
Expand Down
1 change: 1 addition & 0 deletions cmake/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if(DEFINED PDCURSES_ROOT)
set_target_properties(pdcurses PROPERTIES
IMPORTED_LOCATION ${PDCURSES_BUILD_DIR}/pdcurses.lib)
set(CURSES_LIBRARIES pdcurses)
set(CURSES_HAVE_CURSES_H ON)
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
Expand Down

0 comments on commit 9a9cf4c

Please sign in to comment.