OCT 1. 增加第三方依赖库源码自动编译功能

This commit is contained in:
huangxin 2023-01-30 10:13:38 +08:00
parent a62f7436a8
commit 036f589fe7
8 changed files with 85 additions and 11 deletions

Binary file not shown.

View File

@ -19,11 +19,11 @@ FUNCTION(LINUX_INSTALL_SYSTEM_PACKAGE)
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(ERROR "$sudo yum -y install libcurl-devel czmq-devel openssl-devel uuid-devel") MESSAGE(FATAL_ERROR "$sudo yum -y install libcurl-devel czmq-devel openssl-devel uuid-devel")
ELSEIF (${OS_DISTRIB_NAME} MATCHES "Ubuntu") ELSEIF (${OS_DISTRIB_NAME} MATCHES "Ubuntu")
MESSAGE(ERROR "$sudo -S apt -y install libcurl4-openssl-dev libczmq-dev libssl-dev uuid-dev") MESSAGE(FATAL_ERROR "$sudo -S apt -y install libcurl4-openssl-dev libczmq-dev libssl-dev uuid-dev")
ENDIF () ENDIF ()
ELSE() ELSE()
MESSAGE(ERROR "Run command to install system dependencies libraries by yourself") MESSAGE(FATAL_ERROR "Run command to install system dependencies libraries by yourself")
ENDIF () ENDIF ()
ENDFUNCTION(LINUX_INSTALL_SYSTEM_PACKAGE) ENDFUNCTION(LINUX_INSTALL_SYSTEM_PACKAGE)

75
depend/third_libs.cmake Normal file
View File

@ -0,0 +1,75 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.14)
INCLUDE(FetchContent)
PKG_SEARCH_MODULE(LIBUV QUIET libuv)
PKG_SEARCH_MODULE(LIBCONFIG QUIET libconfig)
FIND_LIBRARY(LIBZLOG zlog PATHS "/usr/local/lib")
IF (NOT LIBUV_FOUND)
FETCHCONTENT_DECLARE(libuv
URL file://${CMAKE_SOURCE_DIR}/depend/libuv-v1.44.2.tar.gz
URL_MD5 0addbddcb1098e2c1c99f03f0108e1e7)
ENDIF ()
IF (NOT LIBCONFIG_FOUND)
FETCHCONTENT_DECLARE(libconfig
URL file://${CMAKE_SOURCE_DIR}/depend/libconfig-1.7.3.tar.gz
URL_MD5 8f96910eee26118258ac8d4cd128a0b2)
ENDIF ()
IF (LIBZLOG STREQUAL "LIBZLOG-NOTFOUND")
FETCHCONTENT_DECLARE(zlog
URL file://${CMAKE_SOURCE_DIR}/depend/zlog-1.2.16.tar.gz
URL_MD5 74ebc6fc119d756a13e692b734642ea6)
ENDIF ()
IF (NOT LIBUV_FOUND)
FETCHCONTENT_MAKEAVAILABLE(libuv)
ENDIF ()
IF (NOT LIBCONFIG_FOUND)
FETCHCONTENT_MAKEAVAILABLE(libconfig)
ENDIF ()
IF (LIBZLOG STREQUAL "LIBZLOG-NOTFOUND")
FETCHCONTENT_MAKEAVAILABLE(zlog)
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 ()
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)
IF (NOT libconfig_POPULATED)
FETCHCONTENT_POPULATE(libconfig)
ADD_SUBDIRECTORY(${libconfig_SOURCE_DIR} ${libconfig_BINARY_DIR})
ENDIF ()
LIST(APPEND COMMON_LIBS "config")
ELSE ()
MESSAGE(STATUS "libconfig found ${LIBCONFIG_VERSION} at ${LIBCONFIG_LIBRARY_DIRS}")
LIST(APPEND COMMON_LIBS "${LIBCONFIG_LDFLAGS}")
ENDIF ()
IF (LIBZLOG STREQUAL "LIBZLOG-NOTFOUND")
MESSAGE(STATUS "zlog not found, will be used source code to build it ...")
FETCHCONTENT_GETPROPERTIES(zlog)
IF (NOT zlog_POPULATED)
FETCHCONTENT_POPULATE(zlog)
ADD_SUBDIRECTORY(${zlog_SOURCE_DIR} ${zlog_BINARY_DIR})
ENDIF ()
LIST(APPEND COMMON_LIBS "zlog")
ELSE ()
MESSAGE(STATUS "zlog found of ${LIBZLOG}")
LIST(APPEND COMMON_LIBS "${LIBZLOG}")
ENDIF ()

Binary file not shown.

BIN
depend/zlog-1.2.16.tar.gz Normal file

Binary file not shown.

View File

@ -20,12 +20,12 @@ IF ((NOT LIBZMQ_FOUND) OR (NOT LIBCRYPTO_FOUND) OR (NOT LIBSSL_FOUND) OR (NOT LI
LINUX_INSTALL_SYSTEM_PACKAGE() LINUX_INSTALL_SYSTEM_PACKAGE()
ENDIF () ENDIF ()
PKG_SEARCH_MODULE(LIBUV REQUIRED libuv) SET(COMMON_LIBS "")
PKG_SEARCH_MODULE(LIBCONFIG REQUIRED libconfig)
FIND_LIBRARY(LIBZLOG zlog REQUIRED)
LIST(APPEND COMMON_LIBS "${LIBUV_LDFLAGS} ${LIBCURL_LDFLAGS} ${LIBSSL_LDFLAGS} ${LIBCRYPTO_LDFLAGS}") INCLUDE(../depend/third_libs.cmake)
LIST(APPEND COMMON_LIBS "${LIBCONFIG_LDFLAGS} ${LIBZMQ_LDFLAGS} ${LIBZLOG} ${LIBUUID}")
LIST(APPEND COMMON_LIBS "${LIBCURL_LDFLAGS} ${LIBSSL_LDFLAGS} ${LIBCRYPTO_LDFLAGS}")
LIST(APPEND COMMON_LIBS "${LIBZMQ_LDFLAGS} ${LIBUUID}")
LIST(APPEND COMMON_LIBS "-lm -lpthread") LIST(APPEND COMMON_LIBS "-lm -lpthread")
ADD_DEFINITIONS(${COMMON_DEFINE}) ADD_DEFINITIONS(${COMMON_DEFINE})

View File

@ -34,6 +34,6 @@ INCLUDE_DIRECTORIES(. ./include)
#find_package(Threads REQUIRED) #find_package(Threads REQUIRED)
ADD_LIBRARY(haywire STATIC ${HW_SRC} ${HW_HEADS}) ADD_LIBRARY(haywire STATIC ${HW_SRC} ${HW_HEADS})
TARGET_LINK_LIBRARIES(haywire -luv -pthread) TARGET_LINK_LIBRARIES(haywire)

View File

@ -52,10 +52,9 @@ ENDIF ()
ADD_DEFINITIONS(${COMMON_DEFINE}) ADD_DEFINITIONS(${COMMON_DEFINE})
LINK_LIBRARIES(${COMMON_LIBS})
ADD_LIBRARY(${LIB_PROJECT_TARGET} ${C_SRC} ${C_HEADS}) ADD_LIBRARY(${LIB_PROJECT_TARGET} ${C_SRC} ${C_HEADS})
TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} haywire) TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} ${COMMON_LIBS} haywire)
IF (USED_OPENDHCPD) IF (USED_OPENDHCPD)
TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} opendhcpd) TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} opendhcpd)