INCLUDE (CheckCSourceCompiles)
INCLUDE_DIRECTORIES(src)
FILE(GLOB CBSASL_SRC src/*.c)
FILE(GLOB CRAM_SRC src/cram-md5/*.c)
FILE(GLOB SCRAM_SRC src/scram-sha/*.c)

ADD_LIBRARY(cbsasl-lcb OBJECT ${CBSASL_SRC} ${CRAM_SRC} ${SCRAM_SRC})
SET_TARGET_PROPERTIES(cbsasl-lcb
    PROPERTIES
    POSITION_INDEPENDENT_CODE TRUE
    COMPILE_FLAGS "${LCB_CORE_CFLAGS}")

IF(OPENSSL_FOUND AND (NOT LCB_NO_SSL))
    INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
    ADD_DEFINITIONS(${OPENSSL_DEFINITIONS})
    # Check if the system have a usable version of PKCS5_PBKDF2_HMAC
    CMAKE_PUSH_CHECK_STATE(RESET)
    SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${OPENSSL_LIBRARIES})
    SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${OPENSSL_INCLUDE_DIR})
    CHECK_C_SOURCE_COMPILES("
             #include <openssl/evp.h>
             int main() {
                 PKCS5_PBKDF2_HMAC(NULL, 0, NULL, 0, 0, NULL, 0, NULL);
             }" HAVE_PKCS5_PBKDF2_HMAC)
ENDIF()
