diff options
author | Manuel Argüelles <manuel.arguelles@gmail.com> | 2013-08-22 15:57:34 -0500 |
---|---|---|
committer | Manuel Argüelles <manuel.arguelles@gmail.com> | 2013-08-22 15:57:34 -0500 |
commit | 7ffa4017aaec8a06c6677686a6928e0e7c896f38 (patch) | |
tree | 3694127a3481ada2c8656a4b15c4cd2defec82d9 /cmake | |
parent | 7719a9ed5807aede732230ad30bc31f536a0c4ae (diff) |
Make wide character support optional
Issue #514. FindCursesw modified to make it simpler. Wide character
can be disable by passing NO_WIDECHAR=ON.
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/FindCursesw.cmake | 196 |
1 files changed, 32 insertions, 164 deletions
diff --git a/cmake/FindCursesw.cmake b/cmake/FindCursesw.cmake index 60f01f39..bff02cec 100644 --- a/cmake/FindCursesw.cmake +++ b/cmake/FindCursesw.cmake | |||
@@ -1,179 +1,47 @@ | |||
1 | # - Find the curses include file and library | 1 | # - Find the curses include file and library |
2 | # | 2 | # |
3 | # CURSES_FOUND - system has Curses | ||
4 | # CURSES_INCLUDE_DIR - the Curses include directory | 3 | # CURSES_INCLUDE_DIR - the Curses include directory |
5 | # CURSES_LIBRARIES - The libraries needed to use Curses | 4 | # CURSES_LIBRARIES - The libraries needed to use Curses |
6 | # CURSES_HAVE_CURSES_H - true if curses.h is available | 5 | # CURSES_HAVE_WIDE_CHAR - true if wide char is available |
7 | # CURSES_HAVE_NCURSES_H - true if ncurses.h is available | 6 | # NO_WIDECHAR - Input variable, if set, disable wide char |
8 | # CURSES_HAVE_NCURSES_NCURSES_H - true if ncurses/ncurses.h is available | 7 | # ------------------------------------------------------------------------ |
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 | 8 | ||
118 | FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr HINTS "${_cursesLibDir}") | ||
119 | FIND_LIBRARY(CURSES_EXTRA_LIBRARY cur_colr ) | ||
120 | 9 | ||
121 | SET(CURSES_FORM_LIBRARY_NAME "form") | 10 | find_library(CURSES_LIBRARY "curses") |
122 | IF(CURSES_NEED_WIDE) | 11 | find_library(CURSESW_LIBRARY "cursesw") |
123 | SET(CURSES_FORM_LIBRARY_NAME "formw") | ||
124 | ENDIF(CURSES_NEED_WIDE) | ||
125 | 12 | ||
126 | FIND_LIBRARY(CURSES_CURSES_LIBRARY "${CURSES_LIBRARY_NAME}") | 13 | find_library(NCURSES_LIBRARY "ncurses") |
127 | FIND_LIBRARY(CURSES_FORM_LIBRARY "${CURSES_FORM_LIBRARY_NAME}" HINTS "${_cursesLibDir}") | 14 | find_library(NCURSESW_LIBRARY "ncursesw") |
128 | FIND_LIBRARY(CURSES_FORM_LIBRARY "${CURSES_FORM_LIBRARY_NAME}" ) | ||
129 | 15 | ||
130 | # for compatibility with older FindCurses.cmake this has to be in the cache | 16 | if(NOT NO_WIDECHAR AND (CURSESW_LIBRARY OR NCURSESW_LIBRARY)) |
131 | # FORCE must not be used since this would break builds which preload a cache | 17 | message(STATUS "Found wide character support") |
132 | # qith these variables set | 18 | set(CURSES_HAVE_WIDE_CHAR TRUE) |
133 | SET(FORM_LIBRARY "${CURSES_FORM_LIBRARY}" | 19 | if(NCURSESW_LIBRARY) |
134 | CACHE FILEPATH "The curses form library") | 20 | set(CURSES_LIBRARIES ${NCURSESW_LIBRARY}) |
21 | else() | ||
22 | set(CURSES_LIBRARIES ${CURSESW_LIBRARY}) | ||
23 | endif() | ||
24 | else() | ||
25 | message(STATUS "Could not found wide character support") | ||
26 | if(NCURSES_LIBRARY) | ||
27 | set(CURSES_LIBRARIES ${NCURSES_LIBRARY}) | ||
28 | else() | ||
29 | set(CURSES_LIBRARIES ${CURSES_LIBRARY}) | ||
30 | endif() | ||
31 | endif() | ||
135 | 32 | ||
136 | # Need to provide the *_LIBRARIES | ||
137 | SET(CURSES_LIBRARIES ${CURSES_LIBRARY}) | ||
138 | 33 | ||
139 | IF(CURSES_EXTRA_LIBRARY) | 34 | # We use curses.h not ncurses.h so let's not care about that for now |
140 | SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY}) | ||
141 | ENDIF(CURSES_EXTRA_LIBRARY) | ||
142 | 35 | ||
143 | IF(CURSES_FORM_LIBRARY) | 36 | if(CURSES_HAVE_WIDE_CHAR) |
144 | SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY}) | 37 | find_path(CURSES_INCLUDE_PATH curses.h PATH_SUFFIXES ncursesw) |
145 | ENDIF(CURSES_FORM_LIBRARY) | 38 | else() |
39 | find_path(CURSES_INCLUDE_PATH curses.h PATH_SUFFIXES ncurses) | ||
40 | endif() | ||
146 | 41 | ||
147 | # Proper name is *_INCLUDE_DIR | 42 | set(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH}) |
148 | SET(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH}) | ||
149 | 43 | ||
150 | # handle the QUIETLY and REQUIRED arguments and set CURSES_FOUND to TRUE if | 44 | include(FindPackageHandleStandardArgs) |
151 | # all listed variables are TRUE | 45 | find_package_handle_standard_args(Cursesw DEFAULT_MSG CURSES_INCLUDE_DIR CURSES_LIBRARIES) |
152 | INCLUDE(FindPackageHandleStandardArgs) | ||
153 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Curses DEFAULT_MSG | ||
154 | CURSES_LIBRARY CURSES_INCLUDE_PATH) | ||
155 | 46 | ||
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 | 47 | ||