Warning, /libraries/kproperty/cmake/modules/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 # Requires CMake 2.6 or newer (uses the 'function' command) 0022 # 0023 # Original Author: 0024 # 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> 0025 # http://academic.cleardefinition.com 0026 # Iowa State University HCI Graduate Program/VRAC 0027 # 0028 # Copyright Iowa State University 2009-2010. 0029 # Distributed under the Boost Software License, Version 1.0. 0030 # (See accompanying file LICENSE_1_0.txt or copy at 0031 # http://www.boost.org/LICENSE_1_0.txt) 0032 0033 if(__get_git_revision_description) 0034 return() 0035 endif() 0036 set(__get_git_revision_description YES) 0037 0038 # We must run the following at "include" time, not at function call time, 0039 # to find the path to this module rather than the path to a calling list file 0040 get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) 0041 0042 function(get_git_head_revision _refspecvar _hashvar) 0043 set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") 0044 set(GIT_DIR "${GIT_PARENT_DIR}/.git") 0045 while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories 0046 set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") 0047 get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) 0048 if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) 0049 # We have reached the root directory, we are not in git 0050 set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) 0051 set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) 0052 return() 0053 endif() 0054 set(GIT_DIR "${GIT_PARENT_DIR}/.git") 0055 endwhile() 0056 # check if this is a submodule 0057 if(NOT IS_DIRECTORY ${GIT_DIR}) 0058 file(READ ${GIT_DIR} submodule) 0059 string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule}) 0060 get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH) 0061 get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE) 0062 endif() 0063 set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") 0064 if(NOT EXISTS "${GIT_DATA}") 0065 file(MAKE_DIRECTORY "${GIT_DATA}") 0066 endif() 0067 0068 if(NOT EXISTS "${GIT_DIR}/HEAD") 0069 return() 0070 endif() 0071 set(HEAD_FILE "${GIT_DATA}/HEAD") 0072 configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) 0073 0074 configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" 0075 "${GIT_DATA}/grabRef.cmake" 0076 @ONLY) 0077 include("${GIT_DATA}/grabRef.cmake") 0078 0079 set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) 0080 set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE) 0081 endfunction() 0082 0083 function(git_describe _var) 0084 if(NOT GIT_FOUND) 0085 find_package(Git QUIET) 0086 endif() 0087 get_git_head_revision(refspec hash) 0088 if(NOT GIT_FOUND) 0089 set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) 0090 return() 0091 endif() 0092 if(NOT hash) 0093 set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) 0094 return() 0095 endif() 0096 0097 # TODO sanitize 0098 #if((${ARGN}" MATCHES "&&") OR 0099 # (ARGN MATCHES "||") OR 0100 # (ARGN MATCHES "\\;")) 0101 # message("Please report the following error to the project!") 0102 # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") 0103 #endif() 0104 0105 #message(STATUS "Arguments to execute_process: ${ARGN}") 0106 0107 execute_process(COMMAND 0108 "${GIT_EXECUTABLE}" 0109 describe 0110 ${hash} 0111 ${ARGN} 0112 WORKING_DIRECTORY 0113 "${CMAKE_SOURCE_DIR}" 0114 RESULT_VARIABLE 0115 res 0116 OUTPUT_VARIABLE 0117 out 0118 ERROR_QUIET 0119 OUTPUT_STRIP_TRAILING_WHITESPACE) 0120 if(NOT res EQUAL 0) 0121 set(out "${out}-${res}-NOTFOUND") 0122 endif() 0123 0124 set(${_var} "${out}" PARENT_SCOPE) 0125 endfunction() 0126 0127 function(get_git_branch _var) 0128 if(NOT GIT_FOUND) 0129 find_package(Git QUIET) 0130 endif() 0131 if(NOT GIT_FOUND) 0132 set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) 0133 return() 0134 endif() 0135 0136 execute_process(COMMAND 0137 "${GIT_EXECUTABLE}" 0138 symbolic-ref --short HEAD 0139 WORKING_DIRECTORY 0140 "${CMAKE_SOURCE_DIR}" 0141 RESULT_VARIABLE 0142 res 0143 OUTPUT_VARIABLE 0144 out 0145 ERROR_QUIET 0146 OUTPUT_STRIP_TRAILING_WHITESPACE) 0147 if(NOT res EQUAL 0) 0148 set(out "${out}-${res}-NOTFOUND") 0149 endif() 0150 0151 set(${_var} "${out}" PARENT_SCOPE) 0152 endfunction() 0153 0154 function(git_get_exact_tag _var) 0155 git_describe(out --exact-match ${ARGN}) 0156 set(${_var} "${out}" PARENT_SCOPE) 0157 endfunction()