diff options
author | Manuel Argüelles <manuel.arguelles@gmail.com> | 2013-08-21 13:56:07 -0500 |
---|---|---|
committer | Manuel Argüelles <manuel.arguelles@gmail.com> | 2013-08-21 16:11:07 -0500 |
commit | d840e8a7430616bf96c164446f672d23b06cdfef (patch) | |
tree | 0ef6ef0657789a65b64feb98d6fbd0ac5cefe3ff /cmake | |
parent | c9a88607c21fabcb31c83271bd4c6f4b339275b7 (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.cmake | 179 |
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 | |||
18 | SET(CURSES_NEED_WIDE TRUE) | ||
19 | |||
20 | SET(CURSES_LIBRARY_NAME "curses") | ||
21 | SET(NCURSES_LIBRARY_NAME "ncurses") | ||
22 | IF(CURSES_NEED_WIDE) | ||
23 | MESSAGE( STATUS "Searching for wide character curses") | ||
24 | SET(CURSES_LIBRARY_NAME "cursesw") | ||
25 | SET(NCURSES_LIBRARY_NAME "ncursesw") | ||
26 | ENDIF(CURSES_NEED_WIDE) | ||
27 | |||
28 | FIND_LIBRARY(CURSES_CURSES_LIBRARY "${CURSES_LIBRARY_NAME}") | ||
29 | # MESSAGE(STATUS "CURSES! " ${CURSES_CURSES_LIBRARY}) | ||
30 | |||
31 | FIND_LIBRARY(CURSES_NCURSES_LIBRARY "${NCURSES_LIBRARY_NAME}") | ||
32 | # MESSAGE(STATUS "NCURSES! " ${CURSES_NCURSES_LIBRARY}) | ||
33 | |||
34 | SET(CURSES_USE_NCURSES FALSE) | ||
35 | |||
36 | IF(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_LIBRARY) | ||
37 | SET(CURSES_USE_NCURSES TRUE) | ||
38 | ENDIF(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. | ||
52 | IF(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 | |||
65 | ENDIF(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES) | ||
66 | |||
67 | |||
68 | IF(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") | ||
82 | ELSE(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 | |||
114 | ENDIF(NOT CURSES_USE_NCURSES) | ||
115 | |||
116 | |||
117 | |||
118 | FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr HINTS "${_cursesLibDir}") | ||
119 | FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr ) | ||
120 | |||
121 | SET(CURSES_FORM_LIBRARY_NAME "form") | ||
122 | IF(CURSES_NEED_WIDE) | ||
123 | SET(CURSES_FORM_LIBRARY_NAME "formw") | ||
124 | ENDIF(CURSES_NEED_WIDE) | ||
125 | |||
126 | FIND_LIBRARY(CURSES_CURSES_LIBRARY "${CURSES_LIBRARY_NAME}") | ||
127 | FIND_LIBRARY(CURSES_FORM_LIBRARY "${CURSES_FORM_LIBRARY_NAME}" HINTS "${_cursesLibDir}") | ||
128 | FIND_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 | ||
133 | SET(FORM_LIBRARY "${CURSES_FORM_LIBRARY}" | ||
134 | CACHE FILEPATH "The curses form library") | ||
135 | |||
136 | # Need to provide the *_LIBRARIES | ||
137 | SET(CURSES_LIBRARIES ${CURSES_LIBRARY}) | ||
138 | |||
139 | IF(CURSES_EXTRA_LIBRARY) | ||
140 | SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY}) | ||
141 | ENDIF(CURSES_EXTRA_LIBRARY) | ||
142 | |||
143 | IF(CURSES_FORM_LIBRARY) | ||
144 | SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY}) | ||
145 | ENDIF(CURSES_FORM_LIBRARY) | ||
146 | |||
147 | # Proper name is *_INCLUDE_DIR | ||
148 | SET(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 | ||
152 | INCLUDE(FindPackageHandleStandardArgs) | ||
153 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Curses DEFAULT_MSG | ||
154 | CURSES_LIBRARY CURSES_INCLUDE_PATH) | ||
155 | |||
156 | MARK_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 | |||