Warning, /graphics/krita/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 #
0030 # SPDX-License-Identifier: BSL-1.0
0031 #
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 linked working tree (e.g. submodule or git-worktree)
0057         if(NOT IS_DIRECTORY ${GIT_DIR})
0058                 file(READ ${GIT_DIR} gitdirfile)
0059                 string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_PATH ${gitdirfile})
0060                 if(IS_ABSOLUTE ${GIT_DIR_PATH})
0061                         get_filename_component(GIT_DIR ${GIT_DIR_PATH} ABSOLUTE)
0062                 else()
0063                         get_filename_component(LINKED_DIR ${GIT_DIR} PATH)
0064                         get_filename_component(GIT_DIR ${LINKED_DIR}/${GIT_DIR_PATH} ABSOLUTE)
0065                 endif()
0066         endif()
0067         set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
0068         if(NOT EXISTS "${GIT_DATA}")
0069                 file(MAKE_DIRECTORY "${GIT_DATA}")
0070         endif()
0071 
0072         if(NOT EXISTS "${GIT_DIR}/HEAD")
0073                 return()
0074         endif()
0075         set(HEAD_FILE "${GIT_DATA}/HEAD")
0076         configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
0077 
0078         configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
0079                 "${GIT_DATA}/grabRef.cmake"
0080                 @ONLY)
0081         include("${GIT_DATA}/grabRef.cmake")
0082 
0083         set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
0084         set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
0085 endfunction()
0086 
0087 function(git_describe _var)
0088         if(NOT GIT_FOUND)
0089                 find_package(Git QUIET)
0090         endif()
0091         get_git_head_revision(refspec hash)
0092         if(NOT GIT_FOUND)
0093                 set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
0094                 return()
0095         endif()
0096         if(NOT hash)
0097                 set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
0098                 return()
0099         endif()
0100 
0101         # TODO sanitize
0102         #if((${ARGN}" MATCHES "&&") OR
0103         #       (ARGN MATCHES "||") OR
0104         #       (ARGN MATCHES "\\;"))
0105         #       message("Please report the following error to the project!")
0106         #       message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
0107         #endif()
0108 
0109         #message(STATUS "Arguments to execute_process: ${ARGN}")
0110 
0111         execute_process(COMMAND
0112                 "${GIT_EXECUTABLE}"
0113                 describe
0114                 ${hash}
0115                 ${ARGN}
0116                 WORKING_DIRECTORY
0117                 "${CMAKE_SOURCE_DIR}"
0118                 RESULT_VARIABLE
0119                 res
0120                 OUTPUT_VARIABLE
0121                 out
0122                 ERROR_QUIET
0123                 OUTPUT_STRIP_TRAILING_WHITESPACE)
0124         if(NOT res EQUAL 0)
0125                 set(out "${out}-${res}-NOTFOUND")
0126         endif()
0127 
0128         set(${_var} "${out}" PARENT_SCOPE)
0129 endfunction()
0130 
0131 function(get_git_head_hash _var)
0132         if(NOT GIT_FOUND)
0133                 find_package(Git QUIET)
0134         endif()
0135         if(NOT GIT_FOUND)
0136                 set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
0137                 return()
0138         endif()
0139 
0140         execute_process(COMMAND
0141                 "${GIT_EXECUTABLE}"
0142                 rev-parse --verify HEAD
0143                 WORKING_DIRECTORY
0144                 "${CMAKE_SOURCE_DIR}"
0145                 RESULT_VARIABLE
0146                 res
0147                 OUTPUT_VARIABLE
0148                 out
0149                 ERROR_QUIET
0150                 OUTPUT_STRIP_TRAILING_WHITESPACE)
0151         if(NOT res EQUAL 0)
0152                 set(out "${out}-${res}-NOTFOUND")
0153         endif()
0154 
0155         set(${_var} "${out}" PARENT_SCOPE)
0156 endfunction()
0157 
0158 function(get_git_branch _var)
0159         if(NOT GIT_FOUND)
0160                 find_package(Git QUIET)
0161         endif()
0162         if(NOT GIT_FOUND)
0163                 set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
0164                 return()
0165         endif()
0166 
0167         execute_process(COMMAND
0168                 "${GIT_EXECUTABLE}"
0169                 symbolic-ref --short HEAD
0170                 WORKING_DIRECTORY
0171                 "${CMAKE_SOURCE_DIR}"
0172                 RESULT_VARIABLE
0173                 res
0174                 OUTPUT_VARIABLE
0175                 out
0176                 ERROR_QUIET
0177                 OUTPUT_STRIP_TRAILING_WHITESPACE)
0178         if(NOT res EQUAL 0)
0179                 set(out "${out}-${res}-NOTFOUND")
0180         endif()
0181 
0182         set(${_var} "${out}" PARENT_SCOPE)
0183 endfunction()
0184 
0185 function(git_get_exact_tag _var)
0186         git_describe(out --exact-match ${ARGN})
0187         set(${_var} "${out}" PARENT_SCOPE)
0188 endfunction()