Skip to content

Commit

Permalink
Merge pull request #471 from aol-nnov/automate-version-generation
Browse files Browse the repository at this point in the history
Automate version generation
  • Loading branch information
fralx authored Sep 19, 2024
2 parents a9126d5 + b534c2b commit c5b9ac2
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 30 deletions.
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
limereport/version.h.in export-subst
40 changes: 35 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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')"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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})
Expand All @@ -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
Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions cmake/modules/GenerateVersionHeader.cmake
Original file line number Diff line number Diff line change
@@ -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)

7 changes: 0 additions & 7 deletions common.pri
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions config.h.in

This file was deleted.

1 change: 1 addition & 0 deletions console/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QDir>
#include <QFile>
#include <QCommandLineParser>
#include "../limereport/version.h"

#ifdef _WIN32
#include <io.h>
Expand Down
16 changes: 16 additions & 0 deletions limereport/limereport.pri
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions limereport/lraboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
****************************************************************************/
#ifdef CMAKE_CONFIG
#include <config.h>
#endif
#include "version.h"
#include "lraboutdialog.h"
#include "ui_lraboutdialog.h"

Expand Down
9 changes: 9 additions & 0 deletions limereport/version.h.in
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c5b9ac2

Please sign in to comment.