[CMake] Addition to FindGit

Brad King brad.king at kitware.com
Mon Jun 6 14:31:31 EDT 2011


On 06/05/2011 05:02 AM, Quintus wrote:
> I'm working on a git-versioned project that I'd like to display it's
> version number for development versions like this:
>
> 1.2.3-dev (commit abc1234 on devel, 12/4/10)

FYI, consider using "git describe" for versions.

> CMake's FindGit module seems to be quite limited as it just gives me the
> path to git's executable file, leaving it on me to invoke the necessary
> EXECUTE_PROCESS() commands to find the current git branch and commit.

Most Find* modules provide only the basic search results.  A few of them
try to provide some kind of API to simplify use of the package.  This saves
a lot of boilerplate CMake code in cases that the same thing appears in
many projects.  Since Git is so flexible and has so many different ways
to work I'm not convinced it makes sense in this case.  However, I think
getting the current branch will be a fairly common use case.

> Inspired by this, I wrote another function to get the current branch:

I think the proper way to do this is actually

  git symbolic-ref -q HEAD

which prints out "refs/heads/$branch" or returns non-zero in the case
of a detached head.  This uses git's plumbing which is meant for machine
consumption and will always have a stable API.

> Any chance to get this and the function from the evemu project into
> official CMake's FindGit.cmake?

Our policy for module contributions is documented here:

  http://www.cmake.org/Wiki/CMake:Module_Maintainers

> I'm not sure about their license, but the sourcecode seems to be
> licensed under LGPL

That is not compatible with CMake's OSI-approved BSD license.

-Brad


More information about the CMake mailing list