# - Try to find gnu sasl library
# Once done this will define
#
#  GSASL_FOUND - system has gnu sasl
#  GSASL_INCLUDE_DIR - the gnu sasl include directory
#  GSASL_LIBRARIES - Link these to gnu sasl
#  GSASL_DEFINITIONS - Compiler switches required for using gnu sasl

# Copyright (c) 2009, Michele Caini, <skypjack@gmail.com>
#
# Redistribution and use is allowed according to the terms of the GPLv3 license.


IF (GSASL_INCLUDE_DIR AND GSASL_LIBRARIES)
   # in cache already
   SET(GSasl_FIND_QUIETLY TRUE)
ENDIF (GSASL_INCLUDE_DIR AND GSASL_LIBRARIES)

IF (NOT WIN32)
   # use pkg-config to get the directories and then use these values
   # in the FIND_PATH() and FIND_LIBRARY() calls
   find_package(PkgConfig)
   pkg_check_modules(PC_GSASL libgsasl)
   SET(GSASL_DEFINITIONS ${PC_GSASL_CFLAGS_OTHER})
ENDIF (NOT WIN32)

FIND_PATH(GSASL_INCLUDE_DIR gsasl.h
    PATHS
    ${PC_GSASL_INCLUDEDIR}
    ${PC_GSASL_INCLUDE_DIRS}
  )

FIND_LIBRARY(GSASL_LIBRARIES NAMES gsasl
    PATHS
    ${PC_GSASL_LIBDIR}
    ${PC_GSASL_LIBRARY_DIRS}
  )

IF (GSASL_INCLUDE_DIR AND GSASL_LIBRARIES)
   SET(GSASL_FOUND TRUE)
ELSE (GSASL_INCLUDE_DIR AND GSASL_LIBRARIES)
   SET(GSASL_FOUND FALSE)
ENDIF (GSASL_INCLUDE_DIR AND GSASL_LIBRARIES)

IF (GSASL_FOUND)
   IF (NOT GSasl_FIND_QUIETLY)
      MESSAGE(STATUS "Found gnu sasl library: ${GSASL_LIBRARIES}")
   ENDIF (NOT GSasl_FIND_QUIETLY)
ELSE (GSASL_FOUND)
   IF (GSasl_FIND_REQUIRED)
      MESSAGE(FATAL_ERROR "Could NOT find gnu sasl library")
   ENDIF (GSasl_FIND_REQUIRED)
ENDIF (GSASL_FOUND)

MARK_AS_ADVANCED(GSASL_INCLUDE_DIR GSASL_LIBRARIES)
