## Extract version numbers from version string
function (set_version version major minor patch revision)
  if (version MATCHES "([0-9]+)(\\.[0-9]+)?(\\.[0-9]+)?([_\-][0-9a-z_\-]+)?")
    if (CMAKE_MATCH_1)
      set (_major ${CMAKE_MATCH_1})
    else ()
      set (_major 0)
    endif ()
    if (CMAKE_MATCH_2)
      set (_minor ${CMAKE_MATCH_2})
      string (REGEX REPLACE "^\\." "" _minor "${_minor}")
    else ()
      set (_minor 0)
    endif ()
    if (CMAKE_MATCH_3)
      set (_patch ${CMAKE_MATCH_3})
      string (REGEX REPLACE "^\\." "" _patch "${_patch}")
    else ()
      set (_patch 0)
    endif ()
    if (CMAKE_MATCH_4)
      set (_revision ${CMAKE_MATCH_4})
    else ()
      set (_revision "")
    endif ()
  else ()
    set (_major 0)
    set (_minor 0)
    set (_patch 0)
    set (_revision 0)
  endif ()
  set ("${major}" "${_major}" PARENT_SCOPE)
  set ("${minor}" "${_minor}" PARENT_SCOPE)
  set ("${patch}" "${_patch}" PARENT_SCOPE)
  set ("${revision}" "${_revision}" PARENT_SCOPE)
endfunction ()
