diff --git a/CMakeLists.txt b/CMakeLists.txt index e13c818..1f332e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR) INCLUDE(CMakeDependentOption) OPTION(USED_HTTP_SVR "Build-in http(s) server support" OFF) +OPTION(USED_HTTP_CLIENT "Build-in http(s) client(GET/POST ...) support" ON) OPTION(USED_JSON_VALIDATE "Support json protocol field validate" OFF) OPTION(BUILD_TESTING "Enable tests" OFF) @@ -93,6 +94,13 @@ ELSE () MESSAGE("-- Unselect Option USED_HTTP_SVR") ENDIF () +IF (USED_HTTP_CLIENT) + LIST(APPEND COMMON_DEFINE "-DHTTPCLIENT_ON") + MESSAGE("++ Select Option USED_HTTP_CLIENT") +ELSE () + MESSAGE("-- Unselect Option USED_HTTP_CLIENT") +ENDIF () + IF (USED_SQLITE) MESSAGE("++ Select Option USED_SQLITE") LIST(APPEND COMMON_DEFINE "-DSQLITE_ON") diff --git a/depend/libuv-1.49.2.tar.gz b/depend/libuv-1.49.2.tar.gz deleted file mode 100644 index b043ceb..0000000 Binary files a/depend/libuv-1.49.2.tar.gz and /dev/null differ diff --git a/depend/system_libs.cmake b/depend/system_libs.cmake index 36c2916..8068b25 100644 --- a/depend/system_libs.cmake +++ b/depend/system_libs.cmake @@ -7,21 +7,19 @@ FUNCTION(LINUX_INSTALL_SYSTEM_PACKAGE) IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND EXISTS ${OS_RELEASE_FILE}) FILE(STRINGS ${OS_RELEASE_FILE} OS_RELEASE_NAME LIMIT_COUNT 1) STRING(FIND ${OS_RELEASE_NAME} "CentOS" SUB_OUT) - IF (${SUB_OUT} MATCHES "6") + IF (NOT ${SUB_OUT} MATCHES "-1") SET(OS_DISTRIB_NAME "CentOS") ELSE () STRING(FIND ${OS_RELEASE_NAME} "Ubuntu" SUB_OUT) - - IF (${SUB_OUT} MATCHES "6") + IF (NOT ${SUB_OUT} MATCHES "-1") SET(OS_DISTRIB_NAME "Ubuntu") ENDIF () ENDIF () - MESSAGE("Run this command to install system(${OS_DISTRIB_NAME}) dependencies libraries:") IF (${OS_DISTRIB_NAME} MATCHES "CentOS") MESSAGE(FATAL_ERROR "$sudo yum -y install libcurl-devel openssl-devel libjson-c-devel") ELSEIF (${OS_DISTRIB_NAME} MATCHES "Ubuntu") - MESSAGE(FATAL_ERROR "$sudo apt -y install libcurl4-openssl-dev libssl-dev libjson-c-dev zlib1g-dev libmbedtls-dev") + MESSAGE(FATAL_ERROR "$sudo apt-get -y install libcurl4-openssl-dev libssl-dev libjson-c-dev libuv1-dev zlib1g-dev libmbedtls-dev") ENDIF () ELSE () MESSAGE(FATAL_ERROR "Run command to install system dependencies libraries [libcurl,libssl,libcrypto] by yourself") diff --git a/depend/third_libs.cmake b/depend/third_libs.cmake index 7cd8454..2e5d114 100644 --- a/depend/third_libs.cmake +++ b/depend/third_libs.cmake @@ -5,29 +5,41 @@ ENDIF () INCLUDE(FetchContent) -PKG_SEARCH_MODULE(LIBCURL REQUIRED libcurl) -PKG_SEARCH_MODULE(LIBSSL REQUIRED libssl) -PKG_SEARCH_MODULE(LIBCRYPTO REQUIRED libcrypto) +PKG_SEARCH_MODULE(LIBUV QUIET libuv) +PKG_SEARCH_MODULE(LIBCURL QUIET libcurl) +PKG_SEARCH_MODULE(LIBSSL QUIET libssl) +PKG_SEARCH_MODULE(LIBCRYPTO QUIET libcrypto) +IF (USED_HTTP_CLIENT) + PKG_SEARCH_MODULE(LIBZ QUIET libz) +ENDIF () -IF ((NOT LIBCRYPTO_FOUND) OR (NOT LIBSSL_FOUND) OR (NOT LIBCURL_FOUND)) +IF ((NOT LIBCRYPTO_FOUND) OR (NOT LIBSSL_FOUND) OR (NOT LIBCURL_FOUND) + OR (NOT LIBUV_FOUND)) LINUX_INSTALL_SYSTEM_PACKAGE() ENDIF () +IF (USED_HTTP_CLIENT) + IF ((NOT LIBUV_FOUND)) + LINUX_INSTALL_SYSTEM_PACKAGE() + ENDIF() +ENDIF () + LIST(APPEND COMMON_LIBS "${LIBCURL_LDFLAGS} ${LIBSSL_LDFLAGS} ${LIBCRYPTO_LDFLAGS}") IF (USED_SQLITE AND LIBSQLITE3_FOUND) LIST(APPEND COMMON_LIBS "${LIBSQLITE3_LDFLAGS}") -ENDIF() +ENDIF () LIST(APPEND COMMON_LIBS "-lm -lpthread") -PKG_SEARCH_MODULE(LIBUV QUIET libuv) PKG_SEARCH_MODULE(LIBCONFIG QUIET libconfig) -PKG_SEARCH_MODULE(LIBZ QUIET libz) -FIND_LIBRARY(LIBLLHTTP llhttp PATHS "/usr/local/lib") -FIND_LIBRARY(LIBTLSUV tlsuv PATHS "/usr/local/lib") FIND_LIBRARY(LIBZLOG zlog PATHS "/usr/local/lib") +IF (USED_HTTP_CLIENT) + FIND_LIBRARY(LIBLLHTTP llhttp PATHS "/usr/local/lib") + FIND_LIBRARY(LIBTLSUV tlsuv PATHS "/usr/local/lib") +ENDIF () + IF (USED_JSON_VALIDATE) PKG_CHECK_MODULES(LIBJSON-C QUIET json-c>=0.13) @@ -35,32 +47,22 @@ IF (USED_JSON_VALIDATE) FETCHCONTENT_DECLARE(libjson-c URL file://${CMAKE_SOURCE_DIR}/depend/json-c-0.16.tar.gz URL_MD5 a549a833f886d427148fb5710c3e613e - ) + ) ENDIF () ENDIF () -IF (NOT LIBUV_FOUND) - FETCHCONTENT_DECLARE(libuv - URL file://${CMAKE_SOURCE_DIR}/depend/libuv-1.49.2.tar.gz - URL_MD5 b6aa4c4d5a8be9822a50ee9b6cfd00d2) -ENDIF () +IF (USED_HTTP_CLIENT) + IF (NOT LIBLLHTTP_FOUND) + FETCHCONTENT_DECLARE(llhttp + URL file://${CMAKE_SOURCE_DIR}/depend/llhttp-release-v9.2.1.tar.gz + URL_MD5 546887e9b5760d9a7406c73eef01f522) + ENDIF () -IF (NOT LIBZ_FOUND) - FETCHCONTENT_DECLARE(libz - URL file://${CMAKE_SOURCE_DIR}/depend/zlib-1.3.1.tar.gz - URL_MD5 ddb17dbbf2178807384e57ba0d81e6a1) -ENDIF () - -IF (NOT LIBLLHTTP_FOUND) - FETCHCONTENT_DECLARE(llhttp - URL file://${CMAKE_SOURCE_DIR}/depend/llhttp-release-v9.2.1.tar.gz - URL_MD5 546887e9b5760d9a7406c73eef01f522) -ENDIF () - -IF (NOT LIBTLSUV_FOUND) - FETCHCONTENT_DECLARE(tlsuv - URL file://${CMAKE_SOURCE_DIR}/depend/tlsuv-0.32.9.tar.gz - URL_MD5 a6706d2dd4d6eae0ba1a3cd2c7c6292a) + IF (NOT LIBTLSUV_FOUND) + FETCHCONTENT_DECLARE(tlsuv + URL file://${CMAKE_SOURCE_DIR}/depend/tlsuv-0.32.9.tar.gz + URL_MD5 7977b3c834928c46f9cf072465710a84) + ENDIF () ENDIF () IF (NOT LIBCONFIG_FOUND) @@ -75,28 +77,22 @@ IF (LIBZLOG STREQUAL "LIBZLOG-NOTFOUND") URL_MD5 3fbac790d550b9d95fbd1312d674b9c5) ENDIF () -IF (NOT LIBUV_FOUND) - FETCHCONTENT_MAKEAVAILABLE(libuv) -ENDIF () - IF (NOT LIBCONFIG_FOUND) FETCHCONTENT_MAKEAVAILABLE(libconfig) ENDIF () -IF (NOT LIBZ_FOUND) - FETCHCONTENT_MAKEAVAILABLE(libz) -ENDIF () - IF (${LIBZLOG} STREQUAL "LIBZLOG-NOTFOUND") FETCHCONTENT_MAKEAVAILABLE(zlog) ENDIF () -IF (${LIBLLHTTP} STREQUAL "LIBLLHTTP-NOTFOUND") - FETCHCONTENT_MAKEAVAILABLE(llhttp) -ENDIF () +IF (USED_HTTP_CLIENT) + IF (${LIBLLHTTP} STREQUAL "LIBLLHTTP-NOTFOUND") + FETCHCONTENT_MAKEAVAILABLE(llhttp) + ENDIF () -IF (${LIBTLSUV} STREQUAL "LIBTLSUV-NOTFOUND") - FETCHCONTENT_MAKEAVAILABLE(tlsuv) + IF (${LIBTLSUV} STREQUAL "LIBTLSUV-NOTFOUND") + FETCHCONTENT_MAKEAVAILABLE(tlsuv) + ENDIF () ENDIF () IF (USED_JSON_VALIDATE) @@ -105,34 +101,6 @@ IF (USED_JSON_VALIDATE) ENDIF () ENDIF () -IF (NOT LIBZ_FOUND) - MESSAGE(STATUS "libz not found, will be used source code to build it ...") - FETCHCONTENT_GETPROPERTIES(libz) - IF (NOT libz_POPULATED) - FETCHCONTENT_POPULATE(libz) - ADD_SUBDIRECTORY(${libz_SOURCE_DIR} ${libz_BINARY_DIR}) - ENDIF () - INCLUDE_DIRECTORIES(${libz_SOURCE_DIR}/include) - LIST(APPEND COMMON_LIBS "zlibstatic") -ELSE () - MESSAGE(STATUS "libz found ${LIBZ_VERSION} at ${LIBZ_LIBRARY_DIRS}") - LIST(APPEND COMMON_LIBS "${LIBZ_LDFLAGS}") -ENDIF () - -IF (NOT LIBUV_FOUND) - MESSAGE(STATUS "libuv not found, will be used source code to build it ...") - FETCHCONTENT_GETPROPERTIES(libuv) - IF (NOT libuv_POPULATED) - FETCHCONTENT_POPULATE(libuv) - ADD_SUBDIRECTORY(${libuv_SOURCE_DIR} ${libuv_BINARY_DIR}) - ENDIF () - INCLUDE_DIRECTORIES(${libuv_SOURCE_DIR}/include) - LIST(APPEND COMMON_LIBS "uv_a") -ELSE () - MESSAGE(STATUS "libuv found ${LIBUV_VERSION} at ${LIBUV_LIBRARY_DIRS}") - LIST(APPEND COMMON_LIBS "${LIBUV_LDFLAGS}") -ENDIF () - IF (NOT LIBCONFIG_FOUND) MESSAGE(STATUS "libconfig not found, will be used source code to build it ...") FETCHCONTENT_GETPROPERTIES(libconfig) @@ -161,33 +129,35 @@ ELSE () LIST(APPEND COMMON_LIBS "${LIBZLOG}") ENDIF () -IF (LIBLLHTTP STREQUAL "LIBLLHTTP-NOTFOUND") - MESSAGE(STATUS "llhttp not found, will be used source code to build it ...") - FETCHCONTENT_GETPROPERTIES(llhttp) - IF (NOT llhttp_POPULATED) - FETCHCONTENT_POPULATE(llhttp) - ADD_SUBDIRECTORY(${llhttp_SOURCE_DIR} ${llhttp_BINARY_DIR}) +IF (USED_HTTP_CLIENT) + IF (LIBLLHTTP STREQUAL "LIBLLHTTP-NOTFOUND") + MESSAGE(STATUS "llhttp not found, will be used source code to build it ...") + FETCHCONTENT_GETPROPERTIES(llhttp) + IF (NOT llhttp_POPULATED) + FETCHCONTENT_POPULATE(llhttp) + ADD_SUBDIRECTORY(${llhttp_SOURCE_DIR} ${llhttp_BINARY_DIR}) + ENDIF () + + INCLUDE_DIRECTORIES(${llhttp_SOURCE_DIR}/include) + LIST(APPEND COMMON_LIBS "llhttp_static") + ELSE () + MESSAGE(STATUS "llhttp found of ${LIBLLHTTP}") + LIST(APPEND COMMON_LIBS "${LIBLLHTTP}") ENDIF () - INCLUDE_DIRECTORIES(${llhttp_SOURCE_DIR}/include) - LIST(APPEND COMMON_LIBS "llhttp_static") -ELSE () - MESSAGE(STATUS "llhttp found of ${LIBLLHTTP}") - LIST(APPEND COMMON_LIBS "${LIBLLHTTP}") -ENDIF () - -IF (LIBTLSUV STREQUAL "LIBTLSUV-NOTFOUND") - MESSAGE(STATUS "tlsuv not found, will be used source code to build it ...") - FETCHCONTENT_GETPROPERTIES(tlsuv) - IF (NOT tlsuv_POPULATED) - FETCHCONTENT_POPULATE(tlsuv) - ADD_SUBDIRECTORY(${tlsuv_SOURCE_DIR} ${tlsuv_BINARY_DIR}) + IF (LIBTLSUV STREQUAL "LIBTLSUV-NOTFOUND") + MESSAGE(STATUS "tlsuv not found, will be used source code to build it ...") + FETCHCONTENT_GETPROPERTIES(tlsuv) + IF (NOT tlsuv_POPULATED) + FETCHCONTENT_POPULATE(tlsuv) + ADD_SUBDIRECTORY(${tlsuv_SOURCE_DIR} ${tlsuv_BINARY_DIR}) + ENDIF () + INCLUDE_DIRECTORIES(${tlsuv_SOURCE_DIR}/src) + LIST(APPEND COMMON_LIBS "tlsuv") + ELSE () + MESSAGE(STATUS "tlsuv found of ${LIBTLSUV}") + LIST(APPEND COMMON_LIBS "${LIBTLSUV}") ENDIF () - INCLUDE_DIRECTORIES(${tlsuv_SOURCE_DIR}/src) - LIST(APPEND COMMON_LIBS "tlsuv") -ELSE () - MESSAGE(STATUS "tlsuv found of ${LIBTLSUV}") - LIST(APPEND COMMON_LIBS "${LIBTLSUV}") ENDIF () IF (USED_JSON_VALIDATE) diff --git a/depend/tlsuv-0.32.9.tar.gz b/depend/tlsuv-0.32.9.tar.gz index 941c8e5..8b68be3 100644 Binary files a/depend/tlsuv-0.32.9.tar.gz and b/depend/tlsuv-0.32.9.tar.gz differ diff --git a/depend/zlib-1.3.1.tar.gz b/depend/zlib-1.3.1.tar.gz deleted file mode 100644 index 9c29e94..0000000 Binary files a/depend/zlib-1.3.1.tar.gz and /dev/null differ