Skip to content

Commit 13fd5c3

Browse files
committed
QMake: Add reading version from the version.h
1 parent 04dce32 commit 13fd5c3

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

common.pri

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,20 @@ defineReplace(tsFiles) {
156156

157157
return ($$file_list)
158158
}
159+
160+
defineReplace(getVersion) {
161+
version_file = gcodeshared/include/version.h
162+
!exists ($${PROJECT_ROOT_PATH}/$${version_file}): error(In function getVersion: File \"$${version_file}\" not found)
163+
version_header = $$cat($${PROJECT_ROOT_PATH}/$${version_file}, lines)
164+
165+
for (str, version_header) {
166+
sub_str=$$split(str, " ")
167+
168+
contains (sub_str, GCODEWORKSHOP_VERSION) {
169+
ver_str=$$find(sub_str, '".*"')
170+
!isEmpty(ver_str): return ($$split(ver_str, '"'))
171+
}
172+
}
173+
174+
error(In function getVersion: GCODEWORKSHOP_VERSION not found in $${version_file})
175+
}

gcodefileserver/gcodefileserver.pro

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
# GCoderFileServer
22

3-
VERSION = 0.1.0.0
43
TEMPLATE = app
54
TARGET = gcodefileserver
65

7-
include(../common.pri)
8-
96
QT *= widgets serialport network
107
MODULES *= kdiff3 qtsingleapplication GCodeShared
118

129
include(../common.pri)
1310

11+
defined(VERSION, var) {
12+
# Define the version as a string literal
13+
# https://stackoverflow.com/a/2411008
14+
DEFINES += 'GCODEWORKSHOP_VERSION=\\"$$VERSION\\"'
15+
} else {
16+
VERSION = $$getVersion()
17+
}
1418

1519
SOURCES = \
1620
filechecker.cpp \

gcodeworkshop/gcodeworkshop.pro

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
VERSION = 2018.07
32
TEMPLATE = app
43
TARGET = gcodeworkshop
54

@@ -8,6 +7,14 @@ MODULES *= kdiff3 qtsingleapplication GCodeShared GCodeFileServer addons
87

98
include(../common.pri)
109

10+
defined(VERSION, var) {
11+
# Define the version as a string literal
12+
# https://stackoverflow.com/a/2411008
13+
DEFINES += 'GCODEWORKSHOP_VERSION=\\"$$VERSION\\"'
14+
} else {
15+
VERSION = $$getVersion()
16+
}
17+
1118
INCLUDEPATH += include
1219

1320

gcodeworkshop_top.pro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ win32 {
5353

5454
INSTALLS += translate examples doc
5555
}
56+
57+
!defined(VERSION, var): VERSION = $$getVersion()
58+
message(Project version: $$VERSION)

0 commit comments

Comments
 (0)