Has anybody used __DATE__ and __TIME__ to good effect to render compilation date/time in a string, say in a plugin window to be able to keep track of the exact alpha or beta version one is running?
I’ve seen mixed advice on using these.
Has anybody used __DATE__ and __TIME__ to good effect to render compilation date/time in a string, say in a plugin window to be able to keep track of the exact alpha or beta version one is running?
I’ve seen mixed advice on using these.
Here is what I typically use, in a dedicated dev popup menu:
{ // compilation date, juce version, build type
menu.addItem(juce::String(__DATE__) + ", " + juce::String(__TIME__), false, false, nullptr);
#if JUCE_DEBUG
juce::String build = "debug";
#else
juce::String build = "release";
#endif
menu.addItem("JUCE " + juce::String(JUCE_MAJOR_VERSION) + "." + juce::String(JUCE_MINOR_VERSION) + "." + juce::String(JUCE_BUILDNUMBER) + " (" + build + ")", false, false, nullptr);
}
In addition to date & time, you may also include git commit hash to track the commit.
if (GIT_EXECUTABLE)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
OUTPUT_VARIABLE GIT_CURRENT_HASH
RESULT_VARIABLE GIT_HASH_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT GIT_HASH_ERROR_CODE)
set(FOOBAR_HASH ${GIT_CURRENT_HASH})
endif ()
endif ()
| static Time Time::getCompilationDate | ( | ) | ||
|---|---|---|---|---|
Returns a Time based on the value of the DATE macro when this module was compiled.
References getCompilationDate(), and Time().
Referenced by getCompilationDate()
This is what I was using, but for me it apparently stays stuck on 1 April this year.
#if PLUGIN_PRERELEASE
Time time (Time::getCompilationDate());
lblVersion->setText ("v0.9 beta " +
String (time.getDayOfMonth()) + " " + time.getMonthName (true) + " " + String (time.getYear()) + " " +
String (time.getHours()) + ":" + String (time.getMinutes()), dontSendNotification);
#endif
How do I force compilation of this ‘module’, which I think means this file (called AboutWindow.cpp), every build? I’m on macOS on XCode if that matters.
I would inject it as a string from your build system, rather than doing it within your JUCE app itself. E.g. using CMake’s string(TIMESTAMP ...). If you’re not using cmake then you could use a bash or python script or something and set it in your projucer project
Clean and build
That’s the ticket, but is there a way to mark a certain file as always recompile?
To answer ImJimmi, that’s a great idea, I don’t have a build system yet..
touch path/to/your/file.cpp
This is almost certainly a bug of some kind: JUCE/modules/juce_core/juce_core_CompilationTime.cpp at develop · juce-framework/JUCE · GitHub
I recommend sharing system + build env details to help shed light…
The thing about this is that you should be able to clean/rebuild your project and see this being changed.
Yes but I wasn’t doing a clean in between, so that makes sense
I’ve found it really handy to combine __DATE__ / __TIME__ with a git commit hash — that way you know exactly which source state the build came from. Cleaning before rebuild (as mentioned above) is key, otherwise the timestamp can get stuck. If you’re already using CMake, string(TIMESTAMP …) works great too for injecting a fresh build time automatically.