CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Bugs (http://www.cfd-online.com/Forums/openfoam-bugs/)
-   -   Foam Version as a compile-time macro (http://www.cfd-online.com/Forums/openfoam-bugs/64128-foam-version-compile-time-macro.html)

deepsterblue April 29, 2009 18:35

Foam Version as a compile-time macro
 
Just a suggestion, but perhaps it would be useful to have the Foam version as a compile-time macro. For example, something like this for OF-1.5:

#define FOAM_MAJOR_REVISION 1
#define FOAM_MINOR_REVISION 5

Or something on similar lines (Maybe passed in to g++ with a -D option). Considering how member functions change over revisions, (like faceOwner instead of allOwner in polyMesh, for instance), backward compatibility is sometimes an issue. I agree that it makes code uglier because of #ifdefs all around the source code, but it might be handy to have...

olesen May 25, 2009 05:36

Quote:

Originally Posted by deepsterblue (Post 214699)
Just a suggestion, but perhaps it would be useful to have the Foam version as a compile-time macro. For example, something like this for OF-1.5:

#define FOAM_MAJOR_REVISION 1
#define FOAM_MINOR_REVISION 5

wmake already has/had a PROJECT_VERSION defined as major, 3 digits minor and 3 digits revision.
For example, 1.5 == -DPROJECT_VERSION=1005000.
Unfortunately this breaks down horribly when versions contain non-digits (eg, like 1.5.x). I would thus avoid using it at all.

IMO the better method is to keep your code up-to-date with the latest developments and use branching within git if you also need to maintain code for legacy versions. This is not only much cleanier to read than piles of #ifdefs, but also avoids strange and possibly hard to trace bugs. For example, if you'd moved from 1.5 to 1.5.x, the wrong chunk would get evaluated here:
Code:

#if PROJECT_VERSION >= 1005000
chunk1 ...
#else
chunk2 ...
#endif

I think the need for using PROJECT_VERSION disappeared with the introduction of git for version control. I wouldn't be surprised if PROJECT_VERSION disappeared in a future version, but you can copy the same idea in your own Make/options if you'd like.


All times are GMT -4. The time now is 16:02.