Just wanted to mention that a similar module I wrote is my most popular stack overflow post and had seen a number of pull requests and acknowledgements, so it's seemingly widely used. While it's slightly more complicated than required (when i first wrote it, I thought you had to use the configured file to get it generated) it does pretty reliably work, including with submodules. I'm happy to relicense it for inclusion with CMake. (Bsl should be more permissive anyway) SO answer: http:// <http://stackoverflow.com/a/4318642/265522> stackoverflow.com <http://stackoverflow.com/a/4318642/265522> /a/4318642/265522 <http://stackoverflow.com/a/4318642/265522>
Module: https <https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake> :// <https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake> github.com <https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake> / <https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake> rpavlik <https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake> / <https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake> cmake-modules <https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake> /blob/master/ <https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake> GetGitRevisionDescription.cmake <https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake> Sample usage in practice: https <https://github.com/OSVR/OSVR-Core/blob/master/cmake-local/Version.cmake>:// <https://github.com/OSVR/OSVR-Core/blob/master/cmake-local/Version.cmake> github.com <https://github.com/OSVR/OSVR-Core/blob/master/cmake-local/Version.cmake> /OSVR/ <https://github.com/OSVR/OSVR-Core/blob/master/cmake-local/Version.cmake> OSVR-Core <https://github.com/OSVR/OSVR-Core/blob/master/cmake-local/Version.cmake> /blob/master/ <https://github.com/OSVR/OSVR-Core/blob/master/cmake-local/Version.cmake> cmake-local <https://github.com/OSVR/OSVR-Core/blob/master/cmake-local/Version.cmake>/ <https://github.com/OSVR/OSVR-Core/blob/master/cmake-local/Version.cmake> Version.cmake <https://github.com/OSVR/OSVR-Core/blob/master/cmake-local/Version.cmake> One addition I would have liked to have but haven't had time to do yet: the ability to have a add custom command-based build time generation, instead of our in addition to the CMake time generation. Some projects take a very long time to generate, may cause visual studio to needlessly reload project files, and you may only want the revision for a header file anyway. As you can imagine, this would share much implementation with the configure time code, and the prerequisite refactoring is why I haven't gotten around to doing it yet. Hope this is useful and saves some time reinventing wheels. Ryan On Tue, Oct 6, 2015, 4:41 PM Ben Boeckel <ben.boec...@kitware.com> wrote: > On Mon, Oct 05, 2015 at 12:50:41 +0200, Daniel Wirtz wrote: > > thanks for the feedback, i've included most of it. > > > > Regarding the configure/build issue: that indeed is inconvenient and may > > cause irritation. on the other side, if there has been git activity > > fussing with any source files affecting the build, cmake will run again > > and hence capture the possibly new git info. so the case where you > > change the revision after configure to an extent where cmake will not > > automatically re-run is uncommon, at least for my guessing. > > however, i've included an explicit warning in the docs to raise > awareness. > > Well, without depending on every file in the source tree, it will just > be wrong rather than causing excess configure runs. Adding something > like "configure this file at build time" setup would need to be the > basis though (basically porting and cleaning up sprokit_configure_file() > into CMake as deferred_configure_file() or something similar would work). > > > i'm happy to provide a suitable procedure that is flexible enough; > > providing scripts that configure files (like with sprokit) seems too > > specific as people might want to have a single "config.h" file or so > > containing more than just the git info. > > The sprokit mechanism configures any file using code to determine some > of the variables at build time. It is by no means limited to just header > files. The code injection is a little clunky (being a string and all), > but it could also be changed to an include() statement with an extra > depends on that included file. In fact, with include(), adding support > for SVN, Mercurial and others would be pretty simple as well rather than > duplicating all this for each revision system. > > > i've thought about the possibility to generate an explicit > > "git_version.h" file to include, but that 1) restricts possible > > languages and 2) will require an extra build target that is run each > > build etc. any thoughts? > > Well, you will indeed never have a "nothing to do" build with such a > target, but such information is effectively derived from "this depends > on every file in the tree tracked by git as well as the .git/HEAD, > .git/index, and .git/refs/tags/* files" so "always something to do" > isn't that far off. The step (in sprokit) takes ~0 time to run > anyways[1], so speed isn't an issue. > > --Ben > > [1]45 build trees took < 2 seconds, so figuring for some overhead for > exec() of ninja itself and ninja scanning, the overhead for checking the > git revision is < .05s for a smallish source tree. Something like > webkit's git mirror could take a while though. > -- > > Powered by www.kitware.com > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Kitware offers various services to support the CMake community. For more > information on each offering, please visit: > > CMake Support: http://cmake.org/cmake/help/support.html > CMake Consulting: http://cmake.org/cmake/help/consulting.html > CMake Training Courses: http://cmake.org/cmake/help/training.html > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > > Follow this link to subscribe/unsubscribe: > http://public.kitware.com/mailman/listinfo/cmake-developers >
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers