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 | |
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.
-rwxr-xr-x | CMakeLists.txt | 1 | ||||
-rw-r--r-- | INSTALL.md | 3 | ||||
-rw-r--r-- | cmake/FindCursesw.cmake | 196 | ||||
-rw-r--r-- | testing/toxic/CMakeLists.txt | 5 | ||||
-rw-r--r-- | testing/toxic/chat.c | 4 | ||||
-rw-r--r-- | testing/toxic/main.c | 1 | ||||
-rw-r--r-- | testing/toxic/windows.c | 4 | ||||
-rw-r--r-- | testing/toxic/windows.h | 1 |
8 files changed, 48 insertions, 167 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 132357de..cba0013c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -8,6 +8,7 @@ if(WIN32) | |||
8 | option(SHARED_LIBSODIUM "Links libsodium as a shared library") | 8 | option(SHARED_LIBSODIUM "Links libsodium as a shared library") |
9 | else() | 9 | else() |
10 | option(USE_NACL "Use NaCl library instead of libsodium") | 10 | option(USE_NACL "Use NaCl library instead of libsodium") |
11 | option(NO_WIDECHAR "Do not use wide char, even if supported") | ||
11 | endif() | 12 | endif() |
12 | 13 | ||
13 | #OS X specific | 14 | #OS X specific |
@@ -65,7 +65,8 @@ cmake .. | |||
65 | Advance cmake options: | 65 | Advance cmake options: |
66 | - `-DSHARED_TOXCORE=ON` (default `OFF`) � Build Core as a shared library. | 66 | - `-DSHARED_TOXCORE=ON` (default `OFF`) � Build Core as a shared library. |
67 | - `-DUSE_NACL=ON` (default `OFF`) � Use NaCl library instead of libsodium. | 67 | - `-DUSE_NACL=ON` (default `OFF`) � Use NaCl library instead of libsodium. |
68 | 68 | - `-DNO_WIDECHAR=ON` (default `OFF`) � Disable wide char in toxic. | |
69 | |||
69 | Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only. | 70 | Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only. |
70 | 71 | ||
71 | Then you can build any of the [`/testing`](/testing) and [`/other`](/other) that are currently supported on your platform by running: | 72 | Then you can build any of the [`/testing`](/testing) and [`/other`](/other) that are currently supported on your platform by running: |
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 | ||
diff --git a/testing/toxic/CMakeLists.txt b/testing/toxic/CMakeLists.txt index 53316afb..b59cb55e 100644 --- a/testing/toxic/CMakeLists.txt +++ b/testing/toxic/CMakeLists.txt | |||
@@ -15,6 +15,11 @@ add_executable(${exe_name} | |||
15 | chat.c | 15 | chat.c |
16 | configdir.c) | 16 | configdir.c) |
17 | 17 | ||
18 | if(CURSES_HAVE_WIDE_CHAR) | ||
19 | add_definitions( -D_XOPEN_SOURCE_EXTENDED ) | ||
20 | add_definitions( -DHAVE_WIDE_CHAR ) | ||
21 | endif() | ||
22 | |||
18 | include_directories(${CURSES_INCLUDE_DIR}) | 23 | include_directories(${CURSES_INCLUDE_DIR}) |
19 | 24 | ||
20 | target_link_libraries(${exe_name} | 25 | target_link_libraries(${exe_name} |
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index c7a0f98e..9454010f 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c | |||
@@ -182,7 +182,11 @@ static void chat_onKey(ToxWindow *self, Messenger *m, wint_t key) | |||
182 | getmaxyx(self->window, y2, x2); | 182 | getmaxyx(self->window, y2, x2); |
183 | 183 | ||
184 | /* Add printable chars to buffer and print on input space */ | 184 | /* Add printable chars to buffer and print on input space */ |
185 | #if HAVE_WIDECHAR | ||
185 | if (iswprint(key)) { | 186 | if (iswprint(key)) { |
187 | #else | ||
188 | if (isprint(key)) { | ||
189 | #endif | ||
186 | if (ctx->pos != sizeof(ctx->line) - 1) { | 190 | if (ctx->pos != sizeof(ctx->line) - 1) { |
187 | mvwaddstr(self->window, y, x, wc_to_char(key)); | 191 | mvwaddstr(self->window, y, x, wc_to_char(key)); |
188 | ctx->line[ctx->pos++] = key; | 192 | ctx->line[ctx->pos++] = key; |
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 12b529fc..2d4a39ad 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -2,7 +2,6 @@ | |||
2 | * Toxic -- Tox Curses Client | 2 | * Toxic -- Tox Curses Client |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #define _XOPEN_SOURCE_EXTENDED | ||
6 | #include <curses.h> | 5 | #include <curses.h> |
7 | #include <errno.h> | 6 | #include <errno.h> |
8 | #include <stdio.h> | 7 | #include <stdio.h> |
diff --git a/testing/toxic/windows.c b/testing/toxic/windows.c index f50bdc2d..7f547d0a 100644 --- a/testing/toxic/windows.c +++ b/testing/toxic/windows.c | |||
@@ -234,7 +234,11 @@ void draw_active_window(Messenger *m) | |||
234 | a->onDraw(a, m); | 234 | a->onDraw(a, m); |
235 | 235 | ||
236 | /* Handle input */ | 236 | /* Handle input */ |
237 | #ifdef HAVE_WIDECHAR | ||
237 | get_wch(&ch); | 238 | get_wch(&ch); |
239 | #else | ||
240 | ch = getch(); | ||
241 | #endif | ||
238 | 242 | ||
239 | if (ch == '\t' || ch == KEY_BTAB) | 243 | if (ch == '\t' || ch == KEY_BTAB) |
240 | set_next_window((int) ch); | 244 | set_next_window((int) ch); |
diff --git a/testing/toxic/windows.h b/testing/toxic/windows.h index 227040b9..0f3b82bd 100644 --- a/testing/toxic/windows.h +++ b/testing/toxic/windows.h | |||
@@ -4,7 +4,6 @@ | |||
4 | #ifndef _windows_h | 4 | #ifndef _windows_h |
5 | #define _windows_h | 5 | #define _windows_h |
6 | 6 | ||
7 | #define _XOPEN_SOURCE_EXTENDED | ||
8 | #include <curses.h> | 7 | #include <curses.h> |
9 | #include <stdint.h> | 8 | #include <stdint.h> |
10 | #include <stdbool.h> | 9 | #include <stdbool.h> |