CMake module for Git version detection

It seems that many projects may be able to automatically detect source code version from git tags but many don’t do it. I have also found other versions of similar scripts that are able to detect Git versions but it is difficult to locate a single source for a maintained alternative.

For the above reasons, I wanted to share my take on Git version detection for CMake projects. You can find it at GitHub - antoniovazquezblanco/cmake-gitversiondetect: Make GIT versioning info available in your CMakeLists.txt file

Any feedback would be apreciated! Thanks!

1 Like

I’ve also worked on something like that here, so I can offer a few tips:

  • support .git_archival.txt for git archives
  • needs a target that would re-trigger builds when a commit/tag is created
  • git describe tags should allow for different version formats
  • packaging for other projects to use via FetchContent/find_package?
1 Like

Thank you @Lecris for the pointers. I see your DynamicVersion script is quite nicely packed with features I did not even thought I needed!

Awesome!

We use this project: cmake-git-version-tracking/git_watcher.cmake at master · andrew-hardin/cmake-git-version-tracking · GitHub

2 Likes

Wow! It even has testing! I see it also detects git changes! :smiley:

I am quite new to CMake but those examples really help me improve this and maybe other modules I may try to implement soon.

Thank you! :slight_smile: