From ffe78c97196f92872853caf9a497d1a291c19032 Mon Sep 17 00:00:00 2001 From: huangxin Date: Tue, 17 Jan 2023 16:22:53 +0800 Subject: [PATCH] =?UTF-8?q?OCT=201.=20=E5=A2=9E=E5=8A=A0=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E5=BA=93=E6=A3=80=E6=9F=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + depend/system_libs.cmake | 27 +++++++++++++++++++++++++++ srcs/CMakeLists.txt | 22 +++++++++++++--------- 3 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 depend/system_libs.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d7f653e..d997ae4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR) +INCLUDE(depend/system_libs.cmake) SET(VCPE_VERSION "1.0.1") PROJECT(vCPE VERSION "${VCPE_VERSION}") diff --git a/depend/system_libs.cmake b/depend/system_libs.cmake new file mode 100644 index 0000000..be8c65e --- /dev/null +++ b/depend/system_libs.cmake @@ -0,0 +1,27 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR) + +FUNCTION(LINUX_INSTALL_SYSTEM_PACKAGE) + SET(OS_RELEASE_FILE "/etc/os-release") + SET(OS_DISTRIB_NAME "") + + 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") + SET(OS_DISTRIB_NAME "CentOS") + ELSE () + STRING(FIND ${OS_RELEASE_NAME} "Ubuntu" SUB_OUT) + + IF (${SUB_OUT} MATCHES "6") + 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(ERROR "$sudo yum -y install libcurl-devel czmq-devel openssl-devel uuid-devel") + ELSEIF (${OS_DISTRIB_NAME} MATCHES "Ubuntu") + MESSAGE(ERROR "$sudo -S apt -y install libcurl4-openssl-dev libczmq-dev libssl-dev uuid-dev") + ENDIF () + ENDIF () +ENDFUNCTION(LINUX_INSTALL_SYSTEM_PACKAGE) \ No newline at end of file diff --git a/srcs/CMakeLists.txt b/srcs/CMakeLists.txt index 63fb87f..50ea6a6 100644 --- a/srcs/CMakeLists.txt +++ b/srcs/CMakeLists.txt @@ -6,22 +6,26 @@ ENDIF () PROJECT(${PROJECT_TARGET}) -INCLUDE(ExternalProject) - # 判断依赖库是否存在 FIND_PACKAGE(PkgConfig) -PKG_SEARCH_MODULE(LIBCURL REQUIRED libcurl) -PKG_SEARCH_MODULE(LIBSSL REQUIRED libssl) -PKG_SEARCH_MODULE(LIBCRYPTO REQUIRED libcrypto) +PKG_SEARCH_MODULE(LIBCURL QUIET libcurl) +PKG_SEARCH_MODULE(LIBSSL QUIET libssl) +PKG_SEARCH_MODULE(LIBCRYPTO QUIET libcrypto) +PKG_SEARCH_MODULE(LIBZMQ QUIET libzmq) +FIND_LIBRARY(LIBUUID uuid QUIET) + +IF ((NOT LIBZMQ_FOUND) OR (NOT LIBCRYPTO_FOUND) OR (NOT LIBSSL_FOUND) OR (NOT LIBCURL_FOUND) + OR (${LIBUUID} MATCHES "LIBUUID-NOTFOUND")) + LINUX_INSTALL_SYSTEM_PACKAGE() +ENDIF () + PKG_SEARCH_MODULE(LIBUV REQUIRED libuv) PKG_SEARCH_MODULE(LIBCONFIG REQUIRED libconfig) -PKG_SEARCH_MODULE(LIBZMQ REQUIRED libzmq) FIND_LIBRARY(LIBZLOG zlog REQUIRED) -FIND_LIBRARY(LIBUUID uuid REQUIRED) -LIST(APPEND COMMON_LIBS "${LIBUV_LDFLAGS} ${LIBCONFIG_LDFLAGS} ${LIBCURL_LDFLAGS} ${LIBSSL_LDFLAGS} ${LIBCRYPTO_LDFLAGS}") -LIST(APPEND COMMON_LIBS "${LIBZMQ_LDFLAGS} ${LIBZLOG} ${LIBUUID}") +LIST(APPEND COMMON_LIBS "${LIBUV_LDFLAGS} ${LIBCURL_LDFLAGS} ${LIBSSL_LDFLAGS} ${LIBCRYPTO_LDFLAGS}") +LIST(APPEND COMMON_LIBS "${LIBCONFIG_LDFLAGS} ${LIBZMQ_LDFLAGS} ${LIBZLOG} ${LIBUUID}") LIST(APPEND COMMON_LIBS "-lm -lpthread") ADD_DEFINITIONS(${COMMON_DEFINE})