import re


def get_version(filepath):
  """Reads current version from CMakeLists.txt configuration file.
  
  Parameters
  ----------
  filepath : str
    An absolute filepath to CMakeLists.txt

  Returns
  -------
  tuple
    A tuple of three integers (major, minor, patch)
  """
  major, minor, patch = 0, 0, 0
  with open(filepath) as config:
    content = config.read()
    major_match = re.findall(r'\s*[Ss][Ee][Tt]\s*\(\s*SMARTPEAK_PACKAGE_VERSION_MAJOR\s*([0-9]+)\s*\)[^\n]*', content)
    minor_match = re.findall(r'\s*[Ss][Ee][Tt]\s*\(\s*SMARTPEAK_PACKAGE_VERSION_MINOR\s*([0-9]+)\s*\)[^\n]*', content)
    patch_match = re.findall(r'\s*[Ss][Ee][Tt]\s*\(\s*SMARTPEAK_PACKAGE_VERSION_PATCH\s*([0-9]+)\s*\)[^\n]*', content)
    if len(major_match) > 0 and len(minor_match) > 0 and len(patch_match) > 0:
      major, minor, patch = int(major_match[0]), int(minor_match[0]), int(patch_match[0])
  return major, minor, patch