cmake_minimum_required(VERSION 3.1)
set (MESSAGES_ENABLED 1)
function(message)
list (GET ARGV 0 MessageType)
if (MESSAGES_ENABLED)
list (REMOVE_AT ARGV 0)
_message (${MessageType} "${ARGV}")
endif()
endfunction()
set (ENABLE_SSL AUTO CACHE STRING
"Enable TLS connections and SCRAM-SHA-1 authentication.\ Options are
\"DARWIN\" to use Apple's Secure Transport, \"WINDOWS\" to use Windows
Secure Channel, \"OPENSSL\", \"AUTO\",\ or \"OFF\". These options are
case-sensitive. The default is \"AUTO\". Note\ that SCRAM-SHA-1 is
required for authenticating to MongoDB 3.0 and later.")
set (ENABLE_SASL AUTO CACHE STRING
"Enable SASL authentication (Kerberos).\ Options are \"CYRUS\" to use Cyrus
SASL, \"SSPI\" to use Windows Native SSPI, \"GSSAPI\" to use macOS Native GSS,
\"AUTO\",\ or \"OFF\". These options are case-sensitive.")
set(ENABLE_STATIC AUTO CACHE STRING "Build static libmongoc. Set to ON/AUTO/OFF, default AUTO.")
option(ENABLE_TESTS "Build MongoDB C Driver tests." ON)
option(ENABLE_EXAMPLES "Build MongoDB C Driver examples." ON)
option(ENABLE_MAINTAINER_FLAGS "Use strict compiler checks" OFF)
option(ENABLE_AUTOMATIC_INIT_AND_CLEANUP "Enable automatic init and cleanup (GCC only)" ON)
option(ENABLE_CRYPTO_SYSTEM_PROFILE "Use system crypto profile (OpenSSL only)" OFF)
option(ENABLE_TRACING "Turn on verbose debug output" OFF)
set(ENABLE_SNAPPY bundled CACHE STRING "Enable snappy support")
set(ENABLE_ZLIB bundled CACHE STRING "Enable zlib support")
if (NOT WIN32)
message(WARNING "CMake support is experimental and may not produce production quality artifacts")
endif ()
if (ENABLE_SNAPPY STREQUAL "bundled")
project (libmongoc C CXX)
else ()
project (libmongoc C)
endif ()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/build/cmake)
include(InstallRequiredSystemLibraries)
# Set MONGOC_MAJOR_VERSION, MONGOC_MINOR_VERSION, etc.
include(LoadVersion)
LoadVersion(${PROJECT_SOURCE_DIR}/VERSION_CURRENT MONGOC)
LoadVersion(${PROJECT_SOURCE_DIR}/VERSION_RELEASED MONGOC_RELEASED)
message("Current version (from VERSION_CURRENT file): ${MONGOC_VERSION}")
if (NOT ${MONGOC_VERSION} STREQUAL ${MONGOC_RELEASED_VERSION})
message("Previous release (from VERSION_RELEASED file): ${MONGOC_RELEASED_VERSION}")
endif()
include(MaintainerFlags)
# The input variable BSON_ROOT_DIR is respected for backwards compatibility,
# but you should use the standard CMAKE_PREFIX_PATH instead.
message (STATUS "Searching for libbson CMake packages")
find_package (libbson-1.0
"${MONGOC_MAJOR_VERSION}.${MONGOC_MINOR_VERSION}.${MONGOC_MICRO_VERSION}"
HINTS
${BSON_ROOT_DIR}
REQUIRED)
message ("-- libbson found version \"${BSON_VERSION}\"")
message ("-- libbson include path \"${BSON_INCLUDE_DIRS}\"")
message ("-- libbson libraries \"${BSON_LIBRARIES}\"")
if (ENABLE_STATIC STREQUAL ON OR ENABLE_STATIC STREQUAL AUTO)
find_package (libbson-static-1.0
"${MONGOC_MAJOR_VERSION}.${MONGOC_MINOR_VERSION}.${MONGOC_MICRO_VERSION}"
HINTS
${BSON_ROOT_DIR})
if (ENABLE_STATIC STREQUAL ON AND NOT BSON_STATIC_LIBRARY)
message (FATAL_ERROR "Static libbson not found. Pass -DENABLE_STATIC=OFF")
endif ()
if (BSON_STATIC_LIBRARY)
set (MONGOC_ENABLE_STATIC ON)
endif ()
message ("-- libbson-static found version \"${BSON_STATIC_VERSION}\"")
message ("-- libbson-static include path \"${BSON_STATIC_INCLUDE_DIRS}\"")
message ("-- libbson-static libraries \"${BSON_STATIC_LIBRARIES}\"")
endif ()
if (ENABLE_TESTS AND NOT MONGOC_ENABLE_STATIC)
message (FATAL_ERROR "ENABLE_TESTS requires ENABLE_STATIC")
endif ()
if (NOT (ENABLE_SSL STREQUAL DARWIN
OR ENABLE_SSL STREQUAL WINDOWS
OR ENABLE_SSL STREQUAL OPENSSL
OR ENABLE_SSL STREQUAL AUTO
OR ENABLE_SSL STREQUAL OFF))
message (FATAL_ERROR
"ENABLE_SSL option must be DARWIN, WINDOWS, OPENSSL, AUTO, or OFF")
endif()
if (NOT ENABLE_SSL STREQUAL OFF)
# If "AUTO", try OpenSSL. In version 2.0 we'll default to "DARWIN" on Mac.
if (ENABLE_SSL STREQUAL AUTO OR ENABLE_SSL STREQUAL OPENSSL)
# Sets OPENSSL_FOUND on success.
include (FindOpenSSL)
endif ()
if (ENABLE_SSL STREQUAL LIBRESSL)
set (LIBRESSL 1)
endif ()
if (ENABLE_SSL STREQUAL DARWIN)
if (APPLE)
set (SECURE_TRANSPORT 1)
else ()
message (FATAL_ERROR "ENABLE_SSL=DARWIN only supported on Mac OS X")
endif ()
endif ()
if (ENABLE_SSL STREQUAL AUTO AND NOT OPENSSL_FOUND AND APPLE)
set (SECURE_TRANSPORT 1)
endif ()
if (ENABLE_SSL STREQUAL WINDOWS)
if (WIN32)
set (SECURE_CHANNEL 1)
else ()
message (FATAL_ERROR "ENABLE_SSL=WINDOWS only supported on Windows")
endif ()
endif ()
if (ENABLE_SSL STREQUAL AUTO AND NOT OPENSSL_FOUND AND WIN32)
set (SECURE_CHANNEL 1)
endif ()
if (NOT OPENSSL_FOUND AND NOT SECURE_TRANSPORT AND NOT SECURE_CHANNEL AND NOT LIBRESSL)
if (ENABLE_SSL STREQUAL AUTO)
set (ENABLE_SSL OFF)
else ()
message (FATAL_ERROR "No SSL library found")
endif ()
endif ()
endif ()
# Defaults.
set (MONGOC_ENABLE_SSL 0)
set (MONGOC_ENABLE_SSL_OPENSSL 0)
set (MONGOC_ENABLE_SSL_LIBRESSL 0)
set (MONGOC_ENABLE_SSL_SECURE_TRANSPORT 0)
set (MONGOC_ENABLE_SSL_SECURE_CHANNEL 0)
set (MONGOC_ENABLE_CRYPTO 0)
set (MONGOC_ENABLE_CRYPTO_LIBCRYPTO 0)
set (MONGOC_ENABLE_CRYPTO_COMMON_CRYPTO 0)
set (MONGOC_ENABLE_CRYPTO_CNG 0)
set (MONGOC_ENABLE_CRYPTO_SYSTEM_PROFILE 0)
set (MONGOC_ENABLE_COMPRESSION 0)
set (MONGOC_ENABLE_COMPRESSION_SNAPPY 0)
set (MONGOC_ENABLE_COMPRESSION_ZLIB 0)
if (OPENSSL_FOUND)
if (WIN32 AND OPENSSL_VERSION GREATER 1.1 AND NOT
${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.7)
message (FATAL_ERROR "Building against OpenSSL 1.1.0 and later requires CMake 3.7 or later (hint:"
"You can also compile against Windows Secure Transport with -DENABLE_SSL=WINDOWS")
endif ()
set (MONGOC_ENABLE_SSL 1)
set (MONGOC_ENABLE_SSL_OPENSSL 1)
set (MONGOC_ENABLE_CRYPTO 1)
set (MONGOC_ENABLE_CRYPTO_LIBCRYPTO 1)
elseif (SECURE_TRANSPORT)
set (MONGOC_ENABLE_SSL 1)
set (MONGOC_ENABLE_SSL_SECURE_TRANSPORT 1)
set (MONGOC_ENABLE_CRYPTO 1)
set (MONGOC_ENABLE_CRYPTO_COMMON_CRYPTO 1)
elseif (SECURE_CHANNEL)
set (MONGOC_ENABLE_SSL 1)
set (MONGOC_ENABLE_SSL_SECURE_CHANNEL 1)
set (MONGOC_ENABLE_CRYPTO 1)
set (MONGOC_ENABLE_CRYPTO_CNG 1)
elseif (LIBRESSL)
set (MONGOC_ENABLE_SSL 1)
set (MONGOC_ENABLE_SSL_LIBRESSL 1)
set (MONGOC_ENABLE_CRYPTO 1)
set (MONGOC_ENABLE_CRYPTO_LIBCRYPTO 1)
endif ()
if (ENABLE_CRYPTO_SYSTEM_PROFILE)
if (OPENSSL_FOUND)
set (MONGOC_ENABLE_CRYPTO_SYSTEM_PROFILE 1)
else ()
message (FATAL_ERROR "ENABLE_CRYPTO_SYSTEM_PROFILE only available with OpenSSL")
endif ()
endif ()
include(CheckLibraryExists)
CHECK_LIBRARY_EXISTS(ssl ASN1_STRING_get0_data "openssl/asn1.h" MONGOC_HAVE_ASN1_STRING_GET0_DATA)
if (NOT MONGOC_HAVE_ASN1_STRING_GET0_DATA)
set (MONGOC_HAVE_ASN1_STRING_GET0_DATA 0)
endif ()
if (NOT (ENABLE_SASL STREQUAL CYRUS
OR ENABLE_SASL STREQUAL GSSAPI
OR ENABLE_SASL STREQUAL SSPI
OR ENABLE_SASL STREQUAL AUTO
OR ENABLE_SASL STREQUAL OFF))
message (FATAL_ERROR
"ENABLE_SASL option must be CYRUS, GSSAPI, SSPI, AUTO, or OFF")
endif()
# Defaults.
set (MONGOC_ENABLE_SASL 0)
set (MONGOC_ENABLE_SASL_CYRUS 0)
set (MONGOC_ENABLE_SASL_GSSAPI 0)
set (MONGOC_ENABLE_SASL_SSPI 0)
set (MONGOC_HAVE_SASL_CLIENT_DONE 0)
if (NOT ENABLE_SASL STREQUAL OFF)
if (ENABLE_SASL STREQUAL AUTO OR ENABLE_SASL STREQUAL CYRUS)
# Sets SASL_LIBS.
include(FindSASL2)
endif()
if (SASL_FOUND)
set (MONGOC_ENABLE_SASL 1)
set (MONGOC_ENABLE_SASL_CYRUS 1)
elseif ((ENABLE_SASL STREQUAL SSPI OR ENABLE_SASL STREQUAL AUTO) AND WIN32)
set (MONGOC_ENABLE_SASL 1)
set (MONGOC_ENAB