Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Adding a compile date to your code

JohnR
Beginner
2,009 Views
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
0 Kudos
5 Replies
Steven_L_Intel1
Employee
2,009 Views
The Fortran preprocessor does not have such a symbol, as far as I know.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
2,009 Views
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.
0 Kudos
Dishaw__Jim
Beginner
2,009 Views
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.

0 Kudos
Steven_L_Intel1
Employee
2,009 Views
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.
0 Kudos
JohnR
Beginner
2,009 Views
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"
import datetime
today = datetime.date.today()
fout = open("verno.h", "w")
fout.write( today.strftime("#define CompileDate %Y%m%d") )

Sample Fortran code "main.f90"
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
  1. Run setcompiledate.py
  2. Build ifort -fpp main.f90
0 Kudos
Reply