1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
8 Find the curses or ncurses include file and library.
13 This module defines the following variables:
16 True if Curses is found.
17 ``CURSES_INCLUDE_DIRS``
18 The include directories needed to use Curses.
20 The libraries needed to use Curses.
22 .. versionadded:: 3.16
24 Parameters which ought be given to C/C++ compilers when using Curses.
25 ``CURSES_HAVE_CURSES_H``
26 True if curses.h is available.
27 ``CURSES_HAVE_NCURSES_H``
28 True if ncurses.h is available.
29 ``CURSES_HAVE_NCURSES_NCURSES_H``
30 True if ``ncurses/ncurses.h`` is available.
31 ``CURSES_HAVE_NCURSES_CURSES_H``
32 True if ``ncurses/curses.h`` is available.
34 Set ``CURSES_NEED_NCURSES`` to ``TRUE`` before the
35 ``find_package(Curses)`` call if NCurses functionality is required.
37 .. versionadded:: 3.10
38 Set ``CURSES_NEED_WIDE`` to ``TRUE`` before the
39 ``find_package(Curses)`` call if unicode functionality is required.
41 Backward Compatibility
42 ^^^^^^^^^^^^^^^^^^^^^^
44 The following variable are provided for backward compatibility:
46 ``CURSES_INCLUDE_DIR``
47 Path to Curses include. Use ``CURSES_INCLUDE_DIRS`` instead.
49 Path to Curses library. Use ``CURSES_LIBRARIES`` instead.
50 #]=======================================================================]
52 include(${CMAKE_CURRENT_LIST_DIR}/CheckLibraryExists.cmake)
54 # we don't know anything about cursesw, so only ncurses
56 if(NOT CURSES_NEED_WIDE)
57 set(NCURSES_LIBRARY_NAME "ncurses")
58 set(CURSES_FORM_LIBRARY_NAME "form")
60 set(NCURSES_LIBRARY_NAME "ncursesw")
61 set(CURSES_FORM_LIBRARY_NAME "formw")
62 # Also, if we are searching for wide curses - we are actually searching
63 # for ncurses, we don't know about any other unicode version.
64 set(CURSES_NEED_NCURSES TRUE)
67 find_library(CURSES_CURSES_LIBRARY NAMES curses)
69 find_library(CURSES_NCURSES_LIBRARY NAMES "${NCURSES_LIBRARY_NAME}" )
70 set(CURSES_USE_NCURSES FALSE)
72 if(CURSES_NCURSES_LIBRARY AND ((NOT CURSES_CURSES_LIBRARY) OR CURSES_NEED_NCURSES))
73 set(CURSES_USE_NCURSES TRUE)
75 # http://cygwin.com/ml/cygwin-announce/2010-01/msg00002.html
76 # cygwin ncurses stopped providing curses.h symlinks see above
77 # message. Cygwin is an ncurses package, so force ncurses on
78 # cygwin if the curses.h is missing
79 if(CURSES_NCURSES_LIBRARY AND CYGWIN)
81 if(NOT EXISTS /usr/include/ncursesw/curses.h)
82 set(CURSES_USE_NCURSES TRUE)
85 if(NOT EXISTS /usr/include/curses.h)
86 set(CURSES_USE_NCURSES TRUE)
92 # Not sure the logic is correct here.
93 # If NCurses is required, use the function wsyncup() to check if the library
94 # has NCurses functionality (at least this is where it breaks on NetBSD).
95 # If wsyncup is in curses, use this one.
96 # If not, try to find ncurses and check if this has the symbol.
97 # Once the ncurses library is found, search the ncurses.h header first, but
98 # some web pages also say that even with ncurses there is not always a ncurses.h:
99 # http://osdir.com/ml/gnome.apps.mc.devel/2002-06/msg00029.html
100 # So at first try ncurses.h, if not found, try to find curses.h under the same
101 # prefix as the library was found, if still not found, try curses.h with the
102 # default search paths.
103 if(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES)
104 include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
105 cmake_push_check_state()
106 set(CMAKE_REQUIRED_QUIET ${Curses_FIND_QUIETLY})
107 CHECK_LIBRARY_EXISTS("${CURSES_CURSES_LIBRARY}"
108 wsyncup "" CURSES_CURSES_HAS_WSYNCUP)
110 if(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP)
111 CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}"
112 wsyncup "" CURSES_NCURSES_HAS_WSYNCUP)
113 if( CURSES_NCURSES_HAS_WSYNCUP)
114 set(CURSES_USE_NCURSES TRUE)
117 cmake_pop_check_state()
121 if(CURSES_USE_NCURSES)
122 get_filename_component(_cursesLibDir "${CURSES_NCURSES_LIBRARY}" PATH)
123 get_filename_component(_cursesParentDir "${_cursesLibDir}" PATH)
125 # Use CURSES_NCURSES_INCLUDE_PATH if set, for compatibility.
126 if(CURSES_NCURSES_INCLUDE_PATH)
127 if (CURSES_NEED_WIDE)
128 find_path(CURSES_INCLUDE_PATH
129 NAMES ncursesw/ncurses.h ncursesw/curses.h ncursesw.h cursesw.h
130 PATHS ${CURSES_NCURSES_INCLUDE_PATH}
134 find_path(CURSES_INCLUDE_PATH
135 NAMES ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h
136 PATHS ${CURSES_NCURSES_INCLUDE_PATH}
142 if (CURSES_NEED_WIDE)
143 set(CURSES_TINFO_LIBRARY_NAME tinfow)
144 find_path(CURSES_INCLUDE_PATH
145 NAMES ncursesw/ncurses.h ncursesw/curses.h ncursesw.h cursesw.h
146 HINTS "${_cursesParentDir}/include"
149 set(CURSES_TINFO_LIBRARY_NAME tinfo)
150 find_path(CURSES_INCLUDE_PATH
151 NAMES ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h
152 HINTS "${_cursesParentDir}/include"
156 # Previous versions of FindCurses provided these values.
157 if(NOT DEFINED CURSES_LIBRARY)
158 set(CURSES_LIBRARY "${CURSES_NCURSES_LIBRARY}")
161 CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}"
162 cbreak "" CURSES_NCURSES_HAS_CBREAK)
163 CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}"
164 nodelay "" CURSES_NCURSES_HAS_NODELAY)
165 if(NOT CURSES_NCURSES_HAS_CBREAK OR NOT CURSES_NCURSES_HAS_NODELAY)
166 find_library(CURSES_EXTRA_LIBRARY "${CURSES_TINFO_LIBRARY_NAME}" HINTS "${_cursesLibDir}")
167 find_library(CURSES_EXTRA_LIBRARY "${CURSES_TINFO_LIBRARY_NAME}" )
174 get_filename_component(_cursesLibDir "${CURSES_CURSES_LIBRARY}" PATH)
175 get_filename_component(_cursesParentDir "${_cursesLibDir}" PATH)
177 #We can't find anything with CURSES_NEED_WIDE because we know
178 #only about ncursesw unicode curses version
179 if(NOT CURSES_NEED_WIDE)
180 find_path(CURSES_INCLUDE_PATH
182 HINTS "${_cursesParentDir}/include"
186 # Previous versions of FindCurses provided these values.
187 if(NOT DEFINED CURSES_CURSES_H_PATH)
188 set(CURSES_CURSES_H_PATH "${CURSES_INCLUDE_PATH}")
190 if(NOT DEFINED CURSES_LIBRARY)
191 set(CURSES_LIBRARY "${CURSES_CURSES_LIBRARY}")
195 # Report whether each possible header name exists in the include directory.
196 if(NOT DEFINED CURSES_HAVE_NCURSES_NCURSES_H)
198 if(EXISTS "${CURSES_INCLUDE_PATH}/ncursesw/ncurses.h")
199 set(CURSES_HAVE_NCURSES_NCURSES_H "${CURSES_INCLUDE_PATH}/ncursesw/ncurses.h")
201 elseif(EXISTS "${CURSES_INCLUDE_PATH}/ncurses/ncurses.h")
202 set(CURSES_HAVE_NCURSES_NCURSES_H "${CURSES_INCLUDE_PATH}/ncurses/ncurses.h")
204 if(NOT DEFINED CURSES_HAVE_NCURSES_NCURSES_H)
205 set(CURSES_HAVE_NCURSES_NCURSES_H "CURSES_HAVE_NCURSES_NCURSES_H-NOTFOUND")
208 if(NOT DEFINED CURSES_HAVE_NCURSES_CURSES_H)
210 if(EXISTS "${CURSES_INCLUDE_PATH}/ncursesw/curses.h")
211 set(CURSES_HAVE_NCURSES_CURSES_H "${CURSES_INCLUDE_PATH}/ncursesw/curses.h")
213 elseif(EXISTS "${CURSES_INCLUDE_PATH}/ncurses/curses.h")
214 set(CURSES_HAVE_NCURSES_CURSES_H "${CURSES_INCLUDE_PATH}/ncurses/curses.h")
216 if(NOT DEFINED CURSES_HAVE_NCURSES_CURSES_H)
217 set(CURSES_HAVE_NCURSES_CURSES_H "CURSES_HAVE_NCURSES_CURSES_H-NOTFOUND")
220 if(NOT CURSES_NEED_WIDE)
221 #ncursesw can't be found for this paths
222 if(NOT DEFINED CURSES_HAVE_NCURSES_H)
223 if(EXISTS "${CURSES_INCLUDE_PATH}/ncurses.h")
224 set(CURSES_HAVE_NCURSES_H "${CURSES_INCLUDE_PATH}/ncurses.h")
226 set(CURSES_HAVE_NCURSES_H "CURSES_HAVE_NCURSES_H-NOTFOUND")
229 if(NOT DEFINED CURSES_HAVE_CURSES_H)
230 if(EXISTS "${CURSES_INCLUDE_PATH}/curses.h")
231 set(CURSES_HAVE_CURSES_H "${CURSES_INCLUDE_PATH}/curses.h")
233 set(CURSES_HAVE_CURSES_H "CURSES_HAVE_CURSES_H-NOTFOUND")
238 find_library(CURSES_FORM_LIBRARY "${CURSES_FORM_LIBRARY_NAME}" HINTS "${_cursesLibDir}")
239 find_library(CURSES_FORM_LIBRARY "${CURSES_FORM_LIBRARY_NAME}" )
241 # Previous versions of FindCurses provided these values.
242 if(NOT DEFINED FORM_LIBRARY)
243 set(FORM_LIBRARY "${CURSES_FORM_LIBRARY}")
246 # Need to provide the *_LIBRARIES
247 set(CURSES_LIBRARIES ${CURSES_LIBRARY})
249 if(CURSES_EXTRA_LIBRARY)
250 set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY})
253 if(CURSES_FORM_LIBRARY)
254 set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY})
257 # Provide the *_INCLUDE_DIRS and *_CFLAGS results.
258 set(CURSES_INCLUDE_DIRS ${CURSES_INCLUDE_PATH})
259 set(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH}) # compatibility
261 find_package(PkgConfig QUIET)
263 pkg_check_modules(NCURSES QUIET ${NCURSES_LIBRARY_NAME})
264 set(CURSES_CFLAGS ${NCURSES_CFLAGS_OTHER})
267 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
268 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Curses DEFAULT_MSG
269 CURSES_LIBRARY CURSES_INCLUDE_PATH)
273 CURSES_CURSES_LIBRARY
274 CURSES_NCURSES_LIBRARY