|
| 1 | +# This file is intented to be run with cmake -P |
| 2 | + |
| 3 | +# Derived from |
| 4 | +# Original Author: |
| 5 | +# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> |
| 6 | +# http://academic.cleardefinition.com |
| 7 | +# Iowa State University HCI Graduate Program/VRAC |
| 8 | +# |
| 9 | +# Copyright Iowa State University 2009-2010. |
| 10 | +# Distributed under the Boost Software License, Version 1.0. |
| 11 | +# (See accompanying file LICENSE_1_0.txt or copy at |
| 12 | +# http://www.boost.org/LICENSE_1_0.txt) |
| 13 | + |
| 14 | +message(STATUS "Reading head file ${HEAD_FILE}") |
| 15 | +message(STATUS "Using git executable at \"${GIT_EXECUTABLE}\"") |
| 16 | + |
| 17 | +get_filename_component(ROOT_DIR ${GIT_DIR} DIRECTORY) |
| 18 | + |
| 19 | +set(GIT_SHA1) |
| 20 | + |
| 21 | +file(READ "${HEAD_FILE}" HEAD_CONTENTS LIMIT 1024) |
| 22 | + |
| 23 | +string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS) |
| 24 | +if(HEAD_CONTENTS MATCHES "ref") |
| 25 | + # named branch |
| 26 | + string(REPLACE "ref: " "" GIT_REFSPEC "${HEAD_CONTENTS}") |
| 27 | +endif() |
| 28 | + |
| 29 | +message(STATUS "GIT_REFSPEC: \"${GIT_REFSPEC}\"") |
| 30 | + |
| 31 | +execute_process(COMMAND |
| 32 | + "${GIT_EXECUTABLE}" |
| 33 | + rev-parse --verify HEAD |
| 34 | + WORKING_DIRECTORY |
| 35 | + "${ROOT_DIR}" |
| 36 | + RESULT_VARIABLE |
| 37 | + res |
| 38 | + OUTPUT_VARIABLE |
| 39 | + GIT_SHA1 |
| 40 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 41 | +if(NOT res EQUAL 0) |
| 42 | + message(FATAL_ERROR "could not get the git sha1") |
| 43 | +endif() |
| 44 | + |
| 45 | +message(STATUS "GIT_SHA1: \"${GIT_SHA1}\"") |
| 46 | + |
| 47 | +execute_process(COMMAND |
| 48 | + "${GIT_EXECUTABLE}" |
| 49 | + describe |
| 50 | + ${GIT_SHA1} |
| 51 | + --tags --abbrev=0 --all |
| 52 | + WORKING_DIRECTORY |
| 53 | + "${ROOT_DIR}" |
| 54 | + RESULT_VARIABLE |
| 55 | + res |
| 56 | + OUTPUT_VARIABLE |
| 57 | + GIT_EXACT_TAG |
| 58 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 59 | +if(NOT res EQUAL 0) |
| 60 | + message(FATAL_ERROR "could not get the exact git tag") |
| 61 | +endif() |
| 62 | + |
| 63 | +message(STATUS "GIT_EXACT_TAG: \"${GIT_EXACT_TAG}\"") |
| 64 | + |
| 65 | +execute_process(COMMAND |
| 66 | + "${GIT_EXECUTABLE}" |
| 67 | + describe |
| 68 | + ${GIT_SHA1} |
| 69 | + --abbrev=10 --always --tags --long --all |
| 70 | + WORKING_DIRECTORY |
| 71 | + "${ROOT_DIR}" |
| 72 | + RESULT_VARIABLE |
| 73 | + res |
| 74 | + OUTPUT_VARIABLE |
| 75 | + GIT_DESCRIPTION |
| 76 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 77 | +if(NOT res EQUAL 0) |
| 78 | + message(FATAL_ERROR "could not get the description") |
| 79 | +endif() |
| 80 | + |
| 81 | +message(STATUS "GIT_DESCRIPTION: \"${GIT_DESCRIPTION}\"") |
| 82 | + |
| 83 | +execute_process(COMMAND |
| 84 | + "${GIT_EXECUTABLE}" |
| 85 | + diff-index --quiet HEAD -- |
| 86 | + WORKING_DIRECTORY |
| 87 | + "${ROOT_DIR}" |
| 88 | + RESULT_VARIABLE |
| 89 | + res |
| 90 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 91 | +if(res EQUAL 0) |
| 92 | + set(GIT_CLEAN_STATUS "CLEAN") |
| 93 | +else() |
| 94 | + set(GIT_CLEAN_STATUS "DIRTY") |
| 95 | +endif() |
| 96 | + |
| 97 | +message(STATUS "Git Clean Status: \"${GIT_CLEAN_STATUS}\"") |
| 98 | + |
| 99 | +message(STATUS "Configuring ${IN_FILE} to generate ${OUT_FILE}.") |
| 100 | +configure_file(${IN_FILE} ${OUT_FILE} @ONLY) |
0 commit comments