@@ -40,6 +40,61 @@ else()
4040 message (WARNING "Unknown compiler... recklessly proceeding without a version check" )
4141endif ()
4242
43+ set (LIBMONGOC_REQUIRED_VERSION 1.22.1) # TODO: update to 1.24.0 once released.
44+ set (LIBMONGOC_REQUIRED_ABI_VERSION 1.0)
45+
46+ set (NEED_DOWNLOAD_C_DRIVER false CACHE INTERNAL "" )
47+ if (TARGET mongoc_shared OR TARGET mongoc_static)
48+ # If these targets exist, then libmongoc has already been included as a project
49+ # sub-directory
50+ message ("found libmongoc targets declared in current build scope; version not checked" )
51+
52+ if (NOT MONGOCXX_LINK_WITH_STATIC_MONGOC)
53+ set (libmongoc_target mongoc_shared)
54+ else ()
55+ set (libmongoc_target mongoc_static)
56+ endif ()
57+
58+ if (MONGOCXX_BUILD_STATIC)
59+ set (mongocxx_pkg_dep "find_dependency(mongoc-1.0 REQUIRED)" )
60+ endif ()
61+ else ()
62+ find_package (mongoc-${LIBMONGOC_REQUIRED_ABI_VERSION} ${LIBMONGOC_REQUIRED_VERSION} QUIET )
63+ if (mongoc-${LIBMONGOC_REQUIRED_ABI_VERSION} _FOUND)
64+ message ("already found libmongoc, don't need to download it." )
65+ else ()
66+ set (NEED_DOWNLOAD_C_DRIVER true CACHE INTERNAL "" )
67+ endif ()
68+ endif ()
69+
70+ if (${NEED_DOWNLOAD_C_DRIVER} )
71+ message ("No Mongo C Driver path provided via CMAKE_PREFIX_PATH, will download a release from the internet." )
72+ include (FetchContent)
73+ include (ExternalProject)
74+
75+ # Declare mongo-c-driver as a dependency
76+ FetchContent_Declare(
77+ mongo-c-driver
78+ GIT_REPOSITORY https://github.com/kkloberdanz/mongo-c-driver.git
79+ GIT_TAG 1.24.0
80+ )
81+
82+ FetchContent_MakeAvailable(mongo-c-driver)
83+
84+ # Set the installation directory for mongo-c-driver
85+ set (MONGOC_INSTALL_DIR ${CMAKE_BINARY_DIR} /mongo-c-driver-install )
86+
87+ # Build mongo-c-driver using ExternalProject
88+ ExternalProject_Add(mongo-c-driver-build
89+ SOURCE_DIR ${mongo-c-driver_SOURCE_DIR}
90+ BINARY_DIR ${CMAKE_BINARY_DIR} /mongo-c-driver-build
91+ INSTALL_DIR ${MONGOC_INSTALL_DIR}
92+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${MONGOC_INSTALL_DIR}
93+ )
94+ file (REMOVE ${mongo-c-driver_SOURCE_DIR}/build /generate-uninstall.sh)
95+ file (REMOVE ${mongo-c-driver_SOURCE_DIR}/build /generate-uninstall.cmd)
96+ endif ()
97+
4398# All of our target compilers support the deprecated
4499# attribute. Normally, we would just let the GenerateExportHeader
45100# subsystem do this via configure check, but there appears to be a
0 commit comments