Skip to content

Commit

Permalink
when compiler, gzip use download libz
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanshudong committed Oct 8, 2023
1 parent 986c95e commit 37aec13
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 12 deletions.
78 changes: 67 additions & 11 deletions cmake/Thirdparty.cmake
Original file line number Diff line number Diff line change
@@ -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 ()
Expand All @@ -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)
Expand Down Expand Up @@ -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/")
Expand Down Expand Up @@ -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}")
Expand Down
1 change: 1 addition & 0 deletions servant/makefile/tars-tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion util/src/tc_gzip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "util/tc_gzip.h"

#if TARGET_PLATFORM_LINUX || TARGET_PLATFORM_IOS
#if TARS_GZIP

#include <zlib.h>
#include <string.h>
Expand Down

0 comments on commit 37aec13

Please sign in to comment.