CMake module to get information about current git status.
To use FindGitInfo.cmake, simply add this repository as git submodule into your own repository
mkdir externals
git submodule add git://github.com/RWTH-HPC/CMake-gitinfo.git externals/CMake-gitinfo
and adding externals/cmake-gitinfo/cmake
to your CMAKE_MODULE_PATH
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/externals/cmake-gitinfo/cmake" ${CMAKE_MODULE_PATH})
If you don't use git or dislike submodules you can copy the FindGitInfo.cmake files into your repository. Be careful and keep updates in mind!
Now you can simply run find_package
in your CMake files:
find_package(GitInfo)
git_wc_info(${PROJECT_SOURCE_DIR} VARPREFIX)
message(STATUS "The current git hash is ${VARPREFIX_WC_REVISION_HASH}")
variable | description |
---|---|
<PREFIX>_WC_REVISION_HASH |
Current SHA1 hash |
<PREFIX>_WC_REVISION_NAME |
Name associated with <PREFIX>_WC_REVISION_HASH |
<PREFIX>_WC_LAST_CHANGED_DATE |
Date of last commit |
<PREFIX>_WC_LATEST_TAG |
Latest tag found in history |
<PREFIX>_WC_LATEST_TAG_LONG |
Latest tag found in history as long version. |
<PREFIX>_WC_GITSVN |
Indicate if git is a git svn |
The value of the following variables depends on <PREFIX>_WC_GITSVN
:
variable | <PREFIX>_WC_GITSVN true |
<PREFIX>_WC_GITSVN false |
---|---|---|
<PREFIX>_WC_REVISION |
Current SVN revision number | Same as <PREFIX>_WC_REVISION_HASH |
<PREFIX>_WC_URL , <PREFIX>_WC_ROOT |
URL of the associated SVN repository | Output of command git config --get remote.origin.url |
<PREFIX>_WC_INFO |
Output of command git svn info |
not available |
<PREFIX>_WC_LAST_CHANGED_AUTHOR |
Author of last commit | not available |
<PREFIX>_WC_LAST_CHANGED_REV |
Revision of last commit | not available |
<PREFIX>_WC_LAST_CHANGED_LOG |
Last log of base commit | not available |
-
git_version_info(PREFIX)
This macro sets your projects
*_VERSION
variables by versions found bygit describe --tags
. All you need to do is setting a tag likevX.Y
and you'll get a version likevX.Y-Z-<hash>
, wereZ
is the number of commits since the last tag andhash
the short hash of the currentHEAD
. All formats of tags are supported, but they have to include two numbers separated by a dot.You may pass a combination of these variables to the
VERSION
argument ofproject
, e.g.${NAME_VERSION_MAJOR}.${NAME_VERSION_MINOR}.${NAME_VERSION_PATCH}
.Example:
find_package(Gitinfo) git_version_info(NAME) message(STATUS "Configuring NAME version: ${NAME_VERSION} "(${NAME_VERSION_MAJOR}.${NAME_VERSION_MINOR}. "${NAME_VERSION_PATCH})")
~:$git describe --tags v1.5-beta-3-g7184473 ~:$cmake .. [...] -- Configuring NAME version v1.5-beta-3-g7184473 (1.5.3)
For packaging a
.version
file should be added, containing the output ofgit describe --tags
of the packed git version. Theproject-version-files-${PREFIX}
target generates this file, but is excluded from main. To generate all version files (even those of subprojects) before deploy, just depend onproject-version-files
. A list of all generated version files is accessible via theGIT_GENERATED_VERSION_FILES
GLOBAL
property. *NOTE: You may want to includeCPackDeploy
afterCPack
to add thepackage_deploy
target, which handles source packaging with version files automatically.If even no
.version
file could be found, the version won't be set and may be empty. Like infind_package
you may add theREQUIRED
parameter togit_version_info
, so it will print an error message instead of a warning, which will stop the execution ofCMake
.
Anyone is welcome to contribute. Simply fork this repository, make your changes in an own branch and create a pull-request for your change. Please do only one change per pull-request.
You found a bug? Please fill out an issue and include any data to reproduce the bug.