--- /dev/null
+# The module defines the following variables:
+# GIT_EXECUTABLE - path to git command line client
+# GIT_FOUND - true if the command line client was found
+# Example usage:
+# find_package(Git)
+# if(GIT_FOUND)
+# message("git found: ${GIT_EXECUTABLE}")
+# endif()
+
+#=============================================================================
+# Copyright 2010 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distributed this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+# Look for 'git' or 'eg' (easy git)
+#
+set(git_names git eg)
+
+# Prefer .cmd variants on Windows unless running in a Makefile
+# in the MSYS shell.
+#
+if(WIN32)
+ if(NOT CMAKE_GENERATOR MATCHES "MSYS")
+ set(git_names git.cmd git eg.cmd eg)
+ endif()
+endif()
+
+find_program(GIT_EXECUTABLE
+ NAMES ${git_names}
+ DOC "git command line client"
+ )
+mark_as_advanced(GIT_EXECUTABLE)
+
+# Handle the QUIETLY and REQUIRED arguments and set GIT_FOUND to TRUE if
+# all listed variables are TRUE
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Git DEFAULT_MSG GIT_EXECUTABLE)
# GEN_VERSION_INFO_INTERNAL has to be set ON.
#
# The following variables have to be previously defined:
-# Git_EXECUTABLE - path to git binary
-# Git_VERSION - git version (if not defined it's assumed that >=1.5.3)
+# GIT_EXECUTABLE - path to git binary
+# GIT_VERSION - git version (if not defined it's assumed that >=1.5.3)
# PROJECT_VERSION - hard-coded version string, should have the following structure:
# VERSION[-dev-SUFFIX] where the VERSION can have any form and the suffix
# is optional but should start with -dev
# if git executable xists and it's compatible version
# build the development version string
# this should at some point become VERSION_LESS
-if(EXISTS ${Git_EXECUTABLE} AND NOT Git_VERSION STRLESS "1.5.1")
+if(EXISTS ${GIT_EXECUTABLE} AND NOT ${GIT_VERSION} STRLESS "1.5.1")
# refresh git index
- execute_process(COMMAND ${Git_EXECUTABLE} update-index -q --refresh
+ execute_process(COMMAND ${GIT_EXECUTABLE} update-index -q --refresh
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
TIMEOUT 5
OUTPUT_QUIET
)
# get the full hash of the current HEAD
- execute_process(COMMAND ${Git_EXECUTABLE} rev-parse HEAD
+ execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GMX_GIT_HEAD_HASH
ERROR_VARIABLE EXEC_ERR
string(SUBSTRING ${GMX_GIT_HEAD_HASH} 0 5 HEAD_HASH_SHORT)
# if there are local uncommitted changes, the build gets labeled "dirty"
- execute_process(COMMAND ${Git_EXECUTABLE} diff-index --name-only HEAD
+ execute_process(COMMAND ${GIT_EXECUTABLE} diff-index --name-only HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE SRC_LOCAL_CHANGES
ERROR_VARIABLE EXEC_ERR
# if git is older then 1.5.3 we need to extract the RFC2822 style date
# and massage it, otherwise the ISO 8601 format is more trusworthy
# this should at some point become VERSION_LESS
- if (NOT Git_VERSION STREQUAL "" AND Git_VERSION STRLESS "1.5.3")
- execute_process(COMMAND ${Git_EXECUTABLE} rev-list -n1 "--pretty=format:%cD" HEAD
+ if (NOT GIT_VERSION STREQUAL "" AND GIT_VERSION STRLESS "1.5.3")
+ execute_process(COMMAND ${GIT_EXECUTABLE} rev-list -n1 "--pretty=format:%cD" HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE HEAD_DATE
ERROR_VARIABLE EXEC_ERR
string(REGEX REPLACE "DEC" "12" HEAD_DATE ${HEAD_DATE})
else()
# get the date of the HEAD commit
- execute_process(COMMAND ${Git_EXECUTABLE} rev-list -n1 "--pretty=format:%ci" HEAD
+ execute_process(COMMAND ${GIT_EXECUTABLE} rev-list -n1 "--pretty=format:%ci" HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE HEAD_DATE
ERROR_VARIABLE EXEC_ERR
set(VERSION_STR_SUFFIX "${HEAD_DATE}-${HEAD_HASH_SHORT}${DIRTY_STR}")
# find the name of the remote which is located on the official gromacs git server
- execute_process(COMMAND ${Git_EXECUTABLE} config --get-regexp
+ execute_process(COMMAND ${GIT_EXECUTABLE} config --get-regexp
"remote\\..*\\.url" "git\\.gromacs\\.org[:|/]gromacs"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GMX_REMOTE
# find the first ancestor in the list provided by rev-list (not
# necessarily the last though) which is in GMX_REMOTE, extract the
# hash and the number of commits HEAD is ahead with
- execute_process(COMMAND ${Git_EXECUTABLE} rev-list --max-count=100 HEAD
+ execute_process(COMMAND ${GIT_EXECUTABLE} rev-list --max-count=100 HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE ANCESTOR_LIST
)
set(AHEAD 0)
set(GMX_GIT_REMOTE_HASH "")
foreach(OBJ ${ANCESTOR_LIST})
- execute_process(COMMAND ${Git_EXECUTABLE} name-rev --refs=refs/remotes/${GMX_REMOTE}/* ${OBJ}
+ execute_process(COMMAND ${GIT_EXECUTABLE} name-rev --refs=refs/remotes/${GMX_REMOTE}/* ${OBJ}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE HASH_AND_REVNAME
OUTPUT_STRIP_TRAILING_WHITESPACE