1 # - Find the curses include file and library
3 # CURSES_FOUND - system has Curses
4 # CURSES_INCLUDE_DIR - the Curses include directory
5 # CURSES_LIBRARIES - The libraries needed to use Curses
6 # CURSES_HAVE_CURSES_H - true if curses.h is available
7 # CURSES_HAVE_NCURSES_H - true if ncurses.h is available
8 # CURSES_HAVE_NCURSES_NCURSES_H - true if ncurses/ncurses.h is available
9 # CURSES_HAVE_NCURSES_CURSES_H - true if ncurses/curses.h is available
10 # CURSES_LIBRARY - set for backwards compatibility with 2.4 CMake
12 # Set CURSES_NEED_NCURSES to TRUE before the FIND_PACKAGE() command if NCurses
13 # functionality is required.
15 FIND_LIBRARY(CURSES_CURSES_LIBRARY NAMES curses )
17 FIND_LIBRARY(CURSES_NCURSES_LIBRARY NAMES ncurses )
19 SET(CURSES_USE_NCURSES FALSE)
21 IF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_LIBRARY)
22 SET(CURSES_USE_NCURSES TRUE)
23 ENDIF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_LIBRARY)
26 # Not sure the logic is correct here.
27 # If NCurses is required, use the function wsyncup() to check if the library
28 # has NCurses functionality (at least this is where it breaks on NetBSD).
29 # If wsyncup is in curses, use this one.
30 # If not, try to find ncurses and check if this has the symbol.
31 # Once the ncurses library is found, search the ncurses.h header first, but
32 # some web pages also say that even with ncurses there is not always a ncurses.h:
33 # http://osdir.com/ml/gnome.apps.mc.devel/2002-06/msg00029.html
34 # So at first try ncurses.h, if not found, try to find curses.h under the same
35 # prefix as the library was found, if still not found, try curses.h with the
36 # default search paths.
37 IF(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES)
38 INCLUDE(CheckLibraryExists)
39 CHECK_LIBRARY_EXISTS("${CURSES_CURSES_LIBRARY}"
40 wsyncup "" CURSES_CURSES_HAS_WSYNCUP)
42 IF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP)
43 CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}"
44 wsyncup "" CURSES_NCURSES_HAS_WSYNCUP)
45 IF( CURSES_NCURSES_HAS_WSYNCUP)
46 SET(CURSES_USE_NCURSES TRUE)
47 ENDIF( CURSES_NCURSES_HAS_WSYNCUP)
48 ENDIF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP)
50 ENDIF(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES)
53 IF(NOT CURSES_USE_NCURSES)
54 FIND_FILE(CURSES_HAVE_CURSES_H curses.h )
55 FIND_PATH(CURSES_CURSES_H_PATH curses.h )
56 GET_FILENAME_COMPONENT(_cursesLibDir "${CURSES_CURSES_LIBRARY}" PATH)
57 GET_FILENAME_COMPONENT(_cursesParentDir "${_cursesLibDir}" PATH)
59 # for compatibility with older FindCurses.cmake this has to be in the cache
60 # FORCE must not be used since this would break builds which preload a cache wqith these variables set
61 SET(CURSES_INCLUDE_PATH "${CURSES_CURSES_H_PATH}"
62 CACHE FILEPATH "The curses include path")
63 SET(CURSES_LIBRARY "${CURSES_CURSES_LIBRARY}"
64 CACHE FILEPATH "The curses library")
65 ELSE(NOT CURSES_USE_NCURSES)
66 # we need to find ncurses
67 GET_FILENAME_COMPONENT(_cursesLibDir "${CURSES_NCURSES_LIBRARY}" PATH)
68 GET_FILENAME_COMPONENT(_cursesParentDir "${_cursesLibDir}" PATH)
70 FIND_FILE(CURSES_HAVE_NCURSES_H ncurses.h)
71 FIND_FILE(CURSES_HAVE_NCURSES_NCURSES_H ncurses/ncurses.h)
72 FIND_FILE(CURSES_HAVE_NCURSES_CURSES_H ncurses/curses.h)
73 FIND_FILE(CURSES_HAVE_CURSES_H curses.h
74 HINTS "${_cursesParentDir}/include")
76 FIND_PATH(CURSES_NCURSES_INCLUDE_PATH ncurses.h ncurses/ncurses.h
78 FIND_PATH(CURSES_NCURSES_INCLUDE_PATH curses.h
79 HINTS "${_cursesParentDir}/include")
81 # for compatibility with older FindCurses.cmake this has to be in the cache
82 # FORCE must not be used since this would break builds which preload
83 # a cache wqith these variables set
84 # only put ncurses include and library into
85 # variables if they are found
86 IF(CURSES_NCURSES_INCLUDE_PATH AND CURSES_NCURSES_LIBRARY)
88 SET(CURSES_INCLUDE_PATH "${CURSES_NCURSES_INCLUDE_PATH}"
89 CACHE FILEPATH "The curses include path")
90 SET(CURSES_LIBRARY "${CURSES_NCURSES_LIBRARY}"
91 CACHE FILEPATH "The curses library")
92 ENDIF(CURSES_NCURSES_INCLUDE_PATH AND CURSES_NCURSES_LIBRARY)
94 ENDIF(NOT CURSES_USE_NCURSES)
98 FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr HINTS "${_cursesLibDir}")
99 FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr )
101 FIND_LIBRARY(CURSES_FORM_LIBRARY form HINTS "${_cursesLibDir}")
102 FIND_LIBRARY(CURSES_FORM_LIBRARY form )
104 # for compatibility with older FindCurses.cmake this has to be in the cache
105 # FORCE must not be used since this would break builds which preload a cache
106 # qith these variables set
107 SET(FORM_LIBRARY "${CURSES_FORM_LIBRARY}"
108 CACHE FILEPATH "The curses form library")
110 # Need to provide the *_LIBRARIES
111 SET(CURSES_LIBRARIES ${CURSES_LIBRARY})
113 IF(CURSES_EXTRA_LIBRARY)
114 SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY})
115 ENDIF(CURSES_EXTRA_LIBRARY)
117 IF(CURSES_FORM_LIBRARY)
118 SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY})
119 ENDIF(CURSES_FORM_LIBRARY)
121 # Proper name is *_INCLUDE_DIR
122 SET(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH})
124 # handle the QUIETLY and REQUIRED arguments and set CURSES_FOUND to TRUE if
125 # all listed variables are TRUE
126 INCLUDE(FindPackageHandleStandardArgs)
127 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Curses DEFAULT_MSG
128 CURSES_LIBRARY CURSES_INCLUDE_PATH)
133 CURSES_CURSES_INCLUDE_PATH
134 CURSES_CURSES_LIBRARY
135 CURSES_NCURSES_INCLUDE_PATH
136 CURSES_NCURSES_LIBRARY
141 CURSES_CURSES_HAS_WSYNCUP
142 CURSES_NCURSES_HAS_WSYNCUP