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 )
18 SET(CURSES_USE_NCURSES FALSE)
20 IF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_LIBRARY)
21 SET(CURSES_USE_NCURSES TRUE)
22 ENDIF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_LIBRARY)
25 # Not sure the logic is correct here.
26 # If NCurses is required, use the function wsyncup() to check if the library
27 # has NCurses functionality (at least this is where it breaks on NetBSD).
28 # If wsyncup is in curses, use this one.
29 # If not, try to find ncurses and check if this has the symbol.
30 # Once the ncurses library is found, search the ncurses.h header first, but
31 # some web pages also say that even with ncurses there is not always a ncurses.h:
32 # http://osdir.com/ml/gnome.apps.mc.devel/2002-06/msg00029.html
33 # So at first try ncurses.h, if not found, try to find curses.h under the same
34 # prefix as the library was found, if still not found, try curses.h with the
35 # default search paths.
36 IF(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES)
37 INCLUDE(CheckLibraryExists)
38 CHECK_LIBRARY_EXISTS("${CURSES_CURSES_LIBRARY}"
39 wsyncup "" CURSES_CURSES_HAS_WSYNCUP)
41 IF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP)
42 CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}"
43 wsyncup "" CURSES_NCURSES_HAS_WSYNCUP)
44 IF( CURSES_NCURSES_HAS_WSYNCUP)
45 SET(CURSES_USE_NCURSES TRUE)
46 ENDIF( CURSES_NCURSES_HAS_WSYNCUP)
47 ENDIF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP)
49 ENDIF(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES)
52 IF(NOT CURSES_USE_NCURSES)
53 FIND_FILE(CURSES_HAVE_CURSES_H curses.h )
54 FIND_PATH(CURSES_CURSES_H_PATH curses.h )
55 GET_FILENAME_COMPONENT(_cursesLibDir "${CURSES_CURSES_LIBRARY}" PATH)
56 GET_FILENAME_COMPONENT(_cursesParentDir "${_cursesLibDir}" PATH)
58 # for compatibility with older FindCurses.cmake this has to be in the cache
59 # FORCE must not be used since this would break builds which preload a cache wqith these variables set
60 SET(CURSES_INCLUDE_PATH "${CURSES_CURSES_H_PATH}"
61 CACHE FILEPATH "The curses include path")
62 SET(CURSES_LIBRARY "${CURSES_CURSES_LIBRARY}"
63 CACHE FILEPATH "The curses library")
64 ELSE(NOT CURSES_USE_NCURSES)
65 # we need to find ncurses
66 GET_FILENAME_COMPONENT(_cursesLibDir "${CURSES_NCURSES_LIBRARY}" PATH)
67 GET_FILENAME_COMPONENT(_cursesParentDir "${_cursesLibDir}" PATH)
69 FIND_FILE(CURSES_HAVE_NCURSES_H ncurses.h)
70 FIND_FILE(CURSES_HAVE_NCURSES_NCURSES_H ncurses/ncurses.h)
71 FIND_FILE(CURSES_HAVE_NCURSES_CURSES_H ncurses/curses.h)
72 FIND_FILE(CURSES_HAVE_CURSES_H curses.h
73 HINTS "${_cursesParentDir}/include")
75 FIND_PATH(CURSES_NCURSES_INCLUDE_PATH ncurses.h ncurses/ncurses.h
77 FIND_PATH(CURSES_NCURSES_INCLUDE_PATH curses.h
78 HINTS "${_cursesParentDir}/include")
80 # for compatibility with older FindCurses.cmake this has to be in the cache
81 # FORCE must not be used since this would break builds which preload
82 # however if the value of the variable has NOTFOUND in it, then
83 # it is OK to force, and we need to force in order to have it work.
84 # a cache wqith these variables set
85 # only put ncurses include and library into
86 # variables if they are found
87 IF(NOT CURSES_NCURSES_INCLUDE_PATH AND CURSES_HAVE_NCURSES_NCURSES_H)
88 GET_FILENAME_COMPONENT(CURSES_NCURSES_INCLUDE_PATH
89 "${CURSES_HAVE_NCURSES_NCURSES_H}" PATH)
90 ENDIF(NOT CURSES_NCURSES_INCLUDE_PATH AND CURSES_HAVE_NCURSES_NCURSES_H)
91 IF(CURSES_NCURSES_INCLUDE_PATH AND CURSES_NCURSES_LIBRARY)
93 IF(CURSES_INCLUDE_PATH MATCHES NOTFOUND)
95 ENDIF(CURSES_INCLUDE_PATH MATCHES NOTFOUND)
96 SET(CURSES_INCLUDE_PATH "${CURSES_NCURSES_INCLUDE_PATH}"
97 CACHE FILEPATH "The curses include path" ${FORCE_IT})
99 IF(CURSES_LIBRARY MATCHES NOTFOUND)
101 ENDIF(CURSES_LIBRARY MATCHES NOTFOUND)
102 SET(CURSES_LIBRARY "${CURSES_NCURSES_LIBRARY}"
103 CACHE FILEPATH "The curses library" ${FORCE_IT})
104 ENDIF(CURSES_NCURSES_INCLUDE_PATH AND CURSES_NCURSES_LIBRARY)
106 ENDIF(NOT CURSES_USE_NCURSES)
108 FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr HINTS "${_cursesLibDir}")
109 FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr )
111 FIND_LIBRARY(CURSES_FORM_LIBRARY form HINTS "${_cursesLibDir}")
112 FIND_LIBRARY(CURSES_FORM_LIBRARY form )
114 # for compatibility with older FindCurses.cmake this has to be in the cache
115 # FORCE must not be used since this would break builds which preload a cache
116 # qith these variables set
117 SET(FORM_LIBRARY "${CURSES_FORM_LIBRARY}"
118 CACHE FILEPATH "The curses form library")
120 # Need to provide the *_LIBRARIES
121 SET(CURSES_LIBRARIES ${CURSES_LIBRARY})
123 IF(CURSES_EXTRA_LIBRARY)
124 SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY})
125 ENDIF(CURSES_EXTRA_LIBRARY)
127 IF(CURSES_FORM_LIBRARY)
128 SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY})
129 ENDIF(CURSES_FORM_LIBRARY)
131 # Proper name is *_INCLUDE_DIR
132 SET(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH})
134 # handle the QUIETLY and REQUIRED arguments and set CURSES_FOUND to TRUE if
135 # all listed variables are TRUE
136 INCLUDE(FindPackageHandleStandardArgs)
137 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Curses DEFAULT_MSG
138 CURSES_LIBRARY CURSES_INCLUDE_PATH)
143 CURSES_CURSES_INCLUDE_PATH
144 CURSES_CURSES_LIBRARY
145 CURSES_NCURSES_INCLUDE_PATH
146 CURSES_NCURSES_LIBRARY
151 CURSES_CURSES_HAS_WSYNCUP
152 CURSES_NCURSES_HAS_WSYNCUP