execute_process(
	COMMAND git rev-parse --abbrev-ref HEAD
	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
	OUTPUT_VARIABLE GIT_BRANCH
	OUTPUT_STRIP_TRAILING_WHITESPACE
)

execute_process(
	COMMAND git log -1 --format=%h
	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
	OUTPUT_VARIABLE GIT_COMMIT_HASH
	OUTPUT_STRIP_TRAILING_WHITESPACE
)

execute_process(
	COMMAND git tag -l --points-at HEAD
	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
	OUTPUT_VARIABLE GIT_CURRENT_VERSION
	OUTPUT_STRIP_TRAILING_WHITESPACE
	ERROR_QUIET
)

execute_process(
	COMMAND git describe --abbrev=0 --tags
	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
	OUTPUT_VARIABLE GIT_OLD_VERSION
	OUTPUT_STRIP_TRAILING_WHITESPACE
	ERROR_QUIET
)

if(GIT_OLD_VERSION MATCHES "[0-9]+.[0-9]+.[0-9]+")
	message(STATUS "Setting project version to ${GIT_OLD_VERSION}")
	set(PROJECT_VERSION "${GIT_OLD_VERSION}")
else()
	message(STATUS "Setting project version to 0.0.0")
	set(PROJECT_VERSION "0.0.0")
endif()
