OCT 1. libuv、libz等库设置为系统依赖项

This commit is contained in:
xajhuang 2024-12-12 14:36:54 +08:00
parent 6caa1483b6
commit 728bcf2f7a
6 changed files with 77 additions and 101 deletions

View File

@ -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")

Binary file not shown.

View File

@ -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")

View File

@ -5,14 +5,25 @@ 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)
@ -21,12 +32,13 @@ 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(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")
FIND_LIBRARY(LIBZLOG zlog PATHS "/usr/local/lib")
ENDIF ()
IF (USED_JSON_VALIDATE)
PKG_CHECK_MODULES(LIBJSON-C QUIET json-c>=0.13)
@ -39,18 +51,7 @@ IF (USED_JSON_VALIDATE)
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 (NOT LIBZ_FOUND)
FETCHCONTENT_DECLARE(libz
URL file://${CMAKE_SOURCE_DIR}/depend/zlib-1.3.1.tar.gz
URL_MD5 ddb17dbbf2178807384e57ba0d81e6a1)
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
@ -60,7 +61,8 @@ ENDIF ()
IF (NOT LIBTLSUV_FOUND)
FETCHCONTENT_DECLARE(tlsuv
URL file://${CMAKE_SOURCE_DIR}/depend/tlsuv-0.32.9.tar.gz
URL_MD5 a6706d2dd4d6eae0ba1a3cd2c7c6292a)
URL_MD5 7977b3c834928c46f9cf072465710a84)
ENDIF ()
ENDIF ()
IF (NOT LIBCONFIG_FOUND)
@ -75,22 +77,15 @@ 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 (USED_HTTP_CLIENT)
IF (${LIBLLHTTP} STREQUAL "LIBLLHTTP-NOTFOUND")
FETCHCONTENT_MAKEAVAILABLE(llhttp)
ENDIF ()
@ -98,6 +93,7 @@ ENDIF ()
IF (${LIBTLSUV} STREQUAL "LIBTLSUV-NOTFOUND")
FETCHCONTENT_MAKEAVAILABLE(tlsuv)
ENDIF ()
ENDIF ()
IF (USED_JSON_VALIDATE)
IF (NOT LIBJSON-C_FOUND)
@ -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,6 +129,7 @@ ELSE ()
LIST(APPEND COMMON_LIBS "${LIBZLOG}")
ENDIF ()
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)
@ -189,6 +158,7 @@ ELSE ()
MESSAGE(STATUS "tlsuv found of ${LIBTLSUV}")
LIST(APPEND COMMON_LIBS "${LIBTLSUV}")
ENDIF ()
ENDIF ()
IF (USED_JSON_VALIDATE)
IF (NOT LIBJSON-C_FOUND)

Binary file not shown.

Binary file not shown.