Well-liked and a simple solution.
First. Add this pre-build step to your Visual Studio project:
1 |
echo #define DBJ_BUILD_TIMESTAMP __DATE__ " " __TIME__ > build_time_stamp.inc |
That little inc
, contains a compile-time constant in both C and C++. I usually include it in my main
C or CPP file.
1 |
#include "build_time_stamp.inc" |
Since it is generated on each build, it provokes (re)compilation of main
Usage might be
1 |
printf( "\nBuild time stamp: %s", DBJ_BUILD_TIMESTAMP); |
If you do not want to be bothered by GIT to commit/sync/push, that inc file, after each build, simply do not include it in a project.
In any case, if you want to use it in some more complex scenario, simply keep it in a global constant:
1 |
/* C++ */ constexpr auto build_time_stamp = DBJ_BUILD_TIMESTAMP ; |
Enjoy …