forked from trdtnguyen/mysql-plnvm
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreadline.cmake
207 lines (185 loc) · 6.18 KB
/
readline.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# cmake -DWITH_EDITLINE=system|bundled
# bundled is the default
MACRO (MYSQL_CHECK_MULTIBYTE)
SET(CMAKE_EXTRA_INCLUDE_FILES wchar.h)
CHECK_TYPE_SIZE(mbstate_t SIZEOF_MBSTATE_T)
SET(CMAKE_EXTRA_INCLUDE_FILES)
IF(SIZEOF_MBSTATE_T)
SET(HAVE_MBSTATE_T 1)
ENDIF()
CHECK_C_SOURCE_COMPILES("
#include <langinfo.h>
int main(int ac, char **av)
{
char *cs = nl_langinfo(CODESET);
return 0;
}"
HAVE_LANGINFO_CODESET)
CHECK_FUNCTION_EXISTS(wcsdup HAVE_WCSDUP)
SET(CMAKE_EXTRA_INCLUDE_FILES wchar.h)
CHECK_TYPE_SIZE(wchar_t SIZEOF_WCHAR_T)
IF(SIZEOF_WCHAR_T)
SET(HAVE_WCHAR_T 1)
ENDIF()
SET(CMAKE_EXTRA_INCLUDE_FILES wctype.h)
CHECK_TYPE_SIZE(wint_t SIZEOF_WINT_T)
IF(SIZEOF_WINT_T)
SET(HAVE_WINT_T 1)
ENDIF()
SET(CMAKE_EXTRA_INCLUDE_FILES)
ENDMACRO()
MACRO (FIND_CURSES)
FIND_PACKAGE(Curses)
MARK_AS_ADVANCED(CURSES_CURSES_H_PATH CURSES_FORM_LIBRARY CURSES_HAVE_CURSES_H)
IF(NOT CURSES_FOUND)
SET(ERRORMSG "Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.")
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
SET(ERRORMSG ${ERRORMSG}
"On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates "
"it is ncurses-devel.")
ENDIF()
MESSAGE(FATAL_ERROR ${ERRORMSG})
ENDIF()
IF(CURSES_HAVE_CURSES_H)
SET(HAVE_CURSES_H 1 CACHE INTERNAL "")
ELSEIF(CURSES_HAVE_NCURSES_H)
SET(HAVE_NCURSES_H 1 CACHE INTERNAL "")
ENDIF()
IF(CMAKE_SYSTEM_NAME MATCHES "HP")
# CMake uses full path to library /lib/libcurses.sl
# On Itanium, it results into architecture mismatch+
# the library is for PA-RISC
SET(CURSES_LIBRARY "curses" CACHE INTERNAL "" FORCE)
SET(CURSES_CURSES_LIBRARY "curses" CACHE INTERNAL "" FORCE)
ENDIF()
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
# CMake generates /lib/64/libcurses.so -R/lib/64
# The result is we cannot find
# /opt/studio12u2/lib/stlport4/v9/libstlport.so.1
# at runtime
SET(CURSES_LIBRARY "curses" CACHE INTERNAL "" FORCE)
SET(CURSES_CURSES_LIBRARY "curses" CACHE INTERNAL "" FORCE)
MESSAGE(STATUS "CURSES_LIBRARY ${CURSES_LIBRARY}")
ENDIF()
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
# -Wl,--as-needed breaks linking with -lcurses, e.g on Fedora
# Lower-level libcurses calls are exposed by libtinfo
CHECK_LIBRARY_EXISTS(${CURSES_LIBRARY} tputs "" HAVE_TPUTS_IN_CURSES)
IF(NOT HAVE_TPUTS_IN_CURSES)
CHECK_LIBRARY_EXISTS(tinfo tputs "" HAVE_TPUTS_IN_TINFO)
IF(HAVE_TPUTS_IN_TINFO)
SET(CURSES_LIBRARY tinfo)
ENDIF()
ENDIF()
ENDIF()
ENDMACRO()
MACRO (MYSQL_USE_BUNDLED_EDITLINE)
SET(USE_LIBEDIT_INTERFACE 1)
SET(HAVE_HIST_ENTRY 1)
SET(EDITLINE_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/cmd-line-utils/libedit/editline)
SET(EDITLINE_LIBRARY edit)
FIND_CURSES()
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/cmd-line-utils/libedit)
ENDMACRO()
MACRO (FIND_SYSTEM_EDITLINE)
FIND_PATH(FOUND_EDITLINE_READLINE
NAMES editline/readline.h
)
IF(FOUND_EDITLINE_READLINE)
SET(EDITLINE_INCLUDE_DIR "${FOUND_EDITLINE_READLINE}/editline")
ELSE()
# Different path on FreeBSD
FIND_PATH(FOUND_EDIT_READLINE_READLINE
NAMES edit/readline/readline.h
)
IF(FOUND_EDIT_READLINE_READLINE)
SET(EDITLINE_INCLUDE_DIR "${FOUND_EDIT_READLINE_READLINE}/edit/readline")
ENDIF()
ENDIF()
FIND_LIBRARY(EDITLINE_LIBRARY
NAMES
edit
)
MARK_AS_ADVANCED(EDITLINE_INCLUDE_DIR EDITLINE_LIBRARY)
MESSAGE(STATUS "EDITLINE_INCLUDE_DIR ${EDITLINE_INCLUDE_DIR}")
MESSAGE(STATUS "EDITLINE_LIBRARY ${EDITLINE_LIBRARY}")
INCLUDE(CheckCXXSourceCompiles)
IF(EDITLINE_LIBRARY AND EDITLINE_INCLUDE_DIR)
SET(CMAKE_REQUIRED_INCLUDES ${EDITLINE_INCLUDE_DIR})
SET(CMAKE_REQUIRED_LIBRARIES ${EDITLINE_LIBRARY})
CHECK_CXX_SOURCE_COMPILES("
#include <stdio.h>
#include <readline.h>
int main(int argc, char **argv)
{
HIST_ENTRY entry;
return 0;
}"
EDITLINE_HAVE_HIST_ENTRY)
CHECK_CXX_SOURCE_COMPILES("
#include <stdio.h>
#include <readline.h>
int main(int argc, char **argv)
{
typedef int MYFunction(const char*, int);
MYFunction* myf= rl_completion_entry_function;
int res= (myf)(NULL, 0);
completion_matches(0,0);
return res;
}"
EDITLINE_HAVE_COMPLETION_INT)
CHECK_CXX_SOURCE_COMPILES("
#include <stdio.h>
#include <readline.h>
int main(int argc, char **argv)
{
typedef char* MYFunction(const char*, int);
MYFunction* myf= rl_completion_entry_function;
char *res= (myf)(NULL, 0);
completion_matches(0,0);
return res != NULL;
}"
EDITLINE_HAVE_COMPLETION_CHAR)
IF(EDITLINE_HAVE_COMPLETION_INT OR EDITLINE_HAVE_COMPLETION_CHAR)
SET(HAVE_HIST_ENTRY ${EDITLINE_HAVE_HIST_ENTRY})
SET(USE_LIBEDIT_INTERFACE 1)
SET(EDITLINE_FOUND 1)
IF(EDITLINE_HAVE_COMPLETION_CHAR)
SET(USE_NEW_EDITLINE_INTERFACE 1)
ENDIF()
ENDIF()
ENDIF()
ENDMACRO()
IF (NOT WITH_EDITLINE AND NOT WIN32)
SET(WITH_EDITLINE "bundled" CACHE STRING "By default use bundled editline")
ENDIF()
MACRO (MYSQL_CHECK_EDITLINE)
IF (NOT WIN32)
MYSQL_CHECK_MULTIBYTE()
IF(WITH_EDITLINE STREQUAL "bundled")
MYSQL_USE_BUNDLED_EDITLINE()
ELSEIF(WITH_EDITLINE STREQUAL "system")
FIND_SYSTEM_EDITLINE()
IF(NOT EDITLINE_FOUND)
MESSAGE(FATAL_ERROR "Cannot find system editline libraries.")
ENDIF()
ELSE()
MESSAGE(FATAL_ERROR "WITH_EDITLINE must be bundled or system")
ENDIF()
ENDIF(NOT WIN32)
ENDMACRO()