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(
0066 REGEX REPLACE
0067 "gitdir: (.*)\n$"
0068 "\\1"
0069 GIT_DIR_RELATIVE
0070 ${submodule}
0071 )
0072 get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
0073 get_filename_component(
0074 GIT_DIR
0075 ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE}
0076 ABSOLUTE
0077 )
0078 endif()
0079 set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
0080 if(NOT EXISTS "${GIT_DATA}")
0081 file(MAKE_DIRECTORY "${GIT_DATA}")
0082 endif()
0083
0084 if(NOT EXISTS "${GIT_DIR}/HEAD")
0085 return()
0086 endif()
0087 set(HEAD_FILE "${GIT_DATA}/HEAD")
0088 configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
0089
0090 configure_file(
0091 "${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
0092 "${GIT_DATA}/grabRef.cmake"
0093 @ONLY
0094 )
0095 include("${GIT_DATA}/grabRef.cmake")
0096
0097 set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
0098 set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
0099 endfunction()
0100
0101 function(git_describe _var)
0102 if(NOT GIT_FOUND)
0103 find_package(Git QUIET)
0104 endif()
0105 get_git_head_revision(refspec hash)
0106 if(NOT GIT_FOUND)
0107 set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
0108 return()
0109 endif()
0110 if(NOT hash)
0111 set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
0112 return()
0113 endif()
0114
0115 # TODO sanitize
0116 #if((${ARGN}" MATCHES "&&") OR
0117 # (ARGN MATCHES "||") OR
0118 # (ARGN MATCHES "\\;"))
0119 # message("Please report the following error to the project!")
0120 # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
0121 #endif()
0122
0123 #message(STATUS "Arguments to execute_process: ${ARGN}")
0124
0125 execute_process(
0126 COMMAND "${GIT_EXECUTABLE}" describe ${hash} ${ARGN}
0127 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
0128 RESULT_VARIABLE res
0129 OUTPUT_VARIABLE out
0130 ERROR_QUIET
0131 OUTPUT_STRIP_TRAILING_WHITESPACE
0132 )
0133 if(NOT res EQUAL 0)
0134 set(out "${out}-${res}-NOTFOUND")
0135 endif()
0136
0137 set(${_var} "${out}" PARENT_SCOPE)
0138 endfunction()
0139
0140 function(git_get_exact_tag _var)
0141 git_describe(out --exact-match ${ARGN})
0142 set(${_var} "${out}" PARENT_SCOPE)
0143 endfunction()
0144
0145 function(git_local_changes _var)
0146 if(NOT GIT_FOUND)
0147 find_package(Git QUIET)
0148 endif()
0149 get_git_head_revision(refspec hash)
0150 if(NOT GIT_FOUND)
0151 set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
0152 return()
0153 endif()
0154 if(NOT hash)
0155 set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
0156 return()
0157 endif()
0158
0159 execute_process(
0160 COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD --
0161 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
0162 RESULT_VARIABLE res
0163 OUTPUT_VARIABLE out
0164 ERROR_QUIET
0165 OUTPUT_STRIP_TRAILING_WHITESPACE
0166 )
0167 if(res EQUAL 0)
0168 set(${_var} "CLEAN" PARENT_SCOPE)
0169 else()
0170 set(${_var} "DIRTY" PARENT_SCOPE)
0171 endif()
0172 endfunction()