execute_process(COMMAND git describe --always --dirty --exclude=*
    WORKING_DIRECTORY "${SOURCE_DIR}" OUTPUT_VARIABLE GIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if(NOT GIT_HASH)
    set(GIT_HASH "unknown")
endif()

execute_process(COMMAND git symbolic-ref -q HEAD
    WORKING_DIRECTORY "${SOURCE_DIR}" OUTPUT_VARIABLE GIT_REF OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if(NOT GIT_REF)
    set(DETACHED "1")
else()
    set(DETACHED "0")
endif()

string(TIMESTAMP BUILD_TIME "%Y-%m-%d_%H-%M-%S")

file(WRITE "${OUTPUT_FILE}"
    "// Auto-generated at build time. Do not edit.\n"
    "#pragma once\n"
    "#define JAS_GIT_INFO \"${GIT_HASH}-detached=${DETACHED}\"\n"
    "#define JAS_BUILD_TIME \"${BUILD_TIME}\"\n"
)
