FIND_PACKAGE(Git QUIET)
IF(GIT_FOUND)
    EXECUTE_PROCESS(
        COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
        OUTPUT_VARIABLE "COMMIT"
        OUTPUT_STRIP_TRAILING_WHITESPACE
        ERROR_QUIET
        RESULT_VARIABLE commit_success
    )
    IF(NOT ${commit_success} EQUAL 0)
        SET(COMMIT "unknown")
    ENDIF(NOT ${commit_success} EQUAL 0)

    EXECUTE_PROCESS(
        COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%ai
        OUTPUT_VARIABLE "COMMIT_DATE"
        OUTPUT_STRIP_TRAILING_WHITESPACE
        ERROR_QUIET
        RESULT_VARIABLE commit_date_success
    )
    IF(NOT ${commit_date_success} EQUAL 0)
        SET(COMMIT_DATE "unknown")
    ENDIF(NOT ${commit_date_success} EQUAL 0)
ELSE(GIT_FOUND)
    SET(COMMIT "unknown")
    SET(COMMIT_DATE "unknown")
ENDIF(GIT_FOUND)

#configure_file only detects changes to the input file, not changes to variable values being used (not surprising)
#so, let the custom command that calls this script handle dependencies as to when it should run, then force it to run whenever this script is used by deleting the output first
FILE(REMOVE ${OUTFILE})
CONFIGURE_FILE(${INFILE} ${OUTFILE} @ONLY)
