summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorManuel Argüelles <manuel.arguelles@gmail.com>2013-08-21 13:56:07 -0500
committerManuel Argüelles <manuel.arguelles@gmail.com>2013-08-21 16:11:07 -0500
commitd840e8a7430616bf96c164446f672d23b06cdfef (patch)
tree0ef6ef0657789a65b64feb98d6fbd0ac5cefe3ff /cmake
parentc9a88607c21fabcb31c83271bd4c6f4b339275b7 (diff)
Add cmake module for ncursesw
Default Curses module fails to detect the wide char version of curses when both are installed. Current module should do better.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/FindCursesw.cmake179
1 files changed, 179 insertions, 0 deletions
diff --git a/cmake/FindCursesw.cmake b/cmake/FindCursesw.cmake
new file mode 100644
index 00000000..60f01f39
--- /dev/null
+++ b/cmake/FindCursesw.cmake
@@ -0,0 +1,179 @@
1# - Find the curses include file and library
2#
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
11#
12# Set CURSES_NEED_NCURSES to TRUE before the FIND_PACKAGE() command if NCurses
13# functionality is required.
14
15# Set CURSES_NEED_WIDE to TRUE before the FIND_PACKAGE() command if unicode
16# functionality is required
17
18SET(CURSES_NEED_WIDE TRUE)
19
20SET(CURSES_LIBRARY_NAME "curses")
21SET(NCURSES_LIBRARY_NAME "ncurses")
22IF(CURSES_NEED_WIDE)
23 MESSAGE( STATUS "Searching for wide character curses")
24 SET(CURSES_LIBRARY_NAME "cursesw")
25 SET(NCURSES_LIBRARY_NAME "ncursesw")
26ENDIF(CURSES_NEED_WIDE)
27
28FIND_LIBRARY(CURSES_CURSES_LIBRARY "${CURSES_LIBRARY_NAME}")
29# MESSAGE(STATUS "CURSES! " ${CURSES_CURSES_LIBRARY})
30
31FIND_LIBRARY(CURSES_NCURSES_LIBRARY "${NCURSES_LIBRARY_NAME}")
32# MESSAGE(STATUS "NCURSES! " ${CURSES_NCURSES_LIBRARY})
33
34SET(CURSES_USE_NCURSES FALSE)
35
36IF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_LIBRARY)
37 SET(CURSES_USE_NCURSES TRUE)
38ENDIF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_LIBRARY)
39
40
41# Not sure the logic is correct here.
42# If NCurses is required, use the function wsyncup() to check if the library
43# has NCurses functionality (at least this is where it breaks on NetBSD).
44# If wsyncup is in curses, use this one.
45# If not, try to find ncurses and check if this has the symbol.
46# Once the ncurses library is found, search the ncurses.h header first, but
47# some web pages also say that even with ncurses there is not always a ncurses.h:
48# http://osdir.com/ml/gnome.apps.mc.devel/2002-06/msg00029.html
49# So at first try ncurses.h, if not found, try to find curses.h under the same
50# prefix as the library was found, if still not found, try curses.h with the
51# default search paths.
52IF(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES)
53 INCLUDE(CheckLibraryExists)
54 CHECK_LIBRARY_EXISTS("${CURSES_CURSES_LIBRARY}"
55 wsyncup "" CURSES_CURSES_HAS_WSYNCUP)
56
57 IF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP)
58 CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}"
59 wsyncup "" CURSES_NCURSES_HAS_WSYNCUP)
60 IF( CURSES_NCURSES_HAS_WSYNCUP)
61 SET(CURSES_USE_NCURSES TRUE)
62 ENDIF( CURSES_NCURSES_HAS_WSYNCUP)
63 ENDIF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP)
64
65ENDIF(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES)
66
67
68IF(NOT CURSES_USE_NCURSES)
69 FIND_FILE(CURSES_HAVE_CURSES_H curses.h )
70 FIND_FILE(CURSES_HAVE_CURSESW_H cursesw.h )
71 FIND_PATH(CURSES_CURSES_H_PATH curses.h )
72 FIND_PATH(CURSES_CURSESW_H_PATH cursesw.h )
73 GET_FILENAME_COMPONENT(_cursesLibDir "${CURSES_CURSES_LIBRARY}" PATH)
74 GET_FILENAME_COMPONENT(_cursesParentDir "${_cursesLibDir}" PATH)
75
76 # for compatibility with older FindCurses.cmake this has to be in the cache
77 # FORCE must not be used since this would break builds which preload a cache wqith these variables set
78 SET(CURSES_INCLUDE_PATH "${CURSES_CURSES_H_PATH} ${CURSES_CURSESW_H_PATH}"
79 CACHE FILEPATH "The curses include path")
80 SET(CURSES_LIBRARY "${CURSES_CURSES_LIBRARY}"
81 CACHE FILEPATH "The curses library")
82ELSE(NOT CURSES_USE_NCURSES)
83# we need to find ncurses
84 GET_FILENAME_COMPONENT(_cursesLibDir "${CURSES_NCURSES_LIBRARY}" PATH)
85 GET_FILENAME_COMPONENT(_cursesParentDir "${_cursesLibDir}" PATH)
86
87 FIND_FILE(CURSES_HAVE_NCURSES_H ncurses.h)
88 FIND_FILE(CURSES_HAVE_NCURSES_NCURSES_H ncurses/ncurses.h)
89 FIND_FILE(CURSES_HAVE_NCURSES_CURSES_H ncurses/curses.h)
90 FIND_FILE(CURSES_HAVE_CURSES_H curses.h
91 HINTS "${_cursesParentDir}/include")
92
93 FIND_FILE(CURSES_HAVE_NCURSESW_H ncursesw.h)
94 FIND_FILE(CURSES_HAVE_NCURSESW_NCURSES_H ncursesw/ncurses.h)
95 FIND_FILE(CURSES_HAVE_NCURSESW_CURSES_H ncursesw/curses.h)
96 FIND_FILE(CURSES_HAVE_CURSESW_H cursesw.h
97 HINTS "${_cursesParentDir}/include")
98
99 FIND_PATH(CURSES_NCURSES_INCLUDE_PATH curses.h PATH_SUFFIXES ncursesw)
100
101 # for compatibility with older FindCurses.cmake this has to be in the cache
102 # FORCE must not be used since this would break builds which preload
103 # a cache wqith these variables set
104 # only put ncurses include and library into
105 # variables if they are found
106 IF(CURSES_NCURSES_INCLUDE_PATH AND CURSES_NCURSES_LIBRARY)
107
108 SET(CURSES_INCLUDE_PATH "${CURSES_NCURSES_INCLUDE_PATH} ${CURSES_NCURSESW_INCLUDE_PATH}"
109 CACHE FILEPATH "The curses include path")
110 SET(CURSES_LIBRARY "${CURSES_NCURSES_LIBRARY}"
111 CACHE FILEPATH "The curses library")
112 ENDIF(CURSES_NCURSES_INCLUDE_PATH AND CURSES_NCURSES_LIBRARY)
113
114ENDIF(NOT CURSES_USE_NCURSES)
115
116
117
118FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr HINTS "${_cursesLibDir}")
119FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr )
120
121SET(CURSES_FORM_LIBRARY_NAME "form")
122IF(CURSES_NEED_WIDE)
123 SET(CURSES_FORM_LIBRARY_NAME "formw")
124ENDIF(CURSES_NEED_WIDE)
125
126FIND_LIBRARY(CURSES_CURSES_LIBRARY "${CURSES_LIBRARY_NAME}")
127FIND_LIBRARY(CURSES_FORM_LIBRARY "${CURSES_FORM_LIBRARY_NAME}" HINTS "${_cursesLibDir}")
128FIND_LIBRARY(CURSES_FORM_LIBRARY "${CURSES_FORM_LIBRARY_NAME}" )
129
130# for compatibility with older FindCurses.cmake this has to be in the cache
131# FORCE must not be used since this would break builds which preload a cache
132# qith these variables set
133SET(FORM_LIBRARY "${CURSES_FORM_LIBRARY}"
134 CACHE FILEPATH "The curses form library")
135
136# Need to provide the *_LIBRARIES
137SET(CURSES_LIBRARIES ${CURSES_LIBRARY})
138
139IF(CURSES_EXTRA_LIBRARY)
140 SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY})
141ENDIF(CURSES_EXTRA_LIBRARY)
142
143IF(CURSES_FORM_LIBRARY)
144 SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY})
145ENDIF(CURSES_FORM_LIBRARY)
146
147# Proper name is *_INCLUDE_DIR
148SET(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH})
149
150# handle the QUIETLY and REQUIRED arguments and set CURSES_FOUND to TRUE if
151# all listed variables are TRUE
152INCLUDE(FindPackageHandleStandardArgs)
153FIND_PACKAGE_HANDLE_STANDARD_ARGS(Curses DEFAULT_MSG
154 CURSES_LIBRARY CURSES_INCLUDE_PATH)
155
156MARK_AS_ADVANCED(
157 CURSES_INCLUDE_PATH
158 CURSES_LIBRARY
159 CURSES_CURSES_INCLUDE_PATH
160 CURSES_CURSES_LIBRARY
161 CURSES_NCURSES_INCLUDE_PATH
162 CURSES_NCURSES_LIBRARY
163 CURSES_EXTRA_LIBRARY
164 FORM_LIBRARY
165 CURSES_FORM_LIBRARY
166 CURSES_LIBRARIES
167 CURSES_INCLUDE_DIR
168 CURSES_CURSES_HAS_WSYNCUP
169 CURSES_NCURSES_HAS_WSYNCUP
170 CURSES_HAVE_CURSESW_H
171 CURSES_HAVE_CURSES_H
172 CURSES_HAVE_NCURSESW_CURSES_H
173 CURSES_HAVE_NCURSESW_H
174 CURSES_HAVE_NCURSESW_NCURSES_H
175 CURSES_HAVE_NCURSES_CURSES_H
176 CURSES_HAVE_NCURSES_H
177 CURSES_HAVE_NCURSES_NCURSES_H
178 )
179