mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-08-17 17:41:58 +08:00
cmake: Attempt to fall back to readline if editline not available
This commit is contained in:
+1
-1
@@ -104,7 +104,7 @@ find_package(argon2)
|
||||
|
||||
option(WITH_CTRL_SHELL "Include mosquitto_ctrl interactive shell support?" ON)
|
||||
if(WITH_CTRL_SHELL)
|
||||
find_package(edit)
|
||||
find_package(LineEditing)
|
||||
endif()
|
||||
if(ARGON2_FOUND)
|
||||
# Disable until separate password handling thread is implemented
|
||||
|
||||
@@ -12,7 +12,7 @@ if(WITH_TLS)
|
||||
../../common/json_help.c ../../common/json_help.h
|
||||
)
|
||||
|
||||
if(EDITLINE_FOUND)
|
||||
if(WITH_CTRL_SHELL AND LINEEDITING_FOUND)
|
||||
add_library(ctrl_shell OBJECT
|
||||
ctrl_shell.c
|
||||
ctrl_shell.h
|
||||
@@ -24,26 +24,32 @@ if(WITH_TLS)
|
||||
ctrl_shell_pre_connect.c
|
||||
ctrl_shell_printf.c
|
||||
)
|
||||
target_compile_definitions(ctrl_shell PRIVATE WITH_EDITLINE)
|
||||
target_compile_definitions(ctrl_shell PRIVATE WITH_CTRL_SHELL)
|
||||
target_include_directories(ctrl_shell PRIVATE
|
||||
"${mosquitto_SOURCE_DIR}"
|
||||
"${mosquitto_SOURCE_DIR}/common"
|
||||
"${mosquitto_SOURCE_DIR}/include"
|
||||
"${CJSON_INCLUDE_DIRS}"
|
||||
)
|
||||
target_link_libraries(ctrl_shell PRIVATE OpenSSL::SSL)
|
||||
target_link_libraries(ctrl_shell PRIVATE
|
||||
LineEditing::LineEditing
|
||||
OpenSSL::SSL
|
||||
)
|
||||
|
||||
add_library(ctrl_shell_io OBJECT
|
||||
ctrl_shell_io.c
|
||||
)
|
||||
target_compile_definitions(ctrl_shell_io PRIVATE WITH_EDITLINE)
|
||||
target_compile_definitions(ctrl_shell_io PRIVATE WITH_CTRL_SHELL)
|
||||
target_include_directories(ctrl_shell_io PRIVATE
|
||||
"${mosquitto_SOURCE_DIR}"
|
||||
"${mosquitto_SOURCE_DIR}/common"
|
||||
"${mosquitto_SOURCE_DIR}/include"
|
||||
"${CJSON_INCLUDE_DIRS}"
|
||||
)
|
||||
target_link_libraries(ctrl_shell_io PRIVATE OpenSSL::SSL)
|
||||
target_link_libraries(ctrl_shell_io PRIVATE
|
||||
LineEditing::LineEditing
|
||||
OpenSSL::SSL
|
||||
)
|
||||
endif()
|
||||
add_executable(mosquitto_ctrl ${SRC})
|
||||
|
||||
@@ -62,10 +68,10 @@ if(WITH_TLS)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(EDITLINE_FOUND)
|
||||
target_compile_definitions(mosquitto_ctrl PRIVATE WITH_EDITLINE)
|
||||
if(WITH_CTRL_SHELL AND LINEEDITING_FOUND)
|
||||
target_compile_definitions(mosquitto_ctrl PRIVATE WITH_CTRL_SHELL)
|
||||
target_link_libraries(mosquitto_ctrl PRIVATE
|
||||
"${EDITLINE_LIBRARIES}"
|
||||
LineEditing::LineEditing
|
||||
ctrl_shell
|
||||
ctrl_shell_io
|
||||
)
|
||||
|
||||
@@ -20,9 +20,10 @@ ifeq ($(WITH_THREADING),yes)
|
||||
LOCAL_LDFLAGS+=-pthread
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(WITH_EDITLINE),yes)
|
||||
LOCAL_LDADD+=-ledit
|
||||
LOCAL_CPPFLAGS+=-DWITH_EDITLINE
|
||||
LOCAL_CPPFLAGS+=-DWITH_CTRL_SHELL -DWITH_EDITLINE
|
||||
endif
|
||||
|
||||
OBJS= \
|
||||
|
||||
@@ -40,7 +40,7 @@ Contributors:
|
||||
|
||||
#define UNUSED(A) (void)(A)
|
||||
|
||||
#ifdef WITH_EDITLINE
|
||||
#ifdef WITH_CTRL_SHELL
|
||||
|
||||
#define FREE(A) do{free(A); A = NULL;}while(0)
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ Contributors:
|
||||
#include "ctrl_shell_internal.h"
|
||||
#include "json_help.h"
|
||||
|
||||
#ifdef WITH_EDITLINE
|
||||
#ifdef WITH_CTRL_SHELL
|
||||
|
||||
#define UNUSED(A) (void)(A)
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ Contributors:
|
||||
|
||||
#include "ctrl_shell_internal.h"
|
||||
|
||||
#ifdef WITH_EDITLINE
|
||||
#ifdef WITH_CTRL_SHELL
|
||||
|
||||
#define UNUSED(A) (void)(A)
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ Contributors:
|
||||
|
||||
#include "ctrl_shell_internal.h"
|
||||
|
||||
#ifdef WITH_EDITLINE
|
||||
#ifdef WITH_CTRL_SHELL
|
||||
|
||||
#define UNUSED(A) (void)(A)
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ Contributors:
|
||||
#include "ctrl_shell_internal.h"
|
||||
#include "json_help.h"
|
||||
|
||||
#ifdef WITH_EDITLINE
|
||||
#ifdef WITH_CTRL_SHELL
|
||||
|
||||
#define UNUSED(A) (void)(A)
|
||||
|
||||
|
||||
@@ -18,14 +18,22 @@ Contributors:
|
||||
#ifndef CTRL_SHELL_INTERNAL_H
|
||||
#define CTRL_SHELL_INTERNAL_H
|
||||
|
||||
#ifdef WITH_EDITLINE
|
||||
#ifdef WITH_CTRL_SHELL
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <cjson/cJSON.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef WITH_EDITLINE
|
||||
#include <editline/readline.h>
|
||||
#elif defined(WITH_READLINE)
|
||||
#include <readline/history.h>
|
||||
#include <readline/readline.h>
|
||||
#endif
|
||||
#include <pthread.h>
|
||||
|
||||
#include "ctrl_shell.h"
|
||||
#include "mosquitto_ctrl.h"
|
||||
|
||||
@@ -22,7 +22,7 @@ Contributors:
|
||||
|
||||
#include "ctrl_shell_internal.h"
|
||||
|
||||
#ifdef WITH_EDITLINE
|
||||
#ifdef WITH_CTRL_SHELL
|
||||
|
||||
#define UNUSED(A) (void)(A)
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ Contributors:
|
||||
|
||||
#include "ctrl_shell_internal.h"
|
||||
|
||||
#ifdef WITH_EDITLINE
|
||||
#ifdef WITH_CTRL_SHELL
|
||||
|
||||
#define UNUSED(A) (void)(A)
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ int main(int argc, char *argv[])
|
||||
char lib_name[200];
|
||||
|
||||
if(argc == 1){
|
||||
#ifdef WITH_EDITLINE
|
||||
#ifdef WITH_CTRL_SHELL
|
||||
ctrl_shell__main(NULL);
|
||||
#else
|
||||
print_usage();
|
||||
@@ -86,7 +86,7 @@ int main(int argc, char *argv[])
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifdef WITH_EDITLINE
|
||||
#ifdef WITH_CTRL_SHELL
|
||||
if(argc == 0){
|
||||
ctrl_shell__main(&ctrl.cfg);
|
||||
return 0;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
# Checks an environment variable; note that the first check
|
||||
# does not require the usual CMake $-sign.
|
||||
if(DEFINED env{EDITLINE_DIR})
|
||||
set(EDITLINE_DIR "$ENV{EDITLINE_DIR}")
|
||||
endif()
|
||||
|
||||
find_path(
|
||||
EDITLINE_INCLUDE_DIR
|
||||
editline/readline.h
|
||||
HINTS
|
||||
EDITLINE_DIR
|
||||
)
|
||||
|
||||
find_library(EDITLINE_LIBRARY
|
||||
NAMES edit
|
||||
HINTS ${EDITLINE_DIR}
|
||||
)
|
||||
|
||||
if(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY)
|
||||
set(EDITLINE_FOUND TRUE)
|
||||
set(LINEEDITING_FOUND TRUE)
|
||||
set(LINEEDITING_INCLUDE_DIRS ${EDITLINE_INCLUDE_DIR})
|
||||
set(LINEEDITING_LIBRARIES ${EDITLINE_LIBRARY})
|
||||
|
||||
if(NOT TARGET LineEditing::LineEditing)
|
||||
add_library(LineEditing::LineEditing UNKNOWN IMPORTED)
|
||||
set_target_properties(LineEditing::LineEditing PROPERTIES
|
||||
IMPORTED_LOCATION "${EDITLINE_LIBRARY}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${EDITLINE_INCLUDE_DIR}"
|
||||
INTERFACE_COMPILE_DEFINITIONS "WITH_EDITLINE"
|
||||
)
|
||||
endif()
|
||||
else()
|
||||
find_path(
|
||||
READLINE_INCLUDE_DIR
|
||||
readline/readline.h
|
||||
HINTS
|
||||
READLINE_DIR
|
||||
)
|
||||
|
||||
find_library(READLINE_LIBRARY
|
||||
NAMES readline
|
||||
HINTS ${READLINE_DIR}
|
||||
)
|
||||
|
||||
if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
|
||||
set(LINEEDITING_FOUND TRUE)
|
||||
set(LINEEDITING_INCLUDE_DIRS ${READLINE_INCLUDE_DIR})
|
||||
set(LINEEDITING_LIBRARIES ${READLINE_LIBRARY})
|
||||
|
||||
if(NOT TARGET LineEditing::LineEditing)
|
||||
add_library(LineEditing::LineEditing UNKNOWN IMPORTED)
|
||||
set_target_properties(LineEditing::LineEditing PROPERTIES
|
||||
IMPORTED_LOCATION "${READLINE_LIBRARY}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${READLINE_INCLUDE_DIR}"
|
||||
INTERFACE_COMPILE_DEFINITIONS "WITH_READLINE"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package_handle_standard_args(LineEditing
|
||||
REQUIRED_VARS LINEEDITING_LIBRARIES LINEEDITING_INCLUDE_DIRS
|
||||
FAIL_MESSAGE "Could not find libedit or readline library"
|
||||
)
|
||||
@@ -1,52 +0,0 @@
|
||||
INCLUDE( FindPackageHandleStandardArgs )
|
||||
|
||||
# Checks an environment variable; note that the first check
|
||||
# does not require the usual CMake $-sign.
|
||||
IF( DEFINED ENV{EDITLINE_DIR} )
|
||||
SET( EDITLINE_DIR "$ENV{EDITLINE_DIR}" )
|
||||
ENDIF()
|
||||
|
||||
FIND_PATH(
|
||||
EDITLINE_INCLUDE_DIR
|
||||
editline/readline.h
|
||||
HINTS
|
||||
EDITLINE_DIR
|
||||
)
|
||||
|
||||
FIND_LIBRARY( EDITLINE_LIBRARY
|
||||
NAMES edit
|
||||
HINTS ${EDITLINE_DIR}
|
||||
)
|
||||
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS( edit DEFAULT_MSG
|
||||
EDITLINE_INCLUDE_DIR EDITLINE_LIBRARY
|
||||
)
|
||||
|
||||
SET(EDITLINE_FOUND ${EDIT_FOUND})
|
||||
|
||||
IF( EDITLINE_FOUND )
|
||||
SET( EDITLINE_INCLUDE_DIRS ${EDITLINE_INCLUDE_DIR} )
|
||||
SET( EDITLINE_LIBRARIES ${EDITLINE_LIBRARY} )
|
||||
|
||||
MARK_AS_ADVANCED(
|
||||
EDITLINE_LIBRARY
|
||||
EDITLINE_INCLUDE_DIR
|
||||
EDITLINE_DIR
|
||||
)
|
||||
|
||||
add_library(editline SHARED IMPORTED)
|
||||
set_target_properties(editline
|
||||
PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${EDITLINE_INCLUDE_DIRS}"
|
||||
)
|
||||
|
||||
set_target_properties(editline
|
||||
PROPERTIES
|
||||
IMPORTED_LOCATION "${EDITLINE_LIBRARY}"
|
||||
IMPORTED_IMPLIB "${EDITLINE_LIBRARY}"
|
||||
)
|
||||
ELSE()
|
||||
SET( EDITLINE_DIR "" CACHE STRING
|
||||
"An optional hint to a directory for finding the `editline` library"
|
||||
)
|
||||
ENDIF()
|
||||
@@ -305,7 +305,3 @@ ifeq ($(WITH_ARGON2),yes)
|
||||
LIB_ARGON2=-largon2
|
||||
LIBMOSQ_COMMON+=${LIB_ARGON2}
|
||||
endif
|
||||
|
||||
ifeq ($(WITH_EDITLINE),yes)
|
||||
LOCAL_CPPFLAGS+=-DWITH_EDITLINE
|
||||
endif
|
||||
|
||||
@@ -20,7 +20,7 @@ endforeach()
|
||||
|
||||
|
||||
function(add_ctrl_shell_test TEST_NAME)
|
||||
if(NOT EDITLINE_FOUND)
|
||||
if(NOT WITH_CTRL_SHELL OR NOT EDITLINE_FOUND)
|
||||
return()
|
||||
endif()
|
||||
add_executable(${TEST_NAME}
|
||||
@@ -30,7 +30,10 @@ function(add_ctrl_shell_test TEST_NAME)
|
||||
$<TARGET_OBJECTS:ctrl_shell_mock>
|
||||
$<TARGET_OBJECTS:libmosquitto_mock>
|
||||
)
|
||||
target_compile_definitions(${TEST_NAME} PRIVATE WITH_EDITLINE)
|
||||
target_compile_definitions(${TEST_NAME} PRIVATE
|
||||
WITH_CTRL_SHELL
|
||||
WITH_EDITLINE
|
||||
)
|
||||
target_include_directories(${TEST_NAME} PRIVATE
|
||||
${mosquitto_SOURCE_DIR}
|
||||
${mosquitto_SOURCE_DIR}/apps/mosquitto_ctrl
|
||||
@@ -52,7 +55,7 @@ function(add_ctrl_shell_test TEST_NAME)
|
||||
endfunction()
|
||||
|
||||
function(add_ctrl_shell_test_real_editline TEST_NAME)
|
||||
if(NOT EDITLINE_FOUND)
|
||||
if(NOT WITH_CTRL_SHELL OR NOT EDITLINE_FOUND)
|
||||
return()
|
||||
endif()
|
||||
add_executable(${TEST_NAME}
|
||||
@@ -62,7 +65,9 @@ function(add_ctrl_shell_test_real_editline TEST_NAME)
|
||||
$<TARGET_OBJECTS:ctrl_shell_mock>
|
||||
$<TARGET_OBJECTS:libmosquitto_mock>
|
||||
)
|
||||
target_compile_definitions(${TEST_NAME} PRIVATE WITH_EDITLINE)
|
||||
target_compile_definitions(${TEST_NAME} PRIVATE
|
||||
WITH_CTRL_SHELL
|
||||
)
|
||||
target_include_directories(${TEST_NAME} PRIVATE
|
||||
${mosquitto_SOURCE_DIR}
|
||||
${mosquitto_SOURCE_DIR}/apps/mosquitto_ctrl
|
||||
@@ -74,7 +79,7 @@ function(add_ctrl_shell_test_real_editline TEST_NAME)
|
||||
${mosquitto_SOURCE_DIR}/test/mock/lib
|
||||
)
|
||||
target_link_libraries(${TEST_NAME} PRIVATE
|
||||
"${EDITLINE_LIBRARIES}"
|
||||
LineEditing::LineEditing
|
||||
GTest::gmock_main
|
||||
pthread_mock
|
||||
cjson
|
||||
|
||||
@@ -65,6 +65,7 @@ TEST_OBJS = \
|
||||
|
||||
ifeq ($(WITH_GMOCK),yes)
|
||||
ifeq ($(WITH_EDITLINE),yes)
|
||||
LOCAL_CPPFLAGS+=-DWITH_CTRL_SHELL -DWITH_EDITLINE
|
||||
MOCK_TESTS = \
|
||||
ctrl_shell_test \
|
||||
ctrl_shell_broker_test \
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
if(EDITLINE_FOUND)
|
||||
if(WITH_CTRL_SHELL AND EDITLINE_FOUND)
|
||||
add_library(ctrl_shell_mock OBJECT
|
||||
ctrl_shell_mock.cpp
|
||||
ctrl_shell_mock.hpp
|
||||
)
|
||||
target_compile_definitions(ctrl_shell_mock PRIVATE WITH_EDITLINE)
|
||||
target_compile_definitions(ctrl_shell_mock PRIVATE
|
||||
WITH_CTRL_SHELL
|
||||
WITH_EDITLINE
|
||||
)
|
||||
|
||||
target_include_directories(ctrl_shell_mock
|
||||
PUBLIC
|
||||
|
||||
@@ -4,6 +4,8 @@ include ${R}/config.mk
|
||||
.PHONY: all check test-compile test clean
|
||||
|
||||
LOCAL_CPPFLAGS+= \
|
||||
-DWITH_CTRL_SHELL \
|
||||
-DWITH_EDITLINE \
|
||||
-I../ \
|
||||
-I${R} \
|
||||
-I${R}/apps/mosquitto_ctrl \
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <gmock/gmock.h>
|
||||
#include <editline/readline.h>
|
||||
|
||||
#include "mosquitto_ctrl.h"
|
||||
#include "ctrl_shell_internal.h"
|
||||
|
||||
#include "c_function_mock.hpp"
|
||||
|
||||
Reference in New Issue
Block a user