PDA

View Full Version : Getting VERSION from code?



sdfisher
27th July 2007, 16:55
Is there any reasonable way to get the value of the .pro's VERSION? Perhaps some way to make qmake output a header file for it? It seems a bit of a waste to have my version in two places.

fullmetalcoder
27th July 2007, 17:50
add a define directive to your pro file :

DEFINES += _VERSION_=${VERSION}
And then use the _VERSION_ macro (or whatever you named it) inside your code.

sdfisher
27th July 2007, 23:10
Huh. This doesn't seem to work with the Visual Studio generator. I get VERSION_NUMBER=${VERSION} (with ${VERSION} not expanded) as one of my defines.

Edit: DEFINES += VERSION_NUMBER="$${VERSION}" seems to have worked, though. Thanks for the nudge in the right direction.

Edit #2: Actually, that doesn't seem to work, either. It adds VERSION_NUMBER="1.2.0.1" to the defines, but that doesn't seem to actually work.

fullmetalcoder
28th July 2007, 14:09
Huh. This doesn't seem to work with the Visual Studio generator. I get VERSION_NUMBER=${VERSION} (with ${VERSION} not expanded) as one of my defines.

Edit: DEFINES += VERSION_NUMBER="$${VERSION}" seems to have worked, though. Thanks for the nudge in the right direction.

Edit #2: Actually, that doesn't seem to work, either. It adds VERSION_NUMBER="1.2.0.1" to the defines, but that doesn't seem to actually work.
I'm afraid I never used VS integration so I can barely suggest anything more... The thing is that dependencies are probably not set properly (i.e. files using this macro won't be automatically scheduled for compilation every time the macro changes...) so you may need a "rebuild all" (or whatever it is called) to get the version number actually taken into account by your code...

sdfisher
28th July 2007, 15:42
I think it's just a limitation of VS (not the integration, but of VS itself). It's okay. I can use that technique on other platforms.

fullmetalcoder
28th July 2007, 16:49
I think it's just a limitation of VS (not the integration, but of VS itself)
Well, I'd tend to think that it's actually a limitation of most, if not all, compilers... I'm willing to bet that no build system (may it be cmake, qmake, scons, ...) does such a smart dependency checking... Just rebuild all once you changed the version number or do a "dummy edit" in each file that rely on the version macro. Dummy edit means forcing the file to be saved, without really modifying it, which triggers dependency tracking of your build system, since most rely on time stamps and not file hash... It generally expands to typing a char then undo-ing the change and then saving...

jpn
6th August 2007, 21:22
Edit: DEFINES += VERSION_NUMBER="$${VERSION}" seems to have worked, though. Thanks for the nudge in the right direction.

Edit #2: Actually, that doesn't seem to work, either. It adds VERSION_NUMBER="1.2.0.1" to the defines, but that doesn't seem to actually work.
Does

DEFINES += VERSION_NUMBER=\\\"$${VERSION}\\\"
do what you want?

sdfisher
30th August 2007, 01:15
Yes, that worked. Thank you so much. I'd completely given up. :)