# Copyright (c) 2008, OpenCog.org (http://opencog.org)
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

# Try to find the libmemcachede library; Once done this will define
#
# LIBMEMCACHED_FOUND       - system has the libmemcached library
# LIBMEMCACHED_INCLUDE_DIR - the libmemcached include directory
# LIBMEMCACHED_LIBRARIES   - The libraries needed to use libmemcached

find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBMEMCACHED_PC libmemcached)

IF(LIBMEMCACHED_PC_FOUND)
    message(STATUS "Libmemcached pkgconfig file - found")
    SET(LIBMEMCACHED_INCLUDE_DIR ${LIBMEMCACHED_PC_INCLUDE_DIRS})
    SET(LIBMEMCACHED_LIBRARY ${LIBMEMCACHED_PC_LIBRARIES})
    SET(LIBMEMCACHED_LIBRARIES ${LIBMEMCACHED_PC_LIBRARIES})

ELSE(LIBMEMCACHED_PC_FOUND)
# Look for the header file
FIND_PATH(LIBMEMCACHED_INCLUDE_DIR memcached.h /usr/include /usr/include/libmemcached /usr/local/include /usr/local/include/libmemcached)

# Look for the library
FIND_LIBRARY(LIBMEMCACHED_LIBRARY NAMES memcached PATH /usr/lib /usr/local/lib)

# Copy the results to the output variables.
IF (LIBMEMCACHED_INCLUDE_DIR AND LIBMEMCACHED_LIBRARY)
	SET(LIBMEMCACHED_FOUND 1)
	SET(LIBMEMCACHED_LIBRARIES ${LIBMEMCACHED_LIBRARY})
	SET(LIBMEMCACHED_INCLUDE_DIRS ${LIBMEMCACHED_INCLUDE_DIR})
ELSE (LIBMEMCACHED_INCLUDE_DIR AND LIBMEMCACHED_LIBRARY)
	SET(LIBMEMCACHED_FOUND 0)
	SET(LIBMEMCACHED_LIBRARIES)
	SET(LIBMEMCACHED_INCLUDE_DIRS)
ENDIF (LIBMEMCACHED_INCLUDE_DIR AND LIBMEMCACHED_LIBRARY)

# Report the results.
IF (NOT LIBMEMCACHED_FOUND)
	SET(LIBMEMCACHED_DIR_MESSAGE "LibMemCached was not found. Make sure LIBMEMCACHED_LIBRARY and LIBMEMCACHED_INCLUDE_DIR are set.")
	IF (NOT LIBMEMCACHED_FIND_QUIETLY)
		MESSAGE(STATUS "${LIBMEMCACHED_DIR_MESSAGE}")
	ELSE (NOT LIBMEMCACHED_FIND_QUIETLY)
		IF (LIBMEMCACHED_FIND_REQUIRED)
			MESSAGE(FATAL_ERROR "${LIBMEMCACHED_DIR_MESSAGE}")
		ENDIF (LIBMEMCACHED_FIND_REQUIRED)
	ENDIF (NOT LIBMEMCACHED_FIND_QUIETLY)
ENDIF (NOT LIBMEMCACHED_FOUND)

ENDIF(LIBMEMCACHED_PC_FOUND)

MARK_AS_ADVANCED(
	LIBMEMCACHED_LIBRARY
	LIBMEMCACHED_INCLUDE_DIR
)
