Warning, /graphics/kgeotag/cmake/GitDescription.cmake is written in an unsupported language. File is not indexed.

0001 # SPDX-FileCopyrightText: 2012-2020 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0002 # SPDX-FileCopyrightText: 2020 Tobias Leupold <tl at stonemx dot de>
0003 #
0004 # SPDX-License-Identifier: BSD-3-Clause
0005 
0006 # - GIT_GET_DESCRIPTION ( description_variable [GIT_ARGS arg1 ...] [SEND_ERROR] )
0007 # This macro calls git describe to obtain a concise description of the current
0008 # git repository, i.e. the most recent tag, together with thea "distance" to
0009 # that tag and the short hash of the current commit.
0010 #
0011 # The description will be written into 'description_variable'. If an error
0012 # occurred, the variable will be set to '-NOTFOUND' unless SEND_ERROR is set.
0013 # In this case the a SEND_ERROR will be issued and generation will be skipped.
0014 #
0015 # Additional arguments to "git described" can be specified after the keyword
0016 # GIT_ARGS.
0017 #
0018 # Example invocation:
0019 #  GIT_GET_DESCRIPTION ( PROJECT_VERSION GIT_ARGS --dirty )
0020 #  message ( STATUS "Project is at revision ${PROJECT_VERSION}." )
0021 #
0022 # Assuming the project has been previously tagged with "1.0", there have been 2
0023 # commits since, and the working copy has been changed, this example could print
0024 # the following text:
0025 #  -- Project is at revision 1.0-2-g58a35d9-dirty.
0026 #
0027 # Depends on CMakeParseArguments.
0028 ##
0029 
0030 include(CMakeParseArguments)
0031 
0032 ## git_get_description ( <DESCRIPTION_VARIABLE> [GIT_ARGS <arg1>..<argN>] [SEND_ERROR] )
0033 # Write the result of "git describe" into the variable DESCRIPTION_VARIABLE.
0034 # Additional arguments to git describe ( e.g. --dirty ) can be passed using the keyword GIT_ARGS.
0035 # If SEND_ERROR is set, execution is immediately stopped when an error occurs.
0036 
0037 function(git_get_description DESCVAR)
0038     cmake_parse_arguments(ggd "SEND_ERROR" "GIT_ARGS" "" "${ARGN}")
0039     if (SEND_ERROR)
0040         set(severity SEND_ERROR)
0041     else()
0042         set(severity WARNING)
0043     endif()
0044 
0045     find_package(Git QUIET)
0046 
0047     if (NOT GIT_FOUND)
0048         message(${severity} "git_get_description: could not find package git!")
0049         set(${DESCVAR} "-NOTFOUND" PARENT_SCOPE)
0050         return()
0051     endif()
0052 
0053     # Check if any tag has been set
0054     execute_process(COMMAND "${GIT_EXECUTABLE}" tag -l
0055                     WORKING_DIRECTORY "${BASE_DIR}"
0056                     OUTPUT_VARIABLE git_output
0057                     OUTPUT_STRIP_TRAILING_WHITESPACE)
0058 
0059     if (git_output STREQUAL "")
0060         message(STATUS "git_get_description: No tags set yet, can't determine version. Using the "
0061                        "current commit hash.")
0062         execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD
0063                         WORKING_DIRECTORY "${BASE_DIR}"
0064                         OUTPUT_VARIABLE git_output
0065                         OUTPUT_STRIP_TRAILING_WHITESPACE)
0066         set(${DESCVAR} "commit-${git_output}" PARENT_SCOPE)
0067         return()
0068     endif()
0069 
0070     execute_process(COMMAND "${GIT_EXECUTABLE}" describe --dirty ${ggd_GIT_ARGS}
0071                     WORKING_DIRECTORY "${BASE_DIR}"
0072                     RESULT_VARIABLE git_result
0073                     OUTPUT_VARIABLE git_output
0074                     ERROR_VARIABLE  git_error
0075                     OUTPUT_STRIP_TRAILING_WHITESPACE)
0076 
0077     if (NOT git_result EQUAL 0)
0078         message(${severity} "git_get_description: error during execution of git describe!")
0079         message(${severity} "Error was: ${git_error}")
0080         set(${DESCVAR} "-NOTFOUND" PARENT_SCOPE)
0081         return()
0082     endif()
0083 
0084     string(REGEX REPLACE "^v" "" git_output ${git_output})
0085     set(${DESCVAR} "${git_output}" PARENT_SCOPE)
0086 endfunction()