diff --git a/.appveyor.yml b/.appveyor.yml index ccfaa11..4dde5bf 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -4,5 +4,6 @@ install: - set QTDIR=C:\Qt\5.12\mingw73_64 - set PATH=%QTDIR%\bin;C:\Qt\Tools\mingw730_64\bin;%PATH% build_script: + - git fetch --prune --tags - qmake LimeReport.pro - mingw32-make diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a848c3e --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +limereport/version.h.in export-subst diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 1578466..699aa11 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -23,7 +23,14 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 + with: + fetch-tags: true + + # https://github.com/actions/checkout/issues/1781 + # workaround https://github.com/actions/checkout/issues/1471#issuecomment-1755560284 + - name: Fetch tags + run: git fetch --prune --unshallow --tags - name: Install Qt uses: jurplel/install-qt-action@v3 @@ -57,7 +64,14 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 + with: + fetch-tags: true + + # https://github.com/actions/checkout/issues/1781 + # workaround https://github.com/actions/checkout/issues/1471#issuecomment-1755560284 + - name: Fetch tags + run: git fetch --prune --unshallow --tags - name: Install Qt uses: jurplel/install-qt-action@v3 @@ -94,8 +108,10 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 - + uses: actions/checkout@v4 + with: + fetch-tags: true + - name: Install MinGW-w64 packages Qt5 if: "startsWith(matrix.qt_version, '5')" uses: msys2/setup-msys2@v2 @@ -107,6 +123,7 @@ jobs: cc:p cmake:p ninja:p + git: qt${{ matrix.qt_version }}-base:p qt${{ matrix.qt_version }}-svg:p qt${{ matrix.qt_version }}-tools:p @@ -123,10 +140,16 @@ jobs: cc:p cmake:p ninja:p + git: qt${{ matrix.qt_version }}-base:p qt${{ matrix.qt_version }}-svg:p qt${{ matrix.qt_version }}-tools:p qt${{ matrix.qt_version }}-declarative:p + + # https://github.com/actions/checkout/issues/1781 + # workaround https://github.com/actions/checkout/issues/1471#issuecomment-1755560284 + - name: Fetch tags + run: git fetch --prune --unshallow --tags - name: Configure CMake for Qt5 if: "startsWith(matrix.qt_version, '5')" @@ -151,7 +174,14 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 + with: + fetch-tags: true + + # https://github.com/actions/checkout/issues/1781 + # workaround https://github.com/actions/checkout/issues/1471#issuecomment-1755560284 + - name: Fetch tags + run: git fetch --prune --unshallow --tags - name: Install Qt uses: jurplel/install-qt-action@v3 diff --git a/.gitignore b/.gitignore index 5150452..5425e47 100644 --- a/.gitignore +++ b/.gitignore @@ -289,5 +289,6 @@ $RECYCLE.BIN/ # Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) +limereport/version.h /build/ *.app diff --git a/CMakeLists.txt b/CMakeLists.txt index aff69f8..9b98eca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,10 @@ cmake_minimum_required(VERSION 3.14) project(limereport) +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" "${CMAKE_MODULE_PATH}") +include(GenerateVersionHeader) + set(DEFAULT_ITEM_PADDING 0) -set(LIMEREPORT_VERSION_MAJOR 1) -set(LIMEREPORT_VERSION_MINOR 7) -set(LIMEREPORT_VERSION_RELEASE 14) option(ENABLE_ZINT "Enable libzint build for barcode support" OFF) option(LIMEREPORT_STATIC "Build LimeReport as static library" OFF) @@ -349,14 +349,12 @@ set(EXTRA_FILES ${PROJECT_NAME}/lrpreparedpagesintf.h ) -configure_file(config.h.in config.h @ONLY) - set(GLOBAL_HEADERS ${PROJECT_NAME}/LimeReport ${PROJECT_NAME}/LRCallbackDS ${PROJECT_NAME}/LRDataManager ${PROJECT_NAME}/LRScriptManager - ${CMAKE_CURRENT_BINARY_DIR}/config.h + ${CMAKE_BINARY_DIR}/limereport/version.h ) set(PROJECT_NAME ${PROJECT_NAME}-qt${QT_VERSION_MAJOR}) @@ -371,8 +369,6 @@ else() target_compile_definitions( ${PROJECT_NAME} INTERFACE -DLIMEREPORT_IMPORTS) endif() -target_compile_definitions(${PROJECT_NAME} PUBLIC -DCMAKE_CONFIG) - if(Qt${QT_VERSION_MAJOR}UiTools_FOUND) target_compile_definitions( ${PROJECT_NAME} PRIVATE -DHAVE_UI_LOADER) target_link_libraries( ${PROJECT_NAME} PUBLIC @@ -396,6 +392,7 @@ target_compile_definitions( ${PROJECT_NAME} PRIVATE -DDEFAULT_ITEM_PADDING=${DEF target_include_directories( ${PROJECT_NAME} PRIVATE limereport/ + ${CMAKE_BINARY_DIR}/limereport limereport/base limereport/bands limereport/databrowser diff --git a/cmake/modules/GenerateVersionHeader.cmake b/cmake/modules/GenerateVersionHeader.cmake new file mode 100644 index 0000000..ed62702 --- /dev/null +++ b/cmake/modules/GenerateVersionHeader.cmake @@ -0,0 +1,28 @@ +find_package(Git) + +if(GIT_EXECUTABLE) + # Generate a git-describe version string from Git repository tags + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags --dirty + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_DESCRIBE_VERSION + RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT GIT_DESCRIBE_ERROR_CODE) + set(GIT_VERSION ${GIT_DESCRIBE_VERSION}) + endif() +endif() + +# Final fallback: Just use a bogus version string that is semantically older +# than anything else and spit out a warning to the developer. +if(NOT DEFINED GIT_VERSION) + set(GIT_VERSION 0.0.0-unknown) + message(WARNING "Failed to determine version from Git tags. Using default version \"${GIT_VERSION}\".") +endif() + +configure_file( + ${CMAKE_SOURCE_DIR}/limereport/version.h.in + ${CMAKE_BINARY_DIR}/limereport/version.h + @ONLY) + diff --git a/common.pri b/common.pri index e87efa0..53960ec 100644 --- a/common.pri +++ b/common.pri @@ -139,13 +139,6 @@ UI_SOURCES_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/ui OBJECTS_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/obj RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc -LIMEREPORT_VERSION_MAJOR = 1 -LIMEREPORT_VERSION_MINOR = 7 -LIMEREPORT_VERSION_RELEASE = 14 - -LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}' -DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\" - QT *= xml sql REPORT_PATH = $$PWD/limereport diff --git a/config.h.in b/config.h.in deleted file mode 100644 index dcb5e74..0000000 --- a/config.h.in +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#cmakedefine LIMEREPORT_VERSION_MAJOR "@LIMEREPORT_VERSION_MAJOR@" -#cmakedefine LIMEREPORT_VERSION_MINOR "@LIMEREPORT_VERSION_MINOR@" -#cmakedefine LIMEREPORT_VERSION_RELEASE "@LIMEREPORT_VERSION_RELEASE@" - -#define LIMEREPORT_VERSION_STR LIMEREPORT_VERSION_MAJOR"." LIMEREPORT_VERSION_MINOR"." LIMEREPORT_VERSION_RELEASE diff --git a/console/main.cpp b/console/main.cpp index 7493e67..2d6e9a1 100644 --- a/console/main.cpp +++ b/console/main.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "../limereport/version.h" #ifdef _WIN32 #include diff --git a/limereport/limereport.pri b/limereport/limereport.pri index c86b575..0243cb9 100644 --- a/limereport/limereport.pri +++ b/limereport/limereport.pri @@ -213,3 +213,19 @@ FORMS += \ RESOURCES += \ $$REPORT_PATH/report.qrc \ $$REPORT_PATH/items/items.qrc + +system("git --version") { + LR_VERSION = $$system("git --git-dir=$$PWD/../.git describe --tags --dirty") +} else { + LR_VERSION = "0.0.0-unknown" +} + +VERSION_TEMPLATE = $$PWD/version.h.in + +generateversion.depends = FORCE +generateversion.input = VERSION_TEMPLATE +generateversion.output = $$OUT_PWD/version.h +generateversion.commands = $$QMAKE_STREAM_EDITOR \'s/@GIT_VERSION@/$$LR_VERSION/\' ${QMAKE_FILE_IN} > ${QMAKE_FILE_OUT} +generateversion.CONFIG = no_link target_predeps + +QMAKE_EXTRA_COMPILERS += generateversion diff --git a/limereport/lraboutdialog.cpp b/limereport/lraboutdialog.cpp index 57cddd6..3663e31 100644 --- a/limereport/lraboutdialog.cpp +++ b/limereport/lraboutdialog.cpp @@ -27,9 +27,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * ****************************************************************************/ -#ifdef CMAKE_CONFIG -#include -#endif +#include "version.h" #include "lraboutdialog.h" #include "ui_lraboutdialog.h" diff --git a/limereport/version.h.in b/limereport/version.h.in new file mode 100644 index 0000000..0592268 --- /dev/null +++ b/limereport/version.h.in @@ -0,0 +1,9 @@ +#pragma once + +// git will put "#define GIT_ARCHIVE 1" on the next line inside archives. $Format:%n#define GIT_ARCHIVE 1$ + +#ifdef GIT_ARCHIVE +#define LIMEREPORT_VERSION_STR "$Format:%(describe:tags=true)$" +#else +#define LIMEREPORT_VERSION_STR "@GIT_VERSION@" +#endif