26. September 2016 3 min read

Git version in Doxygen from Makefile

When you generate a Doxygen documentation it is smart to also include version information inside. That happens when you share your documentation with others and they might be interested if there were any updates from since others read it. This is actually quite simple as you can pass environment variables to Doxygen, so all you need to do is create a environment variable VERSION and fill it with contents, then reference that in Doxygen.
There are couple of ways to fill the environment variable and also couple of ways to get nice human readable Git version information, but I suggest using tags and command:

git describe --always --long --abbrev=8 --dirty
# git describe : provide most recent reachable tag and offset from it
# --always : In case there is no tag, just fall back to whatever it is
# --long : Always output the long and same format, even when it matches tag. That way you also can see in case tag was moved
# --abbrev : Number of fields for commit message
# --dirty : Tell if it was generated with uncommited changes

Above command will be used inside Makefile. Before we get to executing of above command lets edit our doxyfile. In Doxyfile you can simply reference environment variable and most suitable is the:

# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version
# control system is used.


Since you are likely to include your version somewhere else (like in binary) the global export in Makefile might not be the best solution. So to avoid that just call export before doxygen command inside doxy target. Makefile with all above will look something like:

# Extract current version from library git repo
VERSION = $(shell echo `git describe --always --long --abbrev=8 --dirty`)

# Add version to source file

.PHONY doxy

	export VERSION=$(VERSION) && doxygen doxyfile

Newest from this category: