# - Try to find QwtPolar
# Once done this will define
#  
#  QWTPOLAR_FOUND        - system has QwtPolar
#  QWTPOLAR_INCLUDE_DIR  - the QwtPolar include directory
#  QWTPOLAR_LIBRARY      - Link this to use QwtPolar

IF(QWTPOLAR_INCLUDE_DIR)
  #already in cache
  SET(QWTPOLAR_FIND_QUIETLY TRUE)
ENDIF(QWTPOLAR_INCLUDE_DIR)

FIND_PATH(QWTPOLAR_INCLUDE_DIR
  NAMES qwt_polar.h
  PATHS /usr/include)

FIND_LIBRARY(QWTPOLAR_LIBRARY
  NAMES qwtpolar
  PATHS /usr/lib64 /lib64)

IF(EXISTS "${QWTPOLAR_INCLUDE_DIR}/qwt_polar_global.h")
    FILE(STRINGS "${QWTPOLAR_INCLUDE_DIR}/qwt_polar_global.h" QWTPOLAR_H REGEX "^#define QWT_POLAR_VERSION_STR \"[^\"]*\"$")
    STRING(REGEX REPLACE "^.*QWT_POLAR_VERSION_STR \"([0-9]+).*$" "\\1" QWTPOLAR_VERSION_MAJOR "${QWTPOLAR_H}")
    STRING(REGEX REPLACE "^.*QWT_POLAR_VERSION_STR \"[0-9]+\\.([0-9]+).*$" "\\1" QWTPOLAR_VERSION_MINOR  "${QWTPOLAR_H}")
    STRING(REGEX REPLACE "^.*QWT_POLAR_VERSION_STR \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" QWTPOLAR_VERSION_PATCH "${QWTPOLAR_H}")
    SET(QWTPOLAR_VERSION_STRING "${QWTPOLAR_VERSION_MAJOR}.${QWTPOLAR_VERSION_MINOR}.${QWTPOLAR_VERSION_PATCH}")
ENDIF()

IF(QWTPOLAR_INCLUDE_DIR AND QWTPOLAR_LIBRARY)
  SET(QWTPOLAR_FOUND TRUE)
  SET(QWTPOLAR_LIBRARY_DIR ${QWTPOLAR_LIBRARY})
ELSE(QWTPOLAR_INCLUDE_DIR AND QWTPOLAR_LIBRARY)
  SET(QWTPOLAR_FOUND FALSE)
  SET(QWTPOLAR_LIBRARY_DIR)
ENDIF(QWTPOLAR_INCLUDE_DIR AND QWTPOLAR_LIBRARY)

# handle the QUIETLY and REQUIRED arguments and set QWTPOLAR_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(QwtPolar DEFAULT_MSG QWTPOLAR_LIBRARY QWTPOLAR_VERSION_STRING)

MARK_AS_ADVANCED(
  QWTPOLAR_INCLUDE_DIR
  QWTPOLAR_LIBRARY
  QWTPOLAR_VERSION_STRING)
