From 2f5e6b6439989cf9b44045fe3a3de154d4cf3bfa Mon Sep 17 00:00:00 2001 From: andy5995 Date: Tue, 25 Sep 2018 02:07:33 -0500 Subject: [PATCH] CMake:use external zlib if present --- source/shared_lib/CMakeLists.txt | 19 ++++++++++++-- .../sources/compression/compression_utils.cpp | 26 +++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/source/shared_lib/CMakeLists.txt b/source/shared_lib/CMakeLists.txt index 77a0b0675..d389d581e 100644 --- a/source/shared_lib/CMakeLists.txt +++ b/source/shared_lib/CMakeLists.txt @@ -231,15 +231,30 @@ IF(BUILD_MODEL_VIEWER OR BUILD_MAP_EDITOR OR BUILD_ZETAGLEST) ######################################################################################### # zetaglest lib + include(FindZLIB) + IF (FORCE_EMBEDDED_LIBS) + SET(DIRS_WITH_SRC + ${DIRS_WITH_SRC} + miniz) + ELSE() + message(STATUS "Searching for zlib") + if (ZLIB_FOUND) + message(STATUS "Using external zlib") + SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${ZLIB_LIBRARIES}) + INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS}) + add_definitions("-DHAVE_ZLIB") + ENDIF() + ENDIF() + SET(DIRS_WITH_SRC - compression + ${DIRS_WITH_SRC} + compression feathery_ftp glew graphics graphics/gl lua map - miniz platform/common sound sound/openal diff --git a/source/shared_lib/sources/compression/compression_utils.cpp b/source/shared_lib/sources/compression/compression_utils.cpp index 61c8e0656..c424ef912 100644 --- a/source/shared_lib/sources/compression/compression_utils.cpp +++ b/source/shared_lib/sources/compression/compression_utils.cpp @@ -17,7 +17,6 @@ // is not a limitation of miniz.c. #include "compression_utils.h" -#include "miniz/miniz.h" #include #include #include @@ -25,6 +24,12 @@ #include "platform_util.h" #include "util.h" +#ifdef HAVE_ZLIB + #include +#else + #include "miniz/miniz.h" +#endif + using namespace Shared::Util; namespace Shared { @@ -53,7 +58,13 @@ namespace Shared { const char *pDst_filename = NULL; long file_loc = 0; - if (SystemFlags::VERBOSE_MODE_ENABLED) printf("miniz.c version: %s\n", MZ_VERSION); + if (SystemFlags::VERBOSE_MODE_ENABLED) { +#ifdef HAVE_ZLIB + printf("zlib version: " ZLIB_VERSION "\n"); +#else + printf("miniz.c version: " MZ_VERSION "\n"); +#endif + } if (argc < 4) { if (SystemFlags::VERBOSE_MODE_ENABLED) { @@ -294,8 +305,19 @@ namespace Shared { } if (SystemFlags::VERBOSE_MODE_ENABLED) { +#ifdef HAVE_ZLIB + printf("Total input bytes: %u\n", stream.total_in); + printf("Total output bytes: %u\n", stream.total_out); +#else + /* + * I don't know why this typecasting (mz_unit32) is used for + * miniz, but it was there when I found the code, so leaving it + * here for now. + * -andy5995, 2018-09-25 + */ printf("Total input bytes: %u\n", (mz_uint32) stream.total_in); printf("Total output bytes: %u\n", (mz_uint32) stream.total_out); +#endif printf("Success.\n"); } return EXIT_SUCCESS;