[CMake] Putting the git commit hash in a cmake variable

Elvis Stansvik elvis.stansvik at orexplore.com
Fri Oct 12 03:11:51 EDT 2018


Den fre 12 okt. 2018 00:24Matt Schulte <schultetwin1 at gmail.com> skrev:

> 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!
>

Yes, I should have mentioned this downside. In our case it was acceptable
as our configuration step is rather quick.

Tangential note from me re. developer experience: Yesterday I tried out
zapcc for local development, and it really is fast:

  https://github.com/yrnkrn/zapcc

Takes a bit of memory of course.

Elvis

>
> -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
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20181012/3697c7eb/attachment.html>


More information about the CMake mailing list