- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Apologies if this is a really easy question, but how do you add an automated compile date to your code? I tried doing this using the pre-processor, but couldn't find a symbol for datetime. Any hints?
Thanks
John
Thanks
John
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The Fortran preprocessor does not have such a symbol, as far as I know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We had a similar thread on automatic increase of version (in the .rc file) with every build (I can dig out the thread if you wish), using a Visual Studio macro. However, without preprocessor support, it would pose a problem if you want to embed it in the code: changing the build timestamp in the code would alter it, triggering a build -- it's a catch-22.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The only methods that I can think of are:
From Visual Studio
- Add a pre-build event
- Feed your code through the C preprocessor and use the __DATE__ and __TIME__ predefined macros. The alternative to using the C preprocessor is to write a small program that will insert the current date and time
From command line using make (or nmake)
- Create a rule for building .obj from .F90 (traditionally only .F file names are run through a preprocessor, but you don't have to follow that convention)
In that rule invoke the C preprocessor or a custom written program
I have not tested it out, so I won't say it will work for sure.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you can fiigure out a way to modify the build options, you could change the value of a /D switch used to compile the source. Another possibility is to use a pre-build step to write an include file that is used to define the date.
I'd also suggest that you file a feature request for adding date and time symbols to the Fortran preprocessor with Intel Premier Support.
I'd also suggest that you file a feature request for adding date and time symbols to the Fortran preprocessor with Intel Premier Support.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks all for your suggestions. They helped quite a bit and inspired me to come up with a python pre-build step. I'm sure this is not optimal, but it works.
Python script "setcompiledate.py"
Build Steps
Python script "setcompiledate.py"
import datetimeSample Fortran code "main.f90"
today = datetime.date.today()
fout = open("verno.h", "w")
fout.write( today.strftime("#define CompileDate %Y%m%d") )
program Hello
#include "verno.h"
!DEC$ IF DEFINED (CompileDate)
write( * , "(A,I8)" ) " Compiled on date: ",CompileDate
!DEC$ ENDIF
write( * , * ) "Hello World"
end program Hello
Build Steps
- Run setcompiledate.py
- Build ifort -fpp main.f90

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page