# Find the libcassandra library.
#
# This module defines
#  LIBCASSANDRA_FOUND             - True if LIBCASSANDRA was found.
#  LIBCASSANDRA_INCLUDE_DIRS      - Include directories for LIBCASSANDRA headers.
#  LIBCASSANDRA_LIBRARIES         - Libraries for LIBCASSANDRA.
#
# To specify an additional directory to search, set LIBCASSANDRA_ROOT.
#
# Copyright (c) 2010, Ewen Cheslack-Postava
# Based on FindSQLite3.cmake by:
#  Copyright (c) 2006, Jaroslaw Staniek, <js@iidea.pl>
#  Extended by Siddhartha Chaudhuri, 2008.
#
# Redistribution and use is allowed according to the terms of the BSD license.
#

SET(LIBCASSANDRA_FOUND FALSE)
SET(LIBCASSANDRA_INCLUDE_DIRS)
SET(LIBCASSANDRA_LIBRARIES)

IF(LIBCASSANDRA_ROOT)
  SET(SEARCH_PATHS
    ${LIBCASSANDRA_ROOT}
    ${LIBCASSANDRA_ROOT}/include
    ${SEARCH_PATHS}
    )
ENDIF()

FIND_PATH(LIBCASSANDRA_INCLUDE_DIRS
  NAMES libcassandra/cassandra.h
  PATHS ${SEARCH_PATHS}
  NO_DEFAULT_PATH)
IF(NOT LIBCASSANDRA_INCLUDE_DIRS)  # now look in system locations
  FIND_PATH(LIBCASSANDRA_INCLUDE_DIRS NAMES libcassandra/cassandra.h)
ENDIF(NOT LIBCASSANDRA_INCLUDE_DIRS)

SET(LIBCASSANDRA_LIBRARY_DIRS)
IF(LIBCASSANDRA_ROOT)
  SET(LIBCASSANDRA_LIBRARY_DIRS ${LIBCASSANDRA_ROOT})
  IF(EXISTS "${LIBCASSANDRA_ROOT}/lib")
    SET(LIBCASSANDRA_LIBRARY_DIRS ${LIBCASSANDRA_LIBRARY_DIRS} ${LIBCASSANDRA_ROOT}/lib)
  ENDIF()
ENDIF()

#libcassandra
# Without system dirs
FIND_LIBRARY(LIBCASSANDRA_LIBRARY
  NAMES cassandra
  PATHS ${LIBCASSANDRA_LIBRARY_DIRS}
  NO_DEFAULT_PATH
  )
IF(NOT LIBCASSANDRA_LIBRARY)  # now look in system locations
  FIND_LIBRARY(LIBCASSANDRA_LIBRARY NAMES cassandra)
ENDIF(NOT LIBCASSANDRA_LIBRARY)

# libgenthrift
# Without system dirs
FIND_LIBRARY(LIBGENTHRIFT_LIBRARY
  NAMES genthrift
  PATHS ${LIBCASSANDRA_LIBRARY_DIRS}
  NO_DEFAULT_PATH
  )
IF(NOT LIBGENTHRIFT_LIBRARY)  # now look in system locations
  FIND_LIBRARY(LIBGENTHRIFT_LIBRARY NAMES genthrift)
ENDIF(NOT LIBGENTHRIFT_LIBRARY)


SET(LIBCASSANDRA_LIBRARIES)
IF(LIBCASSANDRA_LIBRARY AND LIBGENTHRIFT_LIBRARY)
  SET(LIBCASSANDRA_LIBRARIES ${LIBCASSANDRA_LIBRARY} ${LIBGENTHRIFT_LIBRARY})
ENDIF()

IF(LIBCASSANDRA_INCLUDE_DIRS AND LIBCASSANDRA_LIBRARIES)
  SET(LIBCASSANDRA_FOUND TRUE)
  IF(NOT LIBCASSANDRA_FIND_QUIETLY)
    MESSAGE(STATUS "Found libcassandra: headers at ${LIBCASSANDRA_INCLUDE_DIRS}, libraries at ${LIBCASSANDRA_LIBRARY_DIRS} :: ${LIBCASSANDRA_LIBRARIES}")
  ENDIF(NOT LIBCASSANDRA_FIND_QUIETLY)
ELSE(LIBCASSANDRA_INCLUDE_DIRS AND LIBCASSANDRA_LIBRARIES)
  SET(LIBCASSANDRA_FOUND FALSE)
  IF(LIBCASSANDRA_FIND_REQUIRED)
    MESSAGE(STATUS "libcassandra not found")
  ENDIF(LIBCASSANDRA_FIND_REQUIRED)
ENDIF(LIBCASSANDRA_INCLUDE_DIRS AND LIBCASSANDRA_LIBRARIES)

MARK_AS_ADVANCED(LIBCASSANDRA_INCLUDE_DIRS LIBCASSANDRA_LIBRARIES)
