I had this problem and solved it this way. A bit of a fiddle but it works, recording the version and the svn number in the .rc file and its available in the .cpp files too.
- Create a .pri file where the version number is set and use this in all the projects with a line
include(../product_version.pri)
include(../product_version.pri)
To copy to clipboard, switch view to plain text mode
- Create a header file with macros to handle the version number.
- Use the macros in your c++ code with a line
#include "../product_version.h"
#include "../product_version.h"
To copy to clipboard, switch view to plain text mode
- Use the macros within your .rc file with a line
#include "../product_version.h"
#include "../product_version.h"
To copy to clipboard, switch view to plain text mode
The .pri file contains this:
# Product version. Comma delimit 4 numbers eg. NW_VERSION=1,2,3,4
NW_VERSION=3,0,652,0
DEFINES += "VERSION_RC=$${NW_VERSION}"
NW_SVN = $$system(svnversion -n)
DEFINES += "SVN_RC=$${NW_SVN}"
# Display the SVN version number in the build log
QMAKE_PRE_LINK += @echo. & @echo "SVN version:" $$NW_SVN &
# Product version. Comma delimit 4 numbers eg. NW_VERSION=1,2,3,4
NW_VERSION=3,0,652,0
DEFINES += "VERSION_RC=$${NW_VERSION}"
NW_SVN = $$system(svnversion -n)
DEFINES += "SVN_RC=$${NW_SVN}"
# Display the SVN version number in the build log
QMAKE_PRE_LINK += @echo. & @echo "SVN version:" $$NW_SVN &
To copy to clipboard, switch view to plain text mode
- Sets a qmake variable to the 4-digit version number
- Sets the value of this as a #define that gets passed to the compiler as
#define VERSION_RC 1,2,3,4
#define VERSION_RC 1,2,3,4
To copy to clipboard, switch view to plain text mode
- Runs subversion and sets its returned value into another qmake variable and passed to the compiler in similar fashion
- Finally echos the SVN version into the log with a line break to make it stand out.
The header file contains this:
/* We expect declarations VERSION_RC=1,2,3,4 and SVN_RC=4123:4168MS
to have been set in the .pro script using the DEFINES command.
*/
#define MAKESTRING(x) #x
#ifdef _MSC_VER
// Visual studio mangles the standard macro PRODUCT_VERSION_STRING by expanding it to:
// "3,0,652,0" "," "," "," " - " "799:800M"
// So we use this alternative.
#define EXPANDMACROx4(y) MAKESTRING(y)
#else
#define VERSIONSTRING(a,b,c,d) MAKESTRING(a) "," MAKESTRING(b) "," MAKESTRING(c) "," MAKESTRING(d)
#define EXPANDMACROx4(y) VERSIONSTRING(y)
#endif
#define EXPANDMACROx1(y) MAKESTRING(y)
#define FILE_VERSION_STRING EXPANDMACROx4(VERSION_RC)
#define JOIN_STRINGS(a,b) a " - " EXPANDMACROx1(b)
#define PRODUCT_VERSION_STRING JOIN_STRINGS(FILE_VERSION_STRING,SVN_RC)
/* We expect declarations VERSION_RC=1,2,3,4 and SVN_RC=4123:4168MS
to have been set in the .pro script using the DEFINES command.
*/
#define MAKESTRING(x) #x
#ifdef _MSC_VER
// Visual studio mangles the standard macro PRODUCT_VERSION_STRING by expanding it to:
// "3,0,652,0" "," "," "," " - " "799:800M"
// So we use this alternative.
#define EXPANDMACROx4(y) MAKESTRING(y)
#else
#define VERSIONSTRING(a,b,c,d) MAKESTRING(a) "," MAKESTRING(b) "," MAKESTRING(c) "," MAKESTRING(d)
#define EXPANDMACROx4(y) VERSIONSTRING(y)
#endif
#define EXPANDMACROx1(y) MAKESTRING(y)
#define FILE_VERSION_STRING EXPANDMACROx4(VERSION_RC)
#define JOIN_STRINGS(a,b) a " - " EXPANDMACROx1(b)
#define PRODUCT_VERSION_STRING JOIN_STRINGS(FILE_VERSION_STRING,SVN_RC)
To copy to clipboard, switch view to plain text mode
I'm not going to attempt to explain the above, it works by trial and lots of error.
In your source you can have this for example:
m_logo
->setToolTip
(QString(PRODUCT_VERSION_STRING
));
m_logo->setToolTip(QString(PRODUCT_VERSION_STRING));
To copy to clipboard, switch view to plain text mode
In your .rc file you can have this for example:
#include "../product_version.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION VERSION_RC
PRODUCTVERSION VERSION_RC
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904B0"
BEGIN
VALUE "CompanyName", "ABC Systems"
VALUE "FileDescription", "ABC application"
VALUE "FileVersion", FILE_VERSION_STRING
VALUE "LegalCopyright", "© ABC Limited. All rights reserved."
VALUE "OriginalFilename", "abc.exe"
VALUE "ProductName", "Abc"
VALUE "ProductVersion", PRODUCT_VERSION_STRING
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x809, 1200
END
END
#include "../product_version.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION VERSION_RC
PRODUCTVERSION VERSION_RC
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904B0"
BEGIN
VALUE "CompanyName", "ABC Systems"
VALUE "FileDescription", "ABC application"
VALUE "FileVersion", FILE_VERSION_STRING
VALUE "LegalCopyright", "© ABC Limited. All rights reserved."
VALUE "OriginalFilename", "abc.exe"
VALUE "ProductName", "Abc"
VALUE "ProductVersion", PRODUCT_VERSION_STRING
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x809, 1200
END
END
To copy to clipboard, switch view to plain text mode
Don't forget the other gotchas:
- In your project file you'll need:
RC_FILE += product.rc
RC_FILE += product.rc
To copy to clipboard, switch view to plain text mode
- If you use Visual Studio then you will also need:
QMAKE_RC = rc -D_MSC_VER
QMAKE_RC = rc -D_MSC_VER
To copy to clipboard, switch view to plain text mode
I think thats all. Good luck!
Bookmarks