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.
This commit is contained in:
Jim Evins
2017-11-25 03:18:39 -05:00
parent a48a929006
commit 32cde7cb1d
3 changed files with 28 additions and 5 deletions
+7 -2
View File
@@ -48,11 +48,11 @@ if (MINGW)
set (QT_BIN_DIR ${QT_BASE_DIR}/bin) set (QT_BIN_DIR ${QT_BASE_DIR}/bin)
endif () endif ()
find_package (ZLIB 1.2 REQUIRED)
# #
# Optional dependencies # Optional dependencies
# #
find_package (ZLIB 1.2 QUIET)
find_package (GnuBarcode 0.98 QUIET) find_package (GnuBarcode 0.98 QUIET)
find_package (LibQrencode 3.4 QUIET) find_package (LibQrencode 3.4 QUIET)
find_package (LibZint 2.6 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 "Source code location .... " ${glabels_SOURCE_DIR})
message (STATUS "C++ Compiler ............ " ${CMAKE_CXX_COMPILER_ID} " " ${CMAKE_CXX_COMPILER} " " ${CMAKE_CXX_COMPILER_VERSION}) message (STATUS "C++ Compiler ............ " ${CMAKE_CXX_COMPILER_ID} " " ${CMAKE_CXX_COMPILER} " " ${CMAKE_CXX_COMPILER_VERSION})
message (STATUS "Qt version .............. " ${Qt5Core_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) if (GNUBARCODE_FOUND)
message (STATUS "GNU Barcode (optional)... " ${GNUBARCODE_VERSION_STRING}) message (STATUS "GNU Barcode (optional)... " ${GNUBARCODE_VERSION_STRING})
+11 -1
View File
@@ -1,5 +1,15 @@
project (Model LANGUAGES CXX) 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 # Sources
#======================================= #=======================================
@@ -96,7 +106,7 @@ target_link_libraries (Model
Qt5::PrintSupport Qt5::PrintSupport
Qt5::Xml Qt5::Xml
Qt5::Svg Qt5::Svg
ZLIB::ZLIB ${OPTIONAL_ZLIB}
) )
#======================================= #=======================================
+10 -2
View File
@@ -41,8 +41,9 @@
#include <QTextDocument> #include <QTextDocument>
#include <QtDebug> #include <QtDebug>
#if HAVE_ZLIB
#include <zlib.h> #include <zlib.h>
#endif
namespace glabels namespace glabels
{ {
@@ -70,10 +71,15 @@ namespace glabels
QByteArray rawData = file.readAll(); QByteArray rawData = file.readAll();
if ( ((rawData[0]&0xFF) == 0x1F) && ((rawData[1]&0xFF) == 0x8b) ) // gzip magic number 0x1F, 0x8B if ( ((rawData[0]&0xFF) == 0x1F) && ((rawData[1]&0xFF) == 0x8b) ) // gzip magic number 0x1F, 0x8B
{ {
#if HAVE_ZLIB
// gzip compressed format // gzip compressed format
QByteArray unzippedData; QByteArray unzippedData;
gunzip( rawData, unzippedData ); gunzip( rawData, unzippedData );
success = doc.setContent( unzippedData, false, &errorString, &errorLine, &errorColumn ); 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 else
{ {
@@ -175,6 +181,7 @@ namespace glabels
} }
#if HAVE_ZLIB
void void
XmlLabelParser::gunzip( const QByteArray& data, QByteArray& result ) XmlLabelParser::gunzip( const QByteArray& data, QByteArray& result )
{ {
@@ -223,7 +230,8 @@ namespace glabels
// clean up // clean up
inflateEnd(&strm); inflateEnd(&strm);
} }
#endif
Model* Model*
XmlLabelParser::parseRootNode( const QDomElement &node ) XmlLabelParser::parseRootNode( const QDomElement &node )