Default Re: QMake DEFINES
Hi there,
How is it possible to define the FILEVERSION (without the quotes) For the VERSIONINFO struct in the resource file(windows),
something like this:
DEFINES+= PROD_VER=5,6,4,5
thanks for the help...
Cafu
Printable View
Default Re: QMake DEFINES
Hi there,
How is it possible to define the FILEVERSION (without the quotes) For the VERSIONINFO struct in the resource file(windows),
something like this:
DEFINES+= PROD_VER=5,6,4,5
thanks for the help...
Cafu
You can have separate file with all defines, which you can include in .rc file. Here is an example:
Code:
// program_strings.h #ifndef _STRINGS_H_ #define _STRINGS_H_ #define _STR_COMPANY_NAME "My Company Name" #define _STR_PRODUCT_NAME "ProgramName" #define _PRODUCT_VERSION 3,4,0,0 #define _STR_PRODUCT_VERSION "3.4" #define _STR_FILE_DESCRIPTION "Short description of the program" #define _FILE_VERSION 3,4,1234,0 #define _STR_FILE_VERSION "3,4,1234,0" #define _STR_INTERNAL_NAME "ProgramName" #define _STR_LEGAL_COPYRIGHT "Copyright © ..." #define _STR_LEGAL_TRADE_1 "All rights reserved or something" #define _STR_LEGAL_TRADE_2 _STR_LEGAL_TRADE_1 #define _STR_ORIGINAL_FILE_NAME "Program.exe" #define _STR_WEBSITE "www.mywebsite.com" #endif /* _STRINGS_H_ */ // program.rc IDI_ICON1 ICON DISCARDABLE "your icon.ico" #include <windows.h> #include "program_strings.h" VS_VERSION_INFO VERSIONINFO FILEVERSION _FILE_VERSION PRODUCTVERSION _PRODUCT_VERSION BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904E4" BEGIN VALUE "CompanyName", _STR_COMPANY_NAME VALUE "FileDescription", _STR_FILE_DESCRIPTION VALUE "FileVersion", _STR_FILE_VERSION VALUE "InternalName", _STR_INTERNAL_NAME VALUE "LegalCopyright", _STR_LEGAL_COPYRIGHT VALUE "LegalTrademarks1", _STR_LEGAL_TRADE_1 VALUE "OriginalFilename", _STR_ORIGINAL_FILE_NAME VALUE "ProductName", _STR_PRODUCT_NAME VALUE "ProductVersion", _STR_PRODUCT_VERSION END END END
Yeah i know i can do this but i wanted to do it in .pro file so the definition is available in the project as well, and i could use it within the code not just in the rc file. so i decide to do it like this
/*pro file*/
RELEASE=3
DEFINES += "RELEASE_RC=$${RELEASE}"
MAJOR=3
DEFINES += "MAJOR_RC=$${MAJOR}"
MINOR=3
DEFINES += "MINOR_RC=$${MINOR}"
PATCH=3
DEFINES += "PATCH_RC=$${PATCH}"
/*rc file*/
#define PRODUCT_VERSION_RC RELEASE_RC,MAJOR_RC,MINOR_RC,PATCH_RC
Thanks for the help
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
Code:
include(../product_version.pri)
- Create a header file with macros to handle the version number.
- Use the macros in your c++ code with a line
Code:
#include "../product_version.h"
- Use the macros within your .rc file with a line
Code:
#include "../product_version.h"
The .pri file contains this:
Code:
# 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 &
- 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
Code:
#define VERSION_RC 1,2,3,4
- 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:
Code:
/* 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)
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:
In your .rc file you can have this for example:
Code:
#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
Don't forget the other gotchas:
- In your project file you'll need:
Code:
RC_FILE += product.rc
- If you use Visual Studio then you will also need:
Code:
QMAKE_RC = rc -D_MSC_VER
I think thats all. Good luck!