A Fortran module plus helper Makefile and CMake module for capturing the git version of your project in your application or library.
The implementation is split out into a Fortran submodule in order to
avoid re-compilation cascades from use of the parent module.
Fortran-git-version requires git and a Fortran compiler that supports
submodules -- this should be any recent-ish compiler, for example
gfortran has supported Fortran submodules since version 6.
Fortran-git-version can be either copied wholesale into your project,
or used as a git submodule. The module git_version provides the
following functions:
get_git_version: returns the version number fromgit describeget_git_hash: returns the hash of the latest commitget_git_state: returns "-dirty" if there are local modifications, otherwise the empty stringget_git_date: returns the short timestamp (YYYY-MM-DD) of the latest commit
The full version as returned from get_git_version is the output of
git describe --tags --always --dirtySee git describe --help for a full description,
but this gives a version number in the form
<tag>[-N[-g<hash>][-dirty]], where N is the number of commits
since the latest <tag>.
You can use Fortran-git-version in your CMake project like so:
add_subdirectory(fortran-git-version)
target_link_libraries(<your target> PRIVATE fortran_git::fortran_git)There are three configuration options:
FORTRAN_GIT_WORKING_TREE: set the working tree to get thegitinformation fromFORTRAN_GIT_DEBUG: print some extra information during the configure/build processFORTRAN_GIT_BUILD_EXAMPLES: build the example program
You normally shouldn't need to set FORTRAN_GIT_WORKING_TREE as it
should be worked out automatically, but there may be scenarios where
you need to set it manually. For example, where you have embedded
fortran-git-version in a project without using a git submodule,
and your project is then used in another project as a git
submodule. In this case, fortran-git-version would pick up the
version from the parent superproject, rather than your project. You
would then need to explicitly set FORTRAN_GIT_WORKING_TREE in your
project to CMAKE_CURRENT_SOURCE_DIR.
Fortran-git-version comes with a makefile snippet that you can incorporate into your project. It has one option:
FORTRAN_GIT_WORKING_TREE: set the directory to run thegitexecutable in. Defaults to.
It creates a variable FORTRAN_GIT_DEFS that you should add to the
compilation line. You will need to compile src/git_version.f90, and
preprocess and compile src/git_version_impl.F90.
Warning: the makefile snippet is much less developed than the CMake implementation, so use at your own risk!