Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
  • Loading branch information
zhaojh329 committed Apr 27, 2021
1 parent d5d4a8b commit 89815e2
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 494 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "src/buffer"]
path = src/buffer
url = https://github.com/zhaojh329/buffer
[submodule "src/ssl"]
path = src/ssl
url = https://github.com/zhaojh329/ssl
22 changes: 20 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.0)

project(libumqtt C)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")

#set(CMAKE_VERBOSE_MAKEFILE ON)

add_definitions(-D_GNU_SOURCE)
add_compile_options(-O -Wall -Werror --std=gnu99)

option(BUILD_STATIC "Build static library" OFF)

option(BUILD_EXAMPLE "Build example" ON)

if(BUILD_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
endif()

find_package(Libev REQUIRED)

add_subdirectory(src/ssl)

add_subdirectory(src)
add_subdirectory(example)

if(BUILD_EXAMPLE)
add_subdirectory(example)
endif()
37 changes: 0 additions & 37 deletions cmake/Modules/FindMbedTLS.cmake

This file was deleted.

62 changes: 0 additions & 62 deletions cmake/Modules/FindWolfSSL.cmake

This file was deleted.

14 changes: 12 additions & 2 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
include_directories(${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/buffer ${CMAKE_BINARY_DIR}/src)
set(LIBS ${LIBEV_LIBRARY} umqtt)

if(SSL_SUPPORT)
list(APPEND LIBS ${SSL_LIBS})
endif()

include_directories(
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/buffer
${CMAKE_BINARY_DIR}/src
${LIBEV_INCLUDE_DIR})

add_executable(example example.c)
target_link_libraries(example umqtt ${LIBEV_LIBRARY})
target_link_libraries(example PRIVATE ${LIBS})
101 changes: 19 additions & 82 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,93 +1,34 @@
add_definitions(-O -Wall -Werror --std=gnu99 -D_GNU_SOURCE)

# The version number.
set(UMQTT_VERSION_MAJOR 1)
set(UMQTT_VERSION_MINOR 0)
set(UMQTT_VERSION_PATCH 3)

# Check the third party Libraries
find_package(Libev REQUIRED)

include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/buffer ${CMAKE_CURRENT_BINARY_DIR} ${LIBEV_INCLUDE_DIR})

set(EXTRA_LIBS ${LIBEV_LIBRARY} dl)
set(SOURCE_FILES umqtt.c log.c utils.c buffer/buffer.c ssl.c)

set(UMQTT_SSL_SUPPORT_CONFIG 1)
option(UMQTT_SSL_SUPPORT "SSL support" ON)

option(UMQTT_USE_OPENSSL "Force select OpenSSL" OFF)
option(UMQTT_USE_WOLFSSL "Force select WolfSSL(CyaSSL)" OFF)
option(UMQTT_USE_MBEDTLS "Force select MbedTLS(PolarSSL)" OFF)
aux_source_directory(. SOURCES)
list(APPEND SOURCES buffer/buffer.c)

set(SSL_NAME OFF)
set(UMQTT_HAVE_OPENSSL_CONFIG 0)
set(UMQTT_HAVE_WOLFSSL_CONFIG 0)
set(UMQTT_HAVE_MBEDTLS_CONFIG 0)
if(BUILD_STATIC)
if(SSL_SUPPORT)
list(APPEND SOURCES ${SSL_SRC})
endif()

if(NOT UMQTT_SSL_SUPPORT)
set(UMQTT_SSL_SUPPORT_CONFIG 0)
else()
find_package(OpenSSL)
find_package(WolfSSL)
find_package(MbedTLS)
add_library(umqtt STATIC ${SOURCES})

if(UMQTT_USE_OPENSSL)
if (NOT OPENSSL_FOUND)
set(UMQTT_SSL_SUPPORT OFF)
message(WARNING "Force select OpenSSL, but not found it")
endif()
elseif(UMQTT_USE_WOLFSSL)
if (NOT WOLFSSL_FOUND)
set(UMQTT_SSL_SUPPORT OFF)
message(WARNING "Force select WolfSSL(CyaSSL), but not found it")
endif()
elseif(UMQTT_USE_MBEDTLS)
if (NOT MBEDTLS_FOUND)
set(UMQTT_SSL_SUPPORT OFF)
message(WARNING "Force select MbedTLS(PolarSSL), but not found it")
endif()
elseif(OPENSSL_FOUND)
set(UMQTT_USE_OPENSSL ON)
elseif(WOLFSSL_FOUND)
set(UMQTT_USE_WOLFSSL ON)
elseif(MBEDTLS_FOUND)
set(UMQTT_USE_MBEDTLS ON)
else()
set(UMQTT_SSL_SUPPORT OFF)
message(WARNING "No available SSL libraries found")
if(SSL_SUPPORT)
target_compile_definitions(umqtt PRIVATE ${SSL_DEFINE})
target_include_directories(umqtt PRIVATE ${SSL_INC})
endif()
else()
add_library(umqtt SHARED ${SOURCES})

if(UMQTT_USE_OPENSSL)
set(SSL_NAME "OpenSSL")
set(SSL_INC ${OPENSSL_INCLUDE_DIR})
set(SSL_LIB ${OPENSSL_LIBRARIES})
set(UMQTT_HAVE_OPENSSL_CONFIG 1)
elseif(UMQTT_USE_WOLFSSL)
set(SSL_NAME "WolfSSL(CyaSSL)")
set(SSL_INC ${WOLFSSL_INCLUDE_DIR})
set(SSL_LIB ${WOLFSSL_LIBRARIES})
set(UMQTT_HAVE_WOLFSSL_CONFIG 1)
elseif(UMQTT_USE_MBEDTLS)
set(SSL_NAME "MbedTLS(PolarSSL)")
set(SSL_INC ${MBEDTLS_INCLUDE_DIR})
set(SSL_LIB ${MBEDTLS_LIBRARIES})
set(UMQTT_HAVE_MBEDTLS_CONFIG 1)
if(SSL_SUPPORT)
target_link_libraries(umqtt PRIVATE ${SSL_TARGET})
endif()

if(UMQTT_SSL_SUPPORT)
include_directories(${SSL_INC})
list(APPEND EXTRA_LIBS ${SSL_LIB})
message(STATUS "Select ${SSL_NAME} as the SSL backend")
else()
set(SSL_NAME OFF)
set(UMQTT_SSL_SUPPORT_CONFIG 0)
endif()
target_link_libraries(umqtt PRIVATE ${LIBEV_LIBRARY})
set_target_properties(umqtt PROPERTIES VERSION ${UMQTT_VERSION_MAJOR}.${UMQTT_VERSION_MINOR}.${UMQTT_VERSION_PATCH})
endif()

add_library(umqtt SHARED ${SOURCE_FILES})
set_target_properties(umqtt PROPERTIES VERSION ${UMQTT_VERSION_MAJOR}.${UMQTT_VERSION_MINOR}.${UMQTT_VERSION_PATCH})
target_link_libraries(umqtt ${EXTRA_LIBS})
target_include_directories(umqtt PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${LIBEV_INCLUDE_DIR} buffer)

# configure a header file to pass some of the CMake settings to the source code
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
Expand All @@ -97,20 +38,16 @@ add_subdirectory(lua)
install(
FILES
log.h
ssl.h
umqtt.h
utils.h
buffer/buffer.h
${CMAKE_CURRENT_BINARY_DIR}/config.h
DESTINATION
include/umqtt
DESTINATION include/umqtt
)

install(
TARGETS umqtt LIBRARY
TARGETS umqtt
DESTINATION lib
)

message(STATUS "UMQTT_VERSION: ${UMQTT_VERSION_MAJOR}.${UMQTT_VERSION_MINOR}.${UMQTT_VERSION_PATCH}")
message(STATUS "UMQTT_SSL_SUPPORT: ${SSL_NAME}")

2 changes: 1 addition & 1 deletion src/buffer
Submodule buffer updated 2 files
+17 −15 buffer.c
+24 −2 buffer.h
6 changes: 1 addition & 5 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
#define UMQTT_VERSION_PATCH @UMQTT_VERSION_PATCH@
#define UMQTT_VERSION_STRING "@UMQTT_VERSION_MAJOR@.@UMQTT_VERSION_MINOR@.@UMQTT_VERSION_PATCH@"

#define UMQTT_SSL_SUPPORT @UMQTT_SSL_SUPPORT_CONFIG@

#define UMQTT_HAVE_OPENSSL @UMQTT_HAVE_OPENSSL_CONFIG@
#define UMQTT_HAVE_WOLFSSL @UMQTT_HAVE_WOLFSSL_CONFIG@
#define UMQTT_HAVE_MBEDTLS @UMQTT_HAVE_MBEDTLS_CONFIG@
#cmakedefine SSL_SUPPORT

#endif
1 change: 1 addition & 0 deletions src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void umqtt_log_close();

#define umqtt_log_debug(fmt...) umqtt_log(LOG_DEBUG, fmt)
#define umqtt_log_info(fmt...) umqtt_log(LOG_INFO, fmt)
#define umqtt_log_warn(fmt...) umqtt_log(LOG_WARNING, fmt)
#define umqtt_log_err(fmt...) umqtt_log(LOG_ERR, fmt)

void __umqtt_log(const char *filename, int line, int priority, const char *fmt, ...);
Expand Down
19 changes: 9 additions & 10 deletions src/lua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ find_package(Lua)
set(UMQTT_LUA_SUPPORT_DEFAULT "ON")

if (NOT LUA_FOUND)
set(BUILD_LUA_DEFAULT "OFF")
set(BUILD_LUA_DEFAULT "OFF")
endif (NOT LUA_FOUND)

option(UMQTT_LUA_SUPPORT "Enable build of Lua module" ${UMQTT_LUA_SUPPORT_DEFAULT})

if(UMQTT_LUA_SUPPORT)
include_directories(${LUA_INCLUDE_DIR})
add_library(umqtt-lua MODULE umqtt_lua.c)
target_include_directories(umqtt-lua PRIVATE ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/buffer ${CMAKE_BINARY_DIR}/src ${LUA_INCLUDE_DIR})
target_link_libraries(umqtt-lua PRIVATE umqtt)
set_target_properties(umqtt-lua PROPERTIES OUTPUT_NAME umqtt PREFIX "")

add_library(umqtt-lua MODULE umqtt_lua.c)
set_target_properties(umqtt-lua PROPERTIES OUTPUT_NAME umqtt PREFIX "")

target_link_libraries(umqtt-lua umqtt)

install(TARGETS umqtt-lua
LIBRARY DESTINATION lib/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}
)
install(
TARGETS umqtt-lua
DESTINATION lib/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}
)
endif(UMQTT_LUA_SUPPORT)
1 change: 1 addition & 0 deletions src/ssl
Submodule ssl added at e3c49e
Loading

0 comments on commit 89815e2

Please sign in to comment.