Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ba1b178

Browse files
committedSep 17, 2024·
Automate version generation
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
1 parent a9126d5 commit ba1b178

10 files changed

+63
-27
lines changed
 

‎.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
limereport/version.h.in export-subst

‎.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ modules.xml
128128
.LSOverride
129129

130130
# Icon must end with two \r
131-
Icon
131+
Icon
132+
132133

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

290291
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
291-
292+
limereport/version.h
292293
/build/
293294
*.app

‎CMakeLists.txt

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
cmake_minimum_required(VERSION 3.14)
22
project(limereport)
33

4+
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" "${CMAKE_MODULE_PATH}")
5+
include(GenerateVersionHeader)
6+
47
set(DEFAULT_ITEM_PADDING 0)
5-
set(LIMEREPORT_VERSION_MAJOR 1)
6-
set(LIMEREPORT_VERSION_MINOR 7)
7-
set(LIMEREPORT_VERSION_RELEASE 14)
88

99
option(ENABLE_ZINT "Enable libzint build for barcode support" OFF)
1010
option(LIMEREPORT_STATIC "Build LimeReport as static library" OFF)
@@ -349,14 +349,12 @@ set(EXTRA_FILES
349349
${PROJECT_NAME}/lrpreparedpagesintf.h
350350
)
351351

352-
configure_file(config.h.in config.h @ONLY)
353-
354352
set(GLOBAL_HEADERS
355353
${PROJECT_NAME}/LimeReport
356354
${PROJECT_NAME}/LRCallbackDS
357355
${PROJECT_NAME}/LRDataManager
358356
${PROJECT_NAME}/LRScriptManager
359-
${CMAKE_CURRENT_BINARY_DIR}/config.h
357+
${CMAKE_CURRENT_BINARY_DIR}/limereport/version.h
360358
)
361359

362360
set(PROJECT_NAME ${PROJECT_NAME}-qt${QT_VERSION_MAJOR})
@@ -371,8 +369,6 @@ else()
371369
target_compile_definitions( ${PROJECT_NAME} INTERFACE -DLIMEREPORT_IMPORTS)
372370
endif()
373371

374-
target_compile_definitions(${PROJECT_NAME} PUBLIC -DCMAKE_CONFIG)
375-
376372
if(Qt${QT_VERSION_MAJOR}UiTools_FOUND)
377373
target_compile_definitions( ${PROJECT_NAME} PRIVATE -DHAVE_UI_LOADER)
378374
target_link_libraries( ${PROJECT_NAME} PUBLIC
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
find_package(Git)
2+
3+
if(GIT_EXECUTABLE)
4+
# Generate a git-describe version string from Git repository tags
5+
execute_process(
6+
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty
7+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
8+
OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
9+
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
10+
OUTPUT_STRIP_TRAILING_WHITESPACE
11+
)
12+
if(NOT GIT_DESCRIBE_ERROR_CODE)
13+
set(GIT_VERSION ${GIT_DESCRIBE_VERSION})
14+
endif()
15+
endif()
16+
17+
# Final fallback: Just use a bogus version string that is semantically older
18+
# than anything else and spit out a warning to the developer.
19+
if(NOT DEFINED GIT_VERSION)
20+
set(GIT_VERSION 0.0.0-unknown)
21+
message(WARNING "Failed to determine version from Git tags. Using default version \"${FOOBAR_VERSION}\".")
22+
endif()
23+
24+
configure_file(
25+
${CMAKE_SOURCE_DIR}/limereport/version.h.in
26+
${CMAKE_BINARY_DIR}/limereport/version.h
27+
@ONLY)
28+

‎common.pri

-7
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,6 @@ UI_SOURCES_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/ui
139139
OBJECTS_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/obj
140140
RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc
141141

142-
LIMEREPORT_VERSION_MAJOR = 1
143-
LIMEREPORT_VERSION_MINOR = 7
144-
LIMEREPORT_VERSION_RELEASE = 14
145-
146-
LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}'
147-
DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\"
148-
149142
QT *= xml sql
150143

151144
REPORT_PATH = $$PWD/limereport

‎config.h.in

-7
This file was deleted.

‎console/main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <QDir>
77
#include <QFile>
88
#include <QCommandLineParser>
9+
#include "../limereport/version.h"
910

1011
#ifdef _WIN32
1112
#include <io.h>

‎limereport/limereport.pri

+16
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,19 @@ FORMS += \
213213
RESOURCES += \
214214
$$REPORT_PATH/report.qrc \
215215
$$REPORT_PATH/items/items.qrc
216+
217+
system("git -v") {
218+
LR_VERSION = $$system("git --git-dir=../.git describe --tags --dirty")
219+
} else {
220+
LR_VERSION = "0.0.0-unknown"
221+
}
222+
223+
VERSION_TEMPLATE = $$PWD/version.h.in
224+
225+
generateversion.depends = FORCE
226+
generateversion.input = VERSION_TEMPLATE
227+
generateversion.output = $$OUT_PWD/version.h
228+
generateversion.commands = $$QMAKE_STREAM_EDITOR \'s/@GIT_VERSION@/$$LR_VERSION/\' ${QMAKE_FILE_IN} > ${QMAKE_FILE_OUT}
229+
generateversion.CONFIG = no_link target_predeps
230+
231+
QMAKE_EXTRA_COMPILERS += generateversion

‎limereport/lraboutdialog.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
2828
* GNU General Public License for more details. *
2929
****************************************************************************/
30-
#ifdef CMAKE_CONFIG
31-
#include <config.h>
32-
#endif
30+
#include "version.h"
3331
#include "lraboutdialog.h"
3432
#include "ui_lraboutdialog.h"
3533

‎limereport/version.h.in

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
// git will put "#define GIT_ARCHIVE 1" on the next line inside archives. $Format:%n#define GIT_ARCHIVE 1$
4+
5+
#ifdef GIT_ARCHIVE
6+
#define LIMEREPORT_VERSION_STR "$Format:%(describe)$"
7+
#else
8+
#define LIMEREPORT_VERSION_STR "@GIT_VERSION@"
9+
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.