# https://github.com/amireh/libalgol/blob/master/CMake/Scripts/FindModule.cmake
INCLUDE(FindPackageHandleStandardArgs)

MACRO(FIND_MODULE
  M_NAME
  M_HEADER_NAMES
  M_HEADER_PATHS
  M_HEADER_PATH_SUFFIXES
  M_LIBRARY_NAMES
  M_LIBRARY_PATHS
  M_LIBRARY_PATH_SUFFIXES)

  IF (${M_NAME}_INCLUDE_DIRS)
    SET(${M_NAME}_FIND_QUIETLY TRUE)  # Already in cache, be silent
  ENDIF ()

  FIND_PATH(${M_NAME}_INCLUDE_DIR
    NAMES ${M_HEADER_NAMES}
    PATHS ${M_HEADER_PATHS}
    PATH_SUFFIXES ${M_HEADER_PATH_SUFFIXES})

  FIND_LIBRARY(${M_NAME}_LIBRARY
    NAMES ${M_LIBRARY_NAMES}
    PATHS ${M_LIBRARY_PATHS}
    PATH_SUFFIXES ${M_LIBRARY_PATH_SUFFIXES}
    )

  SET( ${M_NAME}_LIBRARIES ${${M_NAME}_LIBRARY} )
  SET( ${M_NAME}_INCLUDE_DIRS ${${M_NAME}_INCLUDE_DIR} )

  FIND_PACKAGE_HANDLE_STANDARD_ARGS(${M_NAME} DEFAULT_MSG ${M_NAME}_LIBRARY ${M_NAME}_INCLUDE_DIR)

  MARK_AS_ADVANCED( ${M_NAME}_LIBRARY ${M_NAME}_INCLUDE_DIR )

ENDMACRO()
