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!
I’ve also worked on something like that here, so I can offer a few tips:
.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?
Thank you @Lecris for the pointers. I see your DynamicVersion script is quite nicely packed with features I did not even thought I needed!
Wow! It even has testing! I see it also detects git changes!
I am quite new to CMake but those examples really help me improve this and maybe other modules I may try to implement soon.