From 37aec1337cfef2d03de78e9c454ad1683d6e3b80 Mon Sep 17 00:00:00 2001 From: ruanshudong Date: Sun, 8 Oct 2023 11:42:04 +0800 Subject: [PATCH] when compiler, gzip use download libz --- cmake/Thirdparty.cmake | 78 ++++++++++++++++++++++++++----- servant/makefile/tars-tools.cmake | 1 + util/src/tc_gzip.cpp | 2 +- 3 files changed, 69 insertions(+), 12 deletions(-) diff --git a/cmake/Thirdparty.cmake b/cmake/Thirdparty.cmake index 752ffad8..d5775704 100755 --- a/cmake/Thirdparty.cmake +++ b/cmake/Thirdparty.cmake @@ -1,26 +1,35 @@ option(TARS_MYSQL "option for mysql" ON) +if(UNIX) +option(TARS_GZIP "option for gzip" ON) +else(UNIX) +option(TARS_GZIP "option for gzip" OFF) +endif(UNIX) option(TARS_SSL "option for ssl" OFF) option(TARS_HTTP2 "option for http2" OFF) option(TARS_PROTOBUF "option for protocol" OFF) option(TARS_GPERF "option for gperf" OFF) -IF(UNIX) - FIND_PACKAGE(ZLIB) - IF(NOT ZLIB_FOUND) - SET(ERRORMSG "zlib library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.") - IF(CMAKE_SYSTEM_NAME MATCHES "Linux") - SET(ERRORMSG ${ERRORMSG} "On Debian/Ubuntu, package name is zlib1g-dev(apt-get install zlib1g-dev), on Redhat/Centos and derivates it is zlib-devel (yum install zlib-devel).") - ENDIF() - MESSAGE(FATAL_ERROR ${ERRORMSG}) - ENDIF() - -ENDIF(UNIX) +#IF(UNIX) +# FIND_PACKAGE(ZLIB) +# IF(NOT ZLIB_FOUND) +# SET(ERRORMSG "zlib library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.") +# IF(CMAKE_SYSTEM_NAME MATCHES "Linux") +# SET(ERRORMSG ${ERRORMSG} "On Debian/Ubuntu, package name is zlib1g-dev(apt-get install zlib1g-dev), on Redhat/Centos and derivates it is zlib-devel (yum install zlib-devel).") +# ENDIF() +# MESSAGE(FATAL_ERROR ${ERRORMSG}) +# ENDIF() +# +#ENDIF(UNIX) if (TARS_MYSQL) add_definitions(-DTARS_MYSQL=1) endif () +if (TARS_GZIP) + add_definitions(-DTARS_GZIP=1) +endif () + if (TARS_GPERF) add_definitions(-DTARS_GPERF=1) endif () @@ -42,6 +51,7 @@ endif () set(THIRDPARTY_PATH "${CMAKE_BINARY_DIR}/src") set(LIB_MYSQL) +set(LIB_GZIP) set(LIB_HTTP2) set(LIB_SSL) set(LIB_CRYPTO) @@ -295,6 +305,51 @@ if (TARS_MYSQL) endif () +if (TARS_GZIP) + set(GZIP_DIR_INC "${THIRDPARTY_PATH}/zlib/include") + set(GZIP_DIR_LIB "${THIRDPARTY_PATH}/zlib/lib") + include_directories(${GZIP_DIR_INC}) + link_directories(${GZIP_DIR_LIB}) + + if (WIN32) + set(LIB_GZIP "libz") + + ExternalProject_Add(ADD_${LIB_GZIP} + URL http://cdn.tarsyun.com/src/zlib-1.2.11.tar.gz + DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download + PREFIX ${CMAKE_BINARY_DIR} + INSTALL_DIR ${CMAKE_SOURCE_DIR} + CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/zlib + SOURCE_DIR ${CMAKE_BINARY_DIR}/src/zlib-lib + BUILD_IN_SOURCE 1 + BUILD_COMMAND ${CMAKE_COMMAND} --build . --config release + INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config release --target install + URL_MD5 1c9f62f0778697a09d36121ead88e08e + ) + + else () + set(LIB_GZIP "z") + + ExternalProject_Add(ADD_${LIB_GZIP} + URL http://cdn.tarsyun.com/src/zlib-1.2.11.tar.gz + DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download + PREFIX ${CMAKE_BINARY_DIR} + INSTALL_DIR ${CMAKE_SOURCE_DIR} + CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/zlib + SOURCE_DIR ${CMAKE_BINARY_DIR}/src/zlib-lib + BUILD_IN_SOURCE 1 + BUILD_COMMAND make + URL_MD5 1c9f62f0778697a09d36121ead88e08e + ) + + endif () + + INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/zlib/lib DESTINATION thirdparty) + INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/zlib/include/ DESTINATION thirdparty/include/zlib) + + add_dependencies(thirdparty ADD_${LIB_GZIP}) +endif () + if (TARS_HTTP2) set(NGHTTP2_DIR_INC "${THIRDPARTY_PATH}/nghttp2/include/") @@ -343,6 +398,7 @@ endif () message("----------------------------------------------------") message("TARS_MYSQL: ${TARS_MYSQL}") +message("TARS_GZIP: ${TARS_GZIP}") message("TARS_HTTP2: ${TARS_HTTP2}") message("TARS_SSL: ${TARS_SSL}") message("TARS_PROTOBUF: ${TARS_PROTOBUF}") diff --git a/servant/makefile/tars-tools.cmake b/servant/makefile/tars-tools.cmake index 26259331..a93b2eea 100755 --- a/servant/makefile/tars-tools.cmake +++ b/servant/makefile/tars-tools.cmake @@ -465,6 +465,7 @@ endif() message("-------------------------------------------------------------------------------------") message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}") message("CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}") +message("CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") message("PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}") message("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") message("PLATFORM: ${PLATFORM}") diff --git a/util/src/tc_gzip.cpp b/util/src/tc_gzip.cpp index e693a35e..8f1a43e1 100644 --- a/util/src/tc_gzip.cpp +++ b/util/src/tc_gzip.cpp @@ -16,7 +16,7 @@ #include "util/tc_gzip.h" -#if TARGET_PLATFORM_LINUX || TARGET_PLATFORM_IOS +#if TARS_GZIP #include #include