6

is there a way to get information for Doxygen from git: For instance for:

@version
@author
@date 

The information should be automatically included in the Doxygen comments.

For @version it would be nice to get maybe the tag information.

Many thanks in advance!

Stefan
  • 99
  • 1
  • 2
  • 5
  • 2
    possible duplicate of [git revision number in source code documentation](http://stackoverflow.com/questions/7016300/git-revision-number-in-source-code-documentation) – CharlesB Feb 22 '12 at 10:43
  • 2
    Read [this answer](http://stackoverflow.com/questions/62264/dealing-with-svn-keyword-expansion-with-git-svn#72874) – Lazy Badger Feb 22 '12 at 15:56

1 Answers1

6

I realize this is an older question, but I was just trying to do the same thing.

Neither of the linked answers in the comments are a great solution to this issue. We may want to include e.g. a git revision in the generated documentation without mucking about with git filters and so forth in our working sources.

Fortunately, Doxygen supports the use of environment variables in your Doxyfile, and provides various settings that can be used to place information in your generated content. The PROJECT_NUMBER setting is meant explicitly for including version control information in your documentation.

If we have this in our Doxyfile:

PROJECT_NUMBER = $(PROJECT_NUMBER)

You can run doxygen like this to include the git revision in your generated docs:

PROJECT_NUMBER=$(git rev-parse --short HEAD) doxygen

You're not limited to just the commit id, either. For example:

PROJECT_NUMBER=$(git log -1 --format "%h (%cd)") doxygen

This makes the title in my generated HTML look like:

<div id="projectname">MyProject
&#160;<span id="projectnumber">9dd847b (Fri Feb 1 15:36:13 2019 -0500)</span>
</div>
larsks
  • 277,717
  • 41
  • 399
  • 399
  • Note that this technique also works on Windows, though you will (probably) want to have a wrapper script and use one of the techniques described [here](https://stackoverflow.com/questions/2768608/batch-equivalent-of-bash-backticks) – ddulaney Mar 02 '21 at 16:13
  • One can also just append the new definition of `PROJECT_NUMBER` to the configuration. For example I have this as a pre-build step in Jenkins: `echo "PROJECT_NUMBER = \"version in git: \""$(git describe --always --dirty --long) >> doxyfile-jenkins.cfg`. Where `doxyfile-jenkins.cfg` is a local copy of the configuration not part of the git index. – user5534993 Mar 16 '21 at 16:15