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) INCLUDE(CMakeDependentOption)
OPTION(USED_HTTP_SVR "Build-in http(s) server support" OFF) 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(USED_JSON_VALIDATE "Support json protocol field validate" OFF)
OPTION(BUILD_TESTING "Enable tests" OFF) OPTION(BUILD_TESTING "Enable tests" OFF)
@ -93,6 +94,13 @@ ELSE ()
MESSAGE("-- Unselect Option USED_HTTP_SVR") MESSAGE("-- Unselect Option USED_HTTP_SVR")
ENDIF () 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) IF (USED_SQLITE)
MESSAGE("++ Select Option USED_SQLITE") MESSAGE("++ Select Option USED_SQLITE")
LIST(APPEND COMMON_DEFINE "-DSQLITE_ON") 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}) IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND EXISTS ${OS_RELEASE_FILE})
FILE(STRINGS ${OS_RELEASE_FILE} OS_RELEASE_NAME LIMIT_COUNT 1) FILE(STRINGS ${OS_RELEASE_FILE} OS_RELEASE_NAME LIMIT_COUNT 1)
STRING(FIND ${OS_RELEASE_NAME} "CentOS" SUB_OUT) STRING(FIND ${OS_RELEASE_NAME} "CentOS" SUB_OUT)
IF (${SUB_OUT} MATCHES "6") IF (NOT ${SUB_OUT} MATCHES "-1")
SET(OS_DISTRIB_NAME "CentOS") SET(OS_DISTRIB_NAME "CentOS")
ELSE () ELSE ()
STRING(FIND ${OS_RELEASE_NAME} "Ubuntu" SUB_OUT) STRING(FIND ${OS_RELEASE_NAME} "Ubuntu" SUB_OUT)
IF (NOT ${SUB_OUT} MATCHES "-1")
IF (${SUB_OUT} MATCHES "6")
SET(OS_DISTRIB_NAME "Ubuntu") SET(OS_DISTRIB_NAME "Ubuntu")
ENDIF () ENDIF ()
ENDIF () ENDIF ()
MESSAGE("Run this command to install system(${OS_DISTRIB_NAME}) dependencies libraries:") MESSAGE("Run this command to install system(${OS_DISTRIB_NAME}) dependencies libraries:")
IF (${OS_DISTRIB_NAME} MATCHES "CentOS") IF (${OS_DISTRIB_NAME} MATCHES "CentOS")
MESSAGE(FATAL_ERROR "$sudo yum -y install libcurl-devel openssl-devel libjson-c-devel") MESSAGE(FATAL_ERROR "$sudo yum -y install libcurl-devel openssl-devel libjson-c-devel")
ELSEIF (${OS_DISTRIB_NAME} MATCHES "Ubuntu") 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 () ENDIF ()
ELSE () ELSE ()
MESSAGE(FATAL_ERROR "Run command to install system dependencies libraries [libcurl,libssl,libcrypto] by yourself") MESSAGE(FATAL_ERROR "Run command to install system dependencies libraries [libcurl,libssl,libcrypto] by yourself")

View File

@ -5,29 +5,41 @@ ENDIF ()
INCLUDE(FetchContent) INCLUDE(FetchContent)
PKG_SEARCH_MODULE(LIBCURL REQUIRED libcurl) PKG_SEARCH_MODULE(LIBUV QUIET libuv)
PKG_SEARCH_MODULE(LIBSSL REQUIRED libssl) PKG_SEARCH_MODULE(LIBCURL QUIET libcurl)
PKG_SEARCH_MODULE(LIBCRYPTO REQUIRED libcrypto) 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() LINUX_INSTALL_SYSTEM_PACKAGE()
ENDIF () 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}") LIST(APPEND COMMON_LIBS "${LIBCURL_LDFLAGS} ${LIBSSL_LDFLAGS} ${LIBCRYPTO_LDFLAGS}")
IF (USED_SQLITE AND LIBSQLITE3_FOUND) IF (USED_SQLITE AND LIBSQLITE3_FOUND)
LIST(APPEND COMMON_LIBS "${LIBSQLITE3_LDFLAGS}") LIST(APPEND COMMON_LIBS "${LIBSQLITE3_LDFLAGS}")
ENDIF() ENDIF ()
LIST(APPEND COMMON_LIBS "-lm -lpthread") LIST(APPEND COMMON_LIBS "-lm -lpthread")
PKG_SEARCH_MODULE(LIBUV QUIET libuv)
PKG_SEARCH_MODULE(LIBCONFIG QUIET libconfig) 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") 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) IF (USED_JSON_VALIDATE)
PKG_CHECK_MODULES(LIBJSON-C QUIET json-c>=0.13) PKG_CHECK_MODULES(LIBJSON-C QUIET json-c>=0.13)
@ -35,32 +47,22 @@ IF (USED_JSON_VALIDATE)
FETCHCONTENT_DECLARE(libjson-c FETCHCONTENT_DECLARE(libjson-c
URL file://${CMAKE_SOURCE_DIR}/depend/json-c-0.16.tar.gz URL file://${CMAKE_SOURCE_DIR}/depend/json-c-0.16.tar.gz
URL_MD5 a549a833f886d427148fb5710c3e613e URL_MD5 a549a833f886d427148fb5710c3e613e
) )
ENDIF () ENDIF ()
ENDIF () ENDIF ()
IF (NOT LIBUV_FOUND) IF (USED_HTTP_CLIENT)
FETCHCONTENT_DECLARE(libuv IF (NOT LIBLLHTTP_FOUND)
URL file://${CMAKE_SOURCE_DIR}/depend/libuv-1.49.2.tar.gz FETCHCONTENT_DECLARE(llhttp
URL_MD5 b6aa4c4d5a8be9822a50ee9b6cfd00d2) URL file://${CMAKE_SOURCE_DIR}/depend/llhttp-release-v9.2.1.tar.gz
ENDIF () URL_MD5 546887e9b5760d9a7406c73eef01f522)
ENDIF ()
IF (NOT LIBZ_FOUND) IF (NOT LIBTLSUV_FOUND)
FETCHCONTENT_DECLARE(libz FETCHCONTENT_DECLARE(tlsuv
URL file://${CMAKE_SOURCE_DIR}/depend/zlib-1.3.1.tar.gz URL file://${CMAKE_SOURCE_DIR}/depend/tlsuv-0.32.9.tar.gz
URL_MD5 ddb17dbbf2178807384e57ba0d81e6a1) URL_MD5 7977b3c834928c46f9cf072465710a84)
ENDIF () 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)
ENDIF () ENDIF ()
IF (NOT LIBCONFIG_FOUND) IF (NOT LIBCONFIG_FOUND)
@ -75,28 +77,22 @@ IF (LIBZLOG STREQUAL "LIBZLOG-NOTFOUND")
URL_MD5 3fbac790d550b9d95fbd1312d674b9c5) URL_MD5 3fbac790d550b9d95fbd1312d674b9c5)
ENDIF () ENDIF ()
IF (NOT LIBUV_FOUND)
FETCHCONTENT_MAKEAVAILABLE(libuv)
ENDIF ()
IF (NOT LIBCONFIG_FOUND) IF (NOT LIBCONFIG_FOUND)
FETCHCONTENT_MAKEAVAILABLE(libconfig) FETCHCONTENT_MAKEAVAILABLE(libconfig)
ENDIF () ENDIF ()
IF (NOT LIBZ_FOUND)
FETCHCONTENT_MAKEAVAILABLE(libz)
ENDIF ()
IF (${LIBZLOG} STREQUAL "LIBZLOG-NOTFOUND") IF (${LIBZLOG} STREQUAL "LIBZLOG-NOTFOUND")
FETCHCONTENT_MAKEAVAILABLE(zlog) FETCHCONTENT_MAKEAVAILABLE(zlog)
ENDIF () ENDIF ()
IF (${LIBLLHTTP} STREQUAL "LIBLLHTTP-NOTFOUND") IF (USED_HTTP_CLIENT)
FETCHCONTENT_MAKEAVAILABLE(llhttp) IF (${LIBLLHTTP} STREQUAL "LIBLLHTTP-NOTFOUND")
ENDIF () FETCHCONTENT_MAKEAVAILABLE(llhttp)
ENDIF ()
IF (${LIBTLSUV} STREQUAL "LIBTLSUV-NOTFOUND") IF (${LIBTLSUV} STREQUAL "LIBTLSUV-NOTFOUND")
FETCHCONTENT_MAKEAVAILABLE(tlsuv) FETCHCONTENT_MAKEAVAILABLE(tlsuv)
ENDIF ()
ENDIF () ENDIF ()
IF (USED_JSON_VALIDATE) IF (USED_JSON_VALIDATE)
@ -105,34 +101,6 @@ IF (USED_JSON_VALIDATE)
ENDIF () ENDIF ()
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) IF (NOT LIBCONFIG_FOUND)
MESSAGE(STATUS "libconfig not found, will be used source code to build it ...") MESSAGE(STATUS "libconfig not found, will be used source code to build it ...")
FETCHCONTENT_GETPROPERTIES(libconfig) FETCHCONTENT_GETPROPERTIES(libconfig)
@ -161,33 +129,35 @@ ELSE ()
LIST(APPEND COMMON_LIBS "${LIBZLOG}") LIST(APPEND COMMON_LIBS "${LIBZLOG}")
ENDIF () ENDIF ()
IF (LIBLLHTTP STREQUAL "LIBLLHTTP-NOTFOUND") IF (USED_HTTP_CLIENT)
MESSAGE(STATUS "llhttp not found, will be used source code to build it ...") IF (LIBLLHTTP STREQUAL "LIBLLHTTP-NOTFOUND")
FETCHCONTENT_GETPROPERTIES(llhttp) MESSAGE(STATUS "llhttp not found, will be used source code to build it ...")
IF (NOT llhttp_POPULATED) FETCHCONTENT_GETPROPERTIES(llhttp)
FETCHCONTENT_POPULATE(llhttp) IF (NOT llhttp_POPULATED)
ADD_SUBDIRECTORY(${llhttp_SOURCE_DIR} ${llhttp_BINARY_DIR}) 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 () ENDIF ()
INCLUDE_DIRECTORIES(${llhttp_SOURCE_DIR}/include) IF (LIBTLSUV STREQUAL "LIBTLSUV-NOTFOUND")
LIST(APPEND COMMON_LIBS "llhttp_static") MESSAGE(STATUS "tlsuv not found, will be used source code to build it ...")
ELSE () FETCHCONTENT_GETPROPERTIES(tlsuv)
MESSAGE(STATUS "llhttp found of ${LIBLLHTTP}") IF (NOT tlsuv_POPULATED)
LIST(APPEND COMMON_LIBS "${LIBLLHTTP}") FETCHCONTENT_POPULATE(tlsuv)
ENDIF () ADD_SUBDIRECTORY(${tlsuv_SOURCE_DIR} ${tlsuv_BINARY_DIR})
ENDIF ()
IF (LIBTLSUV STREQUAL "LIBTLSUV-NOTFOUND") INCLUDE_DIRECTORIES(${tlsuv_SOURCE_DIR}/src)
MESSAGE(STATUS "tlsuv not found, will be used source code to build it ...") LIST(APPEND COMMON_LIBS "tlsuv")
FETCHCONTENT_GETPROPERTIES(tlsuv) ELSE ()
IF (NOT tlsuv_POPULATED) MESSAGE(STATUS "tlsuv found of ${LIBTLSUV}")
FETCHCONTENT_POPULATE(tlsuv) LIST(APPEND COMMON_LIBS "${LIBTLSUV}")
ADD_SUBDIRECTORY(${tlsuv_SOURCE_DIR} ${tlsuv_BINARY_DIR})
ENDIF () 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 () ENDIF ()
IF (USED_JSON_VALIDATE) IF (USED_JSON_VALIDATE)

Binary file not shown.

Binary file not shown.