[cmake] Detect presence of wide-char libedit at build time

Summary:
Instead of hardcoding a list of platforms where libedit is known to have
wide char support we detect this in cmake. The main motivation for this
is attempting to improve compatibility with different versions of
libedit, as the interface of non-wide-char functions varies slightly
between versions.

Reviewers: krytarowski, uweigand, jankratochvil, timshen, beanz

Subscribers: mgorny, lldb-commits

Differential Revision: https://reviews.llvm.org/D47625

llvm-svn: 334393
This commit is contained in:
Pavel Labath 2018-06-11 09:14:26 +00:00
parent 00d8843fa3
commit 3351381165
4 changed files with 33 additions and 14 deletions

View File

@ -4,6 +4,7 @@ include(CheckSymbolExists)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(CheckTypeSize)
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
check_symbol_exists(ppoll poll.h HAVE_PPOLL)
@ -27,6 +28,24 @@ if(NOT UNIX)
set(LLDB_DISABLE_POSIX 1)
endif()
if (NOT LLDB_DISABLE_LIBEDIT)
# Check if we libedit capable of handling wide characters (built with
# '--enable-widec').
set(CMAKE_REQUIRED_LIBRARIES ${libedit_LIBRARIES})
set(CMAKE_REQUIRED_INCLUDES ${libedit_INCLUDE_DIRS})
check_symbol_exists(el_winsertstr histedit.h LLDB_EDITLINE_USE_WCHAR)
set(CMAKE_EXTRA_INCLUDE_FILES histedit.h)
check_type_size(el_rfunc_t LLDB_EL_RFUNC_T_SIZE)
if (LLDB_EL_RFUNC_T_SIZE STREQUAL "")
set(LLDB_HAVE_EL_RFUNC_T 0)
else()
set(LLDB_HAVE_EL_RFUNC_T 1)
endif()
set(CMAKE_REQUIRED_LIBRARIES)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_EXTRA_INCLUDE_FILES)
endif()
if(NOT LLDB_CONFIG_HEADER_INPUT)
set(LLDB_CONFIG_HEADER_INPUT ${LLDB_INCLUDE_ROOT}/lldb/Host/Config.h.cmake)
endif()

View File

@ -16,6 +16,10 @@
// absence of a configuration step.
#define LLDB_CONFIG_TERMIOS_SUPPORTED 1
#define LLDB_EDITLINE_USE_WCHAR 1
#define LLDB_HAVE_EL_RFUNC_T 1
#define HAVE_SYS_EVENT_H 1
#define HAVE_PPOLL 0

View File

@ -12,6 +12,10 @@
#cmakedefine LLDB_CONFIG_TERMIOS_SUPPORTED
#cmakedefine01 LLDB_EDITLINE_USE_WCHAR
#cmakedefine01 LLDB_HAVE_EL_RFUNC_T
#cmakedefine LLDB_DISABLE_POSIX
#define LLDB_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}"

View File

@ -33,23 +33,11 @@
#define liblldb_Editline_h_
#if defined(__cplusplus)
#include <codecvt>
#include <locale>
#include <sstream>
#include <vector>
// components needed to handle wide characters ( <codecvt>, codecvt_utf8,
// libedit built with '--enable-widec' ) are available on some platforms. The
// wchar_t versions of libedit functions will only be used in cases where this
// is true. This is a compile time dependecy, for now selected per target
// Platform
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
defined(__OpenBSD__)
#define LLDB_EDITLINE_USE_WCHAR 1
#include <codecvt>
#else
#define LLDB_EDITLINE_USE_WCHAR 0
#endif
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/lldb-private.h"
@ -81,7 +69,11 @@ using EditLineStringStreamType = std::stringstream;
using EditLineCharType = char;
#endif
#ifdef EL_CLIENTDATA /* editline with wide support + wide char read function */
// At one point the callback type of el_set getchar callback changed from char
// to wchar_t. It is not possible to detect differentiate between the two
// versions exactly, but this is a pretty good approximation and allows us to
// build against almost any editline version out there.
#if LLDB_EDITLINE_USE_WCHAR || defined(EL_CLIENTDATA) || LLDB_HAVE_EL_RFUNC_T
using EditLineGetCharType = wchar_t;
#else
using EditLineGetCharType = char;