From: Manuel Nickschas Date: Wed, 19 Feb 2014 20:19:32 +0000 (+0100) Subject: Use system zlib if available X-Git-Tag: 0.10-rc1~21 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=f64d4eec4bba63ececdece95f5c73b0ac550acd4 Use system zlib if available Only fall back to miniz if we don't find zlib on the system. Distro packagers like this much more, and we use code that has seen much more testing. Incidentally, we've already had one case where miniz was really slow on a 32 bit box. Still keeping miniz as fallback for the rare platform/build box that doesn't ship zlib, since waiting a few seconds for compressing the backlog is still probably better than transmitting a few MB of extra data... --- diff --git a/CMakeLists.txt b/CMakeLists.txt index b5586de1..3e4ee9c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,6 +242,21 @@ if(QT_LRELEASE_EXECUTABLE) endif(QT_LRELEASE_EXECUTABLE) +# zlib for compression, however we can always fall back to miniz +find_package(ZLIB) +if(ZLIB_FOUND) + message(STATUS "Using system zlib for compression") + add_definitions(-DHAVE_ZLIB) + include_directories(${ZLIB_INCLUDE_DIRS}) + set(COMMON_LIBRARIES ${COMMON_LIBRARIES} ${ZLIB_LIBRARIES}) +else() + message(STATUS "zlib NOT found, using bundled miniz for compression") + if(${CMAKE_SIZEOF_VOID_P} EQUAL 4) + message(STATUS "WARNING: This may be slow on 32 bit systems!") + endif() +endif() + + # Execinfo is needed for generating backtraces find_package(ExecInfo) if(EXECINFO_FOUND) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 238cb867..75982d11 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,7 +16,7 @@ if(BUILD_GUI) if(STATIC) link_directories(${QT_PLUGINS_DIR}/imageformats) - set(CLIENT_LIBS ${CLIENT_LIBS} qjpeg qgif) + set(CLIENT_LIBRARIES ${CLIENT_LIBRARIES} qjpeg qgif) endif(STATIC) endif(BUILD_GUI) @@ -42,7 +42,7 @@ if(WANT_CORE) set_target_properties(quasselcore PROPERTIES COMPILE_FLAGS "-DBUILD_CORE ${QUASSEL_QT_COMPILEFLAGS}" OUTPUT_NAME ../quasselcore) - target_link_libraries(quasselcore mod_core mod_common + target_link_libraries(quasselcore mod_core mod_common ${COMMON_LIBRARIES} ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES}) install(TARGETS quasselcore RUNTIME DESTINATION ${BIN_INSTALL_DIR}) endif(WANT_CORE) @@ -55,7 +55,7 @@ if(WANT_QTCLIENT) set_target_properties(quasselclient PROPERTIES COMPILE_FLAGS "-DBUILD_QTUI ${QUASSEL_QT_COMPILEFLAGS} ${CLIENT_COMPILE_FLAGS}" OUTPUT_NAME ../quasselclient) - target_link_libraries(quasselclient ${LINK_KDE} mod_qtui mod_uisupport mod_client mod_common ${CLIENT_LIBS} + target_link_libraries(quasselclient ${LINK_KDE} mod_qtui mod_uisupport mod_client mod_common ${COMMON_LIBRARIES} ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES} ${CLIENT_LIBRARIES}) install(TARGETS quasselclient RUNTIME DESTINATION ${BIN_INSTALL_DIR}) endif(WANT_QTCLIENT) @@ -71,7 +71,7 @@ if(WANT_MONO) set_target_properties(quassel PROPERTIES COMPILE_FLAGS "-DBUILD_MONO ${QUASSEL_QT_COMPILEFLAGS} ${CLIENT_COMPILE_FLAGS}" OUTPUT_NAME ../quassel) - target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common ${CLIENT_LIBS} + target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common ${COMMON_LIBRARIES} ${QUASSEL_QT_LIBRARIES} ${QUASSEL_SSL_LIBRARIES} ${CLIENT_LIBRARIES}) install(TARGETS quassel RUNTIME DESTINATION ${BIN_INSTALL_DIR}) endif(WANT_MONO) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 70c0a55b..87a08d27 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -43,8 +43,6 @@ set(SOURCES protocols/datastream/datastreampeer.cpp protocols/legacy/legacypeer.cpp - - ../../3rdparty/miniz/miniz.c ) set(MOC_HDRS @@ -99,6 +97,10 @@ if (HAVE_QCA2) set(HEADERS ${HEADERS} keyevent.h) endif(HAVE_QCA2) +if(NOT HAVE_ZLIB) + set(SOURCES ${SOURCES} ../../3rdparty/miniz/miniz.c) +endif(NOT HAVE_ZLIB) + if(APPLE) set(SOURCES ${SOURCES} mac_utils.cpp) set(HEADERS ${HEADERS} mac_utils.h) diff --git a/src/common/compressor.cpp b/src/common/compressor.cpp index d2634e48..1d2233ac 100644 --- a/src/common/compressor.cpp +++ b/src/common/compressor.cpp @@ -23,8 +23,12 @@ #include #include -#define MINIZ_HEADER_FILE_ONLY -#include "../../3rdparty/miniz/miniz.c" +#ifdef HAVE_ZLIB +# include +#else +# define MINIZ_HEADER_FILE_ONLY +# include "../../3rdparty/miniz/miniz.c" +#endif const int maxBufferSize = 64 * 1024 * 1024; // protect us from zip bombs const int ioBufferSize = 64 * 1024; // chunk size for inflate/deflate; should not be too large as we preallocate that space! @@ -176,7 +180,7 @@ void Compressor::readData() _readBuffer.resize(_readBuffer.size() + ioBufferSize); _inputBuffer.append(_socket->read(ioBufferSize - _inputBuffer.size())); - _inflater->next_in = reinterpret_cast(_inputBuffer.constData()); + _inflater->next_in = reinterpret_cast(_inputBuffer.data()); _inflater->avail_in = _inputBuffer.size(); _inflater->next_out = reinterpret_cast(_readBuffer.data() + _readBuffer.size() - ioBufferSize); _inflater->avail_out = ioBufferSize; @@ -186,7 +190,7 @@ void Compressor::readData() int status = inflate(_inflater, Z_SYNC_FLUSH); // get as much data as possible // adjust input and output buffers - _readBuffer.resize(_inflater->next_out - reinterpret_cast(_readBuffer.constData())); + _readBuffer.resize(_inflater->next_out - reinterpret_cast(_readBuffer.data())); if (_inflater->avail_in > 0) memmove(_inputBuffer.data(), _inflater->next_in, _inflater->avail_in); _inputBuffer.resize(_inflater->avail_in); @@ -225,7 +229,7 @@ void Compressor::writeData() return; } - _deflater->next_in = reinterpret_cast(_writeBuffer.constData()); + _deflater->next_in = reinterpret_cast(_writeBuffer.data()); _deflater->avail_in = _writeBuffer.size(); int status; diff --git a/src/common/compressor.h b/src/common/compressor.h index 85817f1f..d9103221 100644 --- a/src/common/compressor.h +++ b/src/common/compressor.h @@ -25,7 +25,11 @@ class QTcpSocket; -typedef struct mz_stream_s *z_streamp; +#ifdef HAVE_ZLIB + typedef struct z_stream_s *z_streamp; +#else + typedef struct mz_stream_s *z_streamp; +#endif class Compressor : public QObject {