# - Find the readline include files and libraries
# - Include finding of termcap or curses
#
# READLINE_FOUND
# READLINE_INCLUDE_DIR
# READLINE_LIBRARIES
#
include(FindCurses)
include(FindTermcap)

FIND_LIBRARY(READLINE_HISTORY_LIBRARY NAMES history)
FIND_LIBRARY(READLINE_READLINE_LIBRARY NAMES readline)
FIND_PATH(READLINE_INCLUDE_DIR readline/readline.h)
SET(READLINE_FOUND FALSE)

IF (READLINE_HISTORY_LIBRARY AND READLINE_READLINE_LIBRARY AND READLINE_INCLUDE_DIR)
	SET (READLINE_FOUND TRUE)
	SET (READLINE_INCLUDE_DIR ${READLINE_INCLUDE_DIR})
	SET (READLINE_LIBRARIES ${READLINE_HISTORY_LIBRARY} ${READLINE_READLINE_LIBRARY})
	MESSAGE(STATUS "Found GNU readline: ${READLINE_HISTORY_LIBRARY}, ${READLINE_READLINE_LIBRARY}")
	IF (CURSES_FOUND)
		SET (READLINE_LIBRARIES ${READLINE_LIBRARIES} ${CURSES_LIBRARY})
	ENDIF(CURSES_FOUND)
	IF (TERMCAP_FOUND)
		SET (READLINE_LIBRARIES ${READLINE_LIBRARIES} ${TERMCAP_LIBRARY})
	ENDIF (TERMCAP_FOUND)
ENDIF (READLINE_HISTORY_LIBRARY AND READLINE_READLINE_LIBRARY AND READLINE_INCLUDE_DIR)

MARK_AS_ADVANCED(
	READLINE_FOUND
	READLINE_INCLUDE_DIR
	READLINE_LIBRARIES
	)

# - Find the readline include files and libraries
# - Include finding of termcap or curses
#
# READLINE_FOUND
# READLINE_INCLUDE_DIR
# READLINE_LIBRARIES
#
include(FindTermcap)

FIND_LIBRARY(READLINE_READLINE_LIBRARY NAMES readline)
FIND_PATH(READLINE_INCLUDE_DIR readline/readline.h)
SET(READLINE_FOUND FALSE)

IF (READLINE_READLINE_LIBRARY AND READLINE_INCLUDE_DIR)
	SET (READLINE_FOUND TRUE)
	SET (READLINE_INCLUDE_DIR ${READLINE_INCLUDE_DIR})
	SET (READLINE_LIBRARIES ${READLINE_READLINE_LIBRARY})
	MESSAGE(STATUS "Found GNU readline: ${READLINE_READLINE_LIBRARY}")
	IF (TERMCAP_FOUND)
		SET (READLINE_LIBRARIES ${READLINE_LIBRARIES} ${TERMCAP_LIBRARY})
	ENDIF (TERMCAP_FOUND)
ENDIF (READLINE_READLINE_LIBRARY AND READLINE_INCLUDE_DIR)

MARK_AS_ADVANCED(
	READLINE_FOUND
	READLINE_INCLUDE_DIR
	READLINE_LIBRARIES
	)

Fix broken (crashing) command line client on Ubuntu Precise
Fix broken (crashing) command line client on Ubuntu Precise

libreadline already goes with libhistory compiled in,
no reason to add it to the dynamically linked library
list.
Apparently, explicitly listing libhistory leads to
the dl loader pre-loading it instead of the compiled-in
version, which, in turn, leads to a crash on the first
history search in the command line client.

The fix is to remove cmake dependency on libhistory
as well as on libncurses, which we don't need either
(always require libtermcap).
