find_path(MANTELLA_INCLUDE_DIR mantella)
find_library(MANTELLA_LIBRARIES mantella)

if(MANTELLA_INCLUDE_DIR)
  set(MANTELLA_VERSION_MAJOR 0)
  set(MANTELLA_VERSION_MINOR 0)
  set(MANTELLA_VERSION_PATCH 0)

  if(EXISTS "${MANTELLA_INCLUDE_DIR}/mantella")
    file(STRINGS "${MANTELLA_INCLUDE_DIR}/mantella" MANTELLA_HEADER_CONTENTS REGEX "#define MANTELLA_VERSION_[A-Z]+ ")
    
    string(REGEX REPLACE ".*#define MANTELLA_VERSION_MAJOR ([0-9]+).*" "\\1" MANTELLA_VERSION_MAJOR "${MANTELLA_HEADER_CONTENTS}")
    string(REGEX REPLACE ".*#define MANTELLA_VERSION_MINOR ([0-9]+).*" "\\1" MANTELLA_VERSION_MINOR "${MANTELLA_HEADER_CONTENTS}")
    string(REGEX REPLACE ".*#define MANTELLA_VERSION_PATCH ([0-9]+).*" "\\1" MANTELLA_VERSION_PATCH "${MANTELLA_HEADER_CONTENTS}")
    
    unset(MANTELLA_HEADER_CONTENTS)
  endif()

  set(MANTELLA_VERSION "${MANTELLA_VERSION_MAJOR}.${MANTELLA_VERSION_MINOR}.${MANTELLA_VERSION_PATCH}")
endif ()
  
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Mantella
  REQUIRED_VARS MANTELLA_LIBRARIES MANTELLA_INCLUDE_DIR
  VERSION_VAR MANTELLA_VERSION)

mark_as_advanced(
  MANTELLA_LIBRARIES
  MANTELLA_INCLUDE_DIR)