Skip to content

Commit

Permalink
Automate version generation
Browse files Browse the repository at this point in the history
Version is now generated automatically based on git tags.
Both cases are handled: building from git tree and building tarball downloaded from github.

Works for qmake and cmake
  • Loading branch information
aol-nnov committed Sep 4, 2024
1 parent b143441 commit f2030c3
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 27 deletions.
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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ modules.xml
.LSOverride

# Icon must end with two \r
Icon
Icon


# Thumbnails
._*
Expand Down Expand Up @@ -288,6 +289,6 @@ $RECYCLE.BIN/
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,qtcreator,qt,macos,intellij+iml,cmake,linux,windows

# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)

limereport/version.h
/build/
*.app
12 changes: 4 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_CURRENT_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 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 \"${FOOBAR_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 -v") {
LR_VERSION = $$system("git --git-dir=../.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)$"
#else
#define LIMEREPORT_VERSION_STR "@GIT_VERSION@"
#endif

0 comments on commit f2030c3

Please sign in to comment.