Fwiw, this is my single most popular stack overflow post (and presumably my
most popular CMake module)
https://stackoverflow.com/questions/1435953/how-can-i-pass-git-sha1-to-compiler-as-definition-using-cmake/4318642#4318642
It does incorporate the other ideas that have come up, like making a
Sorry if this shows up oddly on the list; I was forwarded the original
in order to reply. As such, please keep me in Cc.
> I'd like to set a CMake variable to the current git commit short hash.
> This variable will be used as part of the version string for my
> project (ex:
Den fre 12 okt. 2018 00:24Matt Schulte 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
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
> 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
Den tors 11 okt. 2018 kl 18:28 skrev Matt Schulte :
>
> Thanks Isaiah and Michael.
>
> Both solutions work great if you just want to generate a header file
> that contains the git commit hash. I have seen these solutions before.
> I'd like to go a little farther and have the current commit hash
>
Thanks Isaiah and Michael.
Both solutions work great if you just want to generate a header file
that contains the git commit hash. I have seen these solutions before.
I'd like to go a little farther and have the current commit hash
available in a CMake variable. This means CMake must re-configure
You could use a custom_target() instead, where that target is a simple
shell/batch file that runs the needed git command and creates a simple header
file. Then your main executable/library targets are dependent on that
custom_target() so that it is run every time. We do something similar in our
Similar question with some suggestions in response:
https://cmake.org/pipermail/cmake/2018-July/067887.html
Best,
Isaiah
On Wed, Oct 10, 2018 at 5:05 PM Matt Schulte wrote:
> Hi all,
>
> I'd like to set a CMake variable to the current git commit short hash.
> This variable will be used as
Hi all,
I'd like to set a CMake variable to the current git commit short hash.
This variable will be used as part of the version string for my
project (ex: "1.0.1+git.${SHORT_HASH}"). I can get at this short hash
by using execute_process and setting the resulting output to a
variable.
```cmake
10 matches
Mail list logo