[CMake] Putting the git commit hash in a cmake variable
Matt Schulte
schultetwin1 at gmail.com
Thu Oct 11 18:24:12 EDT 2018
Ah, that's a good tip Elvis. The CONFIGURE_DEPENDS on the .git/index
would do the trick. I can set that up for now.
In the long run, its not that ideal because it forces a reconfigure on
every commit (which is annoying for developers at their desk).
My example above is actually a little more complex in real life. I
just simplified it for this e-mail. We only append the git hash to our
version string if we are on certain branches. So our version string
doesn't change on feature branches.
For now I think we'll bite the bullet and re-configure on every
commit. I'll keep mulling over the how to set this up. Thanks for the
idea!
-Matt
On Thu, Oct 11, 2018 at 12:26 PM Chuck Atkins <chuck.atkins at kitware.com> wrote:
>
>
>> COMMAND "${GIT_EXECUTABLE}" describe --always HEAD
>
>
> git describe is nice way to do it since you can get a monotonic-ish increasing version number
>
>
>>
>> string(REGEX REPLACE "^.*-(.*)-g.*$" "\\1" MYAPP_VERSION_MICRO "${MYAPP_VERSION}")
>> ...
>> set(MYAPP_VERSION_MICRO "0")
>
>
> Only tangentially related, CMake commands and functions that deal with version information refer to the 4th component as _TWEAK.
>
> - Chuck
>
More information about the CMake
mailing list