Warning, /acts/cmake/GetGitRevisionDescription.cmake is written in an unsupported language. File is not indexed.
0001 # - Returns a version string from Git
0002 #
0003 # These functions force a re-configure on each git commit so that you can
0004 # trust the values of the variables in your build system.
0005 #
0006 # get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
0007 #
0008 # Returns the refspec and sha hash of the current head revision
0009 #
0010 # git_describe(<var> [<additional arguments to git describe> ...])
0011 #
0012 # Returns the results of git describe on the source tree, and adjusting
0013 # the output so that it tests false if an error occurs.
0014 #
0015 # git_get_exact_tag(<var> [<additional arguments to git describe> ...])
0016 #
0017 # Returns the results of git describe --exact-match on the source tree,
0018 # and adjusting the output so that it tests false if there was no exact
0019 # matching tag.
0020 #
0021 # git_local_changes(<var>)
0022 #
0023 # Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
0024 # Uses the return code of "git diff-index --quiet HEAD --".
0025 # Does not regard untracked files.
0026 #
0027 # Requires CMake 2.6 or newer (uses the 'function' command)
0028 #
0029 # Original Author:
0030 # 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
0031 # http://academic.cleardefinition.com
0032 # Iowa State University HCI Graduate Program/VRAC
0033 #
0034 # Copyright Iowa State University 2009-2010.
0035 # Distributed under the Boost Software License, Version 1.0.
0036 # (See accompanying file LICENSE_1_0.txt or copy at
0037 # http://www.boost.org/LICENSE_1_0.txt)
0038
0039 if(__get_git_revision_description)
0040 return()
0041 endif()
0042 set(__get_git_revision_description YES)
0043
0044 # We must run the following at "include" time, not at function call time,
0045 # to find the path to this module rather than the path to a calling list file
0046 get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
0047
0048 function(get_git_head_revision _refspecvar _hashvar)
0049 set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
0050 set(GIT_DIR "${GIT_PARENT_DIR}/.git")
0051 while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
0052 set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
0053 get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
0054 if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
0055 # We have reached the root directory, we are not in git
0056 set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
0057 set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
0058 return()
0059 endif()
0060 set(GIT_DIR "${GIT_PARENT_DIR}/.git")
0061 endwhile()
0062 # check if this is a submodule
0063 if(NOT IS_DIRECTORY ${GIT_DIR})
0064 file(READ ${GIT_DIR} submodule)
0065 string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
0066 get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
0067 get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
0068 endif()
0069 set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
0070 if(NOT EXISTS "${GIT_DATA}")
0071 file(MAKE_DIRECTORY "${GIT_DATA}")
0072 endif()
0073
0074 if(NOT EXISTS "${GIT_DIR}/HEAD")
0075 return()
0076 endif()
0077 set(HEAD_FILE "${GIT_DATA}/HEAD")
0078 configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
0079
0080 configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
0081 "${GIT_DATA}/grabRef.cmake"
0082 @ONLY)
0083 include("${GIT_DATA}/grabRef.cmake")
0084
0085 set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
0086 set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
0087 endfunction()
0088
0089 function(git_describe _var)
0090 if(NOT GIT_FOUND)
0091 find_package(Git QUIET)
0092 endif()
0093 get_git_head_revision(refspec hash)
0094 if(NOT GIT_FOUND)
0095 set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
0096 return()
0097 endif()
0098 if(NOT hash)
0099 set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
0100 return()
0101 endif()
0102
0103 # TODO sanitize
0104 #if((${ARGN}" MATCHES "&&") OR
0105 # (ARGN MATCHES "||") OR
0106 # (ARGN MATCHES "\\;"))
0107 # message("Please report the following error to the project!")
0108 # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
0109 #endif()
0110
0111 #message(STATUS "Arguments to execute_process: ${ARGN}")
0112
0113 execute_process(COMMAND
0114 "${GIT_EXECUTABLE}"
0115 describe
0116 ${hash}
0117 ${ARGN}
0118 WORKING_DIRECTORY
0119 "${CMAKE_CURRENT_SOURCE_DIR}"
0120 RESULT_VARIABLE
0121 res
0122 OUTPUT_VARIABLE
0123 out
0124 ERROR_QUIET
0125 OUTPUT_STRIP_TRAILING_WHITESPACE)
0126 if(NOT res EQUAL 0)
0127 set(out "${out}-${res}-NOTFOUND")
0128 endif()
0129
0130 set(${_var} "${out}" PARENT_SCOPE)
0131 endfunction()
0132
0133 function(git_get_exact_tag _var)
0134 git_describe(out --exact-match ${ARGN})
0135 set(${_var} "${out}" PARENT_SCOPE)
0136 endfunction()
0137
0138 function(git_local_changes _var)
0139 if(NOT GIT_FOUND)
0140 find_package(Git QUIET)
0141 endif()
0142 get_git_head_revision(refspec hash)
0143 if(NOT GIT_FOUND)
0144 set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
0145 return()
0146 endif()
0147 if(NOT hash)
0148 set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
0149 return()
0150 endif()
0151
0152 execute_process(COMMAND
0153 "${GIT_EXECUTABLE}"
0154 diff-index --quiet HEAD --
0155 WORKING_DIRECTORY
0156 "${CMAKE_CURRENT_SOURCE_DIR}"
0157 RESULT_VARIABLE
0158 res
0159 OUTPUT_VARIABLE
0160 out
0161 ERROR_QUIET
0162 OUTPUT_STRIP_TRAILING_WHITESPACE)
0163 if(res EQUAL 0)
0164 set(${_var} "CLEAN" PARENT_SCOPE)
0165 else()
0166 set(${_var} "DIRTY" PARENT_SCOPE)
0167 endif()
0168 endfunction()