FIND_PACKAGE(Git)
IF(GIT_FOUND)
    EXECUTE_PROCESS(
        COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
        OUTPUT_VARIABLE "commit"
        OUTPUT_STRIP_TRAILING_WHITESPACE
    )
    EXECUTE_PROCESS(
        COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%ai
        OUTPUT_VARIABLE "commit_date"
        OUTPUT_STRIP_TRAILING_WHITESPACE
    )
ELSE(GIT_FOUND)
    SET(commit "unknown")
    SET(commit_date "unknown")
ENDIF(GIT_FOUND)
IF(WIN32)
    EXECUTE_PROCESS(
        COMMAND powershell.exe -Command "& {(Get-Content ${INFILE}) | ForEach-Object { ($_ -replace \"@COMMIT@\", \"${commit}\") -replace \"@COMMIT_DATE@\", \"${commit_date}\" } | Set-Content ${OUTFILE}}"
    )
ELSE(WIN32)
    EXECUTE_PROCESS(
        INPUT_FILE "${INFILE}"
        COMMAND sed -e "s/@COMMIT@/${commit}/g" -e "s/@COMMIT_DATE@/${commit_date}/g"
        OUTPUT_FILE "${OUTFILE}"
    )
ENDIF(WIN32)
