I would like my Qt/C++ application to know which version it is. It should know that not from some configuration files, but with version number compiled into application binary. A version itself is string like "X.Y.Z", where X is a major version number, Y is a minor version number and Z is a revision under SVN (or a revision number under SVN minus a revision number when version "X.Y.0" came out). What would you think is the simplest way to accomplish this with scons?
SCons has Substfile
and Textfile
builders for generating files. So create a function to calculate the version (using pysvn or by calling svn
command) and write it's output to a file using Substfile
(takes template from a file) or Textfile
(just writes provided content). Than compile and link that file with the rest of the application.
The file should be a source file (not a header) with content like (assuming C/C++, but the same technique would be appropriate with any language):
char *VERSION = "X.Y.Z";
(and any other alternate formats you want) and declare
extern char *VERSION;
somewhere, than only the one file will be recompiled plus the application relinked (which it will anyway, because some other sources probably changed too, right).
Here are some more answers that came from [scons-users] mailing list.
Brian Cody:
One command line option we pass into scons is the repository version of the SVN rep. We then put this number into a define (-DREP_NUM=\"123\") and build a string in our C++ code that uses this number. That's for our server run builds. For local builds, we actually use the username instead of the version number, because someone's local build of version XYZ doesn't necessarily equal someone else's XYZ (in windows, the env var USERNAME contains the logged-in user). One other consideration is that changing any part of a compilation statement in scons means that the target is automatically out-of-date. To work around this issue our build system picks out the one object target that actually cares about the flags and it only passes the flags to the compilation of that one object.
Good luck
Gary Oberbrunner:
I would like my Qt/C++ application to know which version it is.
There's some info at http://www.scons.org/wiki/BuildNumberProcessing which may be helpful.
-- -- Gary
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With