FIND_PACKAGE(PkgConfig)

PKG_CHECK_MODULES(PC_PANGO_FT2 pangoft2)

FIND_PATH(PANGO_INCLUDE_DIR pango/pangoft2.h
          HINTS ${PC_PANGO_FT2_INCLUDE_DIRS})

FIND_PATH(FT2_INCLUDE_DIR NAMES freetype/freetype.h freetype2/freetype.h
          HINTS ${PC_PANGO_FT2_INCLUDE_DIRS})

FIND_PATH(FT2BUILD_INCLUDE_DIR ft2build.h
          HINTS ${PC_PANGO_FT2_INCLUDE_DIRS})

FIND_PATH(FONTCONFIG_INCLUDE_DIR fontconfig/fontconfig.h
          HINTS ${PC_PANGO_FT2_INCLUDE_DIRS})

FIND_PATH(GLIB2_INCLUDE_DIR glib.h
          HINTS ${PC_PANGO_FT2_INCLUDE_DIRS})

FIND_PATH(GLIB2_CONFIG_INCLUDE_DIR glibconfig.h
          HINTS ${PC_PANGO_FT2_INCLUDE_DIRS})

FIND_LIBRARY(PANGO_FT2_LIBRARY NAMES pangoft2-1.0 pangoft2
             HINTS ${PC_PANGO_FT2_LIBDIR})

FIND_LIBRARY(PANGO_LIBRARY NAMES pango-1.0 pango
             HINTS ${PC_PANGO_FT2_LIBDIR})

FIND_LIBRARY(GOBJECT2_LIBRARY NAMES gobject-2.0 gobject
             HINTS ${PC_PANGO_FT2_LIBDIR})

FIND_LIBRARY(GLIB2_LIBRARY NAMES glib-2.0 glib
             HINTS ${PC_PANGO_FT2_LIBDIR})

SET(PANGO_FT2_INCLUDE_DIRS
    ${PANGO_INCLUDE_DIR}
    ${FT2_INCLUDE_DIR}
    ${FT2BUILD_INCLUDE_DIR}
    ${FONTCONFIG_INCLUDE_DIR}
    ${GLIB2_INCLUDE_DIR}
    ${GLIB2_CONFIG_INCLUDE_DIR})

SET(PANGO_FT2_LIBRARIES
    ${PANGO_FT2_LIBRARY}
    ${PANGO_LIBRARY}
    ${GOBJECT2_LIBRARY}
    ${GLIB2_LIBRARY})

IF (PANGO_INCLUDE_DIR
    AND FT2_INCLUDE_DIR
    AND FT2BUILD_INCLUDE_DIR
    AND FONTCONFIG_INCLUDE_DIR
    AND GLIB2_INCLUDE_DIR
    AND GLIB2_CONFIG_INCLUDE_DIR
    AND PANGO_FT2_LIBRARIES)
  SET(PANGO_FT2_FOUND TRUE)
ELSE (PANGO_INCLUDE_DIR
    AND FT2_INCLUDE_DIR
    AND FT2BUILD_INCLUDE_DIR
    AND FONTCONFIG_INCLUDE_DIR
    AND GLIB2_INCLUDE_DIR
    AND GLIB2_CONFIG_INCLUDE_DIR
    AND PANGO_FT2_LIBRARIES)
  SET(PANGO_FT2_FOUND FALSE)
ENDIF(PANGO_INCLUDE_DIR
    AND FT2_INCLUDE_DIR
    AND FT2BUILD_INCLUDE_DIR
    AND FONTCONFIG_INCLUDE_DIR
    AND GLIB2_INCLUDE_DIR
    AND GLIB2_CONFIG_INCLUDE_DIR
    AND PANGO_FT2_LIBRARIES)
