# FindMongoCXX
# --------
#
# Find the mongo-cxx-driver library
#
# The following variables will be defined:
#
# ``MongoCXX_FOUND`` True if MongoCXX found on the local system
#
# ``MongoCXX_INCLUDE_DIRS`` Location of Mongo-CXX header files
#
# ``MongoCXX_LIBRARY_DIRS`` Location of Mongo-CXX libraries
#
# ``MongoCXX_LIBRARIES`` List of the Mongo-CXX libraries found
#

# static or shared
if (MONGO_STATIC_LIB)
    set(MONGO_CXX_LIBRARY_TYPE STATIC)
    # lib
    set(MONGO_CXX_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX})
    # .a
    set(MONGO_CXX_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
else()
    set(MONGO_CXX_LIBRARY_TYPE SHARED)
    # lib
    set(MONGO_CXX_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX})
    # .dylib
    set(MONGO_CXX_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()

# full name
set(MONGO_C_LIB_NAME ${MONGO_CXX_PREFIX}mongoc-1.0${MONGO_CXX_SUFFIX})
set(MONGO_CXX_LIB_NAME ${MONGO_CXX_PREFIX}mongocxx${MONGO_CXX_SUFFIX})
set(BSON_CXX_LIB_NAME ${MONGO_CXX_PREFIX}bsoncxx${MONGO_CXX_SUFFIX})

# includes
find_path(MONGO_C_INCLUDE_DIR
    NAMES
        libmongoc-1.0/mongoc.h
    PATHS
        /usr/local/include
    NO_DEFAULT_PATH)
find_path(MONGO_CXX_INCLUDE_DIR
    NAMES
        mongocxx/client.hpp
    PATHS
        /usr/local/include/mongocxx/v_noabi/
    NO_DEFAULT_PATH)
find_path(BSON_CXX_INCLUDE_DIR
    NAMES
        bsoncxx/types.hpp
    PATHS
        /usr/local/include/bsoncxx/v_noabi/
    NO_DEFAULT_PATH)

# libs
find_library(MONGO_C_LIBRARY
    NAMES
        ${MONGO_C_LIB_NAME}
    PATHS
        /usr/local/lib
    NO_DEFAULT_PATH)
find_library(MONGO_CXX_LIBRARY
    NAMES
        ${MONGO_CXX_LIB_NAME}
    PATHS
        /usr/local/lib
    NO_DEFAULT_PATH)
find_library(BSON_CXX_LIBRARY
    NAMES
        ${BSON_CXX_LIB_NAME}
    PATHS
        /usr/local/lib
    NO_DEFAULT_PATH)

# vars
if (MONGO_CXX_INCLUDE_DIR AND MONGO_CXX_LIBRARY)
    set(MONGO_CXX_FOUND TRUE)
endif(MONGO_CXX_INCLUDE_DIR AND MONGO_CXX_LIBRARY)

if (MONGO_C_INCLUDE_DIR AND MONGO_C_LIBRARY)
    set(MONGO_C_FOUND TRUE)
endif(MONGO_C_INCLUDE_DIR AND MONGO_C_LIBRARY)
