###################################################################################################
# Copyright (C) 2020 by Andrey Ponomarev and Timur Kazhimuratov
# This file is part of cxx_plugins project.
# License is available at https://github.com/Spaghetti-Software/cxx_plugins/blob/master/LICENSE
###################################################################################################
#
# \file    get_git_version.cmake
# \author  Andrey Ponomarev
# \date    06 May 2020
# \brief
# This file contains function for extracting version from git tags

include(GetGitRevisionDescription)

function(get_git_version VERSION_VAR_NAME)
  git_describe(VERSION --tags )
  if (${VERSION})
    string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
    string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
    string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")

    set(${VERSION_VAR_NAME} "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" PARENT_SCOPE)
  else()
    set(${VERSION_VAR_NAME} 0.0.0 PARENT_SCOPE)
  endif()
endfunction()



