Add the version number in iclude files

Hi Algiane and Luca,

it would be very nice to have information on the version number inside a dedicated .h file.
This will greatly facilitate the maintenance of our code when the interface of a function changes from one version to the other…

This can be implemented like this this (inspired from PETSC):
#if !defined(MMGVERSION_H)
#define MMGVERSION_H

#define MMG_VERSION_RELEASE 5
#define MMG_VERSION_MAJOR 4
#define MMG_VERSION_MINOR 4
#define MMG_VERSION_SUBMINOR 0
#define MMG_VERSION_PATCH 0
#define MMG_RELEASE_DATE “Oct 1, 2020”

#define MMG_VERSION_EQ(MAJOR,MINOR,SUBMINOR)
((MMG_VERSION_MAJOR == (MAJOR)) &&
(MMG_VERSION_MINOR == (MINOR)) &&
(MMG_VERSION_SUBMINOR == (SUBMINOR)) &&
(MMG_VERSION_RELEASE == 5))

#define MMG_VERSION_ MMG_VERSION_EQ

#define MMG_VERSION_LT(MAJOR,MINOR,SUBMINOR)
(MMG_VERSION_RELEASE == 5 &&
(MMG_VERSION_MAJOR < (MAJOR) ||
(MMG_VERSION_MAJOR == (MAJOR) &&
(MMG_VERSION_MINOR < (MINOR) ||
(MMG_VERSION_MINOR == (MINOR) &&
(MMG_VERSION_SUBMINOR < (SUBMINOR)))))))

#define MMG_VERSION_LE(MAJOR,MINOR,SUBMINOR)
(MMG_VERSION_LT(MAJOR,MINOR,SUBMINOR) ||
MMG_VERSION_EQ(MAJOR,MINOR,SUBMINOR))

#define MMG_VERSION_GT(MAJOR,MINOR,SUBMINOR)
(0 == MMG_VERSION_LE(MAJOR,MINOR,SUBMINOR))

#define MMG_VERSION_GE(MAJOR,MINOR,SUBMINOR)
(0 == MMG_VERSION_LT(MAJOR,MINOR,SUBMINOR))

#endif

which can then be used (in Fortran) as:
#include “mmgversion.h”
#if MMG_VERSION_LE(5,4,3)
call MMG2D_SET_MESHSIZE(mesh,np,nt,na,retval)
#else
call MMG2D_SET_MESHSIZE(mesh,np,nt,nquad,na,retval)
#endif
#endif

Ideally, it could also include information about the git branch (master, develop, …)
In the above example, the interface is different between the last official release (5.4.3) and the development branch: this is not easy to track (maybe the develop branch could be indicated with a patch number >0)…

Thanks!
Ghislain

Hi Ghislain,

Thank you for this suggestion and the detailed example. I will try to add this for the next release.

Have a nice day,

Algiane

Hi Ghislain,

I have used your example to add an mmgversion.h file to the Mmg headers (it is included in the libmmg<X>.h file so it is not mandatory to include it too).

I just use a lighter convention than the PETSC one (because we don’t need as much levels as them and I wanted to respect the old Mmg numbering) :

  • MMG_VERSION_RELEASE is the entire version info (5.4.1 for example);
  • MMG_VERSION_MAJOR is the major release info (5);
  • MMG_VERSION_MINOR is the minor release info (4);
  • MMG_VERSION_PATCH is the patch info (1), it should not break the API.

Consequently, the MMG_VERSION_{LE,LT,EQ,GT,GE} macros take only the MAJOR and MINOR arguments.

If you want, you can ß-test it in the develop branch since commit 647ca97.

Kind regards,

Algiane