From 3eb31fe3f8e547be1d6009d95bfb3a9313e1e1d7 Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Sun, 22 Nov 2020 11:29:45 +0000 Subject: [PATCH] Take version information from CmakeLists.txt Warning: potential incompatibility because version number is no longer stored in zint.h --- CMakeLists.txt | 4 ++-- backend/CMakeLists.txt | 2 ++ backend/common.h | 1 + backend/zint.h | 5 ----- backend/zintconfig.h.in | 5 +++++ backend_qt/qzint.cpp | 4 ++++ backend_qt/qzint.h | 2 ++ frontend/main.c | 18 +++++++++++++++--- frontend_qt/mainwindow.cpp | 17 ++++++++++++++--- 9 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 backend/zintconfig.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index e21834c8..4e6ccdb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,8 +12,8 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set (ZINT_VERSION_MAJOR 2) set (ZINT_VERSION_MINOR 9) set (ZINT_VERSION_RELEASE 1) -set (ZINT_VERSION_BUILD ".9") # Set to "" before release, set to ".9" after release -set (ZINT_VERSION "${ZINT_VERSION_MAJOR}.${ZINT_VERSION_MINOR}.${ZINT_VERSION_RELEASE}${ZINT_VERSION_BUILD}" ) +set (ZINT_VERSION_BUILD 9) # Set to 0 before release, set to 9 after release +set (ZINT_VERSION "${ZINT_VERSION_MAJOR}.${ZINT_VERSION_MINOR}.${ZINT_VERSION_RELEASE}.${ZINT_VERSION_BUILD}" ) add_definitions(-DZINT_VERSION=\"${ZINT_VERSION}\") diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index a0fdfd5a..b28eeb9b 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -2,6 +2,8 @@ project(zint) +configure_file(zintconfig.h.in zintconfig.h) + find_package(PNG) set(zint_COMMON_SRCS common.c library.c large.c reedsol.c gs1.c eci.c general_field.c sjis.c gb2312.c gb18030.c) diff --git a/backend/common.h b/backend/common.h index c64a8a57..0cb1c337 100644 --- a/backend/common.h +++ b/backend/common.h @@ -47,6 +47,7 @@ #define NEON "0123456789" #include "zint.h" +#include "zintconfig.h" #include #include diff --git a/backend/zint.h b/backend/zint.h index ae27702d..5ff1c850 100644 --- a/backend/zint.h +++ b/backend/zint.h @@ -110,11 +110,6 @@ extern "C" { int warn_level; }; -#define ZINT_VERSION_MAJOR 2 -#define ZINT_VERSION_MINOR 9 -#define ZINT_VERSION_RELEASE 1 -#define ZINT_VERSION_BUILD 9 /* Set to 0 before release, set to 9 after release */ - /* Tbarcode 7 codes */ #define BARCODE_CODE11 1 #define BARCODE_C25STANDARD 2 diff --git a/backend/zintconfig.h.in b/backend/zintconfig.h.in new file mode 100644 index 00000000..875eca1e --- /dev/null +++ b/backend/zintconfig.h.in @@ -0,0 +1,5 @@ +// the configured options and settings for libzint +#define ZINT_VERSION_MAJOR @ZINT_VERSION_MAJOR@ +#define ZINT_VERSION_MINOR @ZINT_VERSION_MINOR@ +#define ZINT_VERSION_RELEASE @ZINT_VERSION_RELEASE@ +#define ZINT_VERSION_BUILD @ZINT_VERSION_BUILD@ diff --git a/backend_qt/qzint.cpp b/backend_qt/qzint.cpp index f5a4d959..335153ef 100644 --- a/backend_qt/qzint.cpp +++ b/backend_qt/qzint.cpp @@ -363,6 +363,10 @@ namespace Zint { bool QZint::hasErrors() const { return m_lastError.length(); } + + int QZint::getVersion() const { + return ZBarcode_Version(); + } bool QZint::save_to_file(QString filename) { resetSymbol(); diff --git a/backend_qt/qzint.h b/backend_qt/qzint.h index b6f0d9be..24240b0b 100644 --- a/backend_qt/qzint.h +++ b/backend_qt/qzint.h @@ -119,6 +119,8 @@ public: bool save_to_file(QString filename); void render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode=IgnoreAspectRatio); + + int getVersion() const; signals: void encoded(); diff --git a/frontend/main.c b/frontend/main.c index 91dfa27f..8b1692cc 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -76,12 +76,24 @@ static void types(void) { } /* Output usage information */ + static void usage(void) { - if (ZINT_VERSION_BUILD) { - printf( "Zint version %d.%d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE, ZINT_VERSION_BUILD); + int zint_version = ZBarcode_Version(); + int version_major = zint_version / 10000; + int version_minor = (zint_version % 10000) / 100; + int version_release = zint_version % 100; + int version_build; + + if (version_release > 10) { + /* This is a test release */ + version_release = version_release / 10; + version_build = zint_version % 10; + printf( "Zint version %d.%d.%d.%d\n", version_major, version_minor, version_release, version_build); } else { - printf( "Zint version %d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE); + /* This is a stable release */ + printf( "Zint version %d.%d.%d\n", version_major, version_minor, version_release); } + printf( "Encode input data in a barcode and save as BMP/EMF/EPS/GIF/PCX/PNG/SVG/TIF/TXT\n\n" " -b, --barcode=NUMBER Number of barcode type. Default is 20 (Code 128)\n" " --addongap=NUMBER Set add-on gap in multiples of X-dimension for UPC/EAN\n" diff --git a/frontend_qt/mainwindow.cpp b/frontend_qt/mainwindow.cpp index bff1b6f1..7ee7daea 100644 --- a/frontend_qt/mainwindow.cpp +++ b/frontend_qt/mainwindow.cpp @@ -344,10 +344,21 @@ bool MainWindow::save() void MainWindow::about() { QString zint_version; - if (ZINT_VERSION_BUILD) { - QTextStream(&zint_version) << ZINT_VERSION_MAJOR << "." << ZINT_VERSION_MINOR << "." << ZINT_VERSION_RELEASE << "." << ZINT_VERSION_BUILD; + + int lib_version = ZBarcode_Version(); + int version_major = lib_version / 10000; + int version_minor = (lib_version % 10000) / 100; + int version_release = lib_version % 100; + int version_build; + + if (version_release > 10) { + /* This is a test release */ + version_release = version_release / 10; + version_build = lib_version % 10; + QTextStream(&zint_version) << version_major << "." << version_minor << "." << version_release << "." << version_build; } else { - QTextStream(&zint_version) << ZINT_VERSION_MAJOR << "." << ZINT_VERSION_MINOR << "." << ZINT_VERSION_RELEASE; + /* This is a stable release */ + QTextStream(&zint_version) << version_major << "." << version_minor << "." << version_release; } QMessageBox::about(this, tr("About Zint"),