From 32cde7cb1de70c0b66526a24b1a22343563b2b6f Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 25 Nov 2017 03:18:39 -0500 Subject: [PATCH] Made zlib an optional dependency. Only needed to read legacy files, which is not fully supported yet. Hopefully this will make it easier to build on Windows. --- CMakeLists.txt | 9 +++++++-- model/CMakeLists.txt | 12 +++++++++++- model/XmlLabelParser.cpp | 12 ++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 71fbc9f..5641de5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,11 +48,11 @@ if (MINGW) set (QT_BIN_DIR ${QT_BASE_DIR}/bin) endif () -find_package (ZLIB 1.2 REQUIRED) # # Optional dependencies # +find_package (ZLIB 1.2 QUIET) find_package (GnuBarcode 0.98 QUIET) find_package (LibQrencode 3.4 QUIET) find_package (LibZint 2.6 QUIET) @@ -91,7 +91,12 @@ message (STATUS "Installation prefix ..... " ${CMAKE_INSTALL_PREFIX}) message (STATUS "Source code location .... " ${glabels_SOURCE_DIR}) message (STATUS "C++ Compiler ............ " ${CMAKE_CXX_COMPILER_ID} " " ${CMAKE_CXX_COMPILER} " " ${CMAKE_CXX_COMPILER_VERSION}) message (STATUS "Qt version .............. " ${Qt5Core_VERSION}) -message (STATUS "zlib version ............ " ${ZLIB_VERSION_STRING}) + +if (ZLIB_FOUND) + message (STATUS "zlib (optional).......... " ${ZLIB_VERSION_STRING}) +else (ZLIB_FOUND) + message (STATUS "zlib (optional).......... No.") +endif (ZLIB_FOUND) if (GNUBARCODE_FOUND) message (STATUS "GNU Barcode (optional)... " ${GNUBARCODE_VERSION_STRING}) diff --git a/model/CMakeLists.txt b/model/CMakeLists.txt index 1585607..d01a551 100644 --- a/model/CMakeLists.txt +++ b/model/CMakeLists.txt @@ -1,5 +1,15 @@ project (Model LANGUAGES CXX) +#======================================= +# Handle optional dependencies +#======================================= +if (${ZLIB_FOUND}) + add_definitions (-DHAVE_ZLIB=1) + set (OPTIONAL_ZLIB ZLIB::ZLIB) +else () + set (OPTIONAL_ZLIB "") +endif () + #======================================= # Sources #======================================= @@ -96,7 +106,7 @@ target_link_libraries (Model Qt5::PrintSupport Qt5::Xml Qt5::Svg - ZLIB::ZLIB + ${OPTIONAL_ZLIB} ) #======================================= diff --git a/model/XmlLabelParser.cpp b/model/XmlLabelParser.cpp index edff48f..2717c22 100644 --- a/model/XmlLabelParser.cpp +++ b/model/XmlLabelParser.cpp @@ -41,8 +41,9 @@ #include #include +#if HAVE_ZLIB #include - +#endif namespace glabels { @@ -70,10 +71,15 @@ namespace glabels QByteArray rawData = file.readAll(); if ( ((rawData[0]&0xFF) == 0x1F) && ((rawData[1]&0xFF) == 0x8b) ) // gzip magic number 0x1F, 0x8B { +#if HAVE_ZLIB // gzip compressed format QByteArray unzippedData; gunzip( rawData, unzippedData ); success = doc.setContent( unzippedData, false, &errorString, &errorLine, &errorColumn ); +#else + qWarning() << "Warning: Cannot read compressed glabels project file! gLabels not build with ZLIB."; + return nullptr; +#endif } else { @@ -175,6 +181,7 @@ namespace glabels } +#if HAVE_ZLIB void XmlLabelParser::gunzip( const QByteArray& data, QByteArray& result ) { @@ -223,7 +230,8 @@ namespace glabels // clean up inflateEnd(&strm); } - +#endif + Model* XmlLabelParser::parseRootNode( const QDomElement &node )