Skip to content

Commit 3734f53

Browse files
botaneggrobot-piglet
authored andcommitted
feat mongo: add CMake support for mongo-c-driver 2.x.x
Tests: протестировано CI --- Pull Request resolved: #1175 commit_hash:88404055d44e6643ddc912434617f36d8f288854
1 parent 9746318 commit 3734f53

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

cmake/SetupMongoDeps.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ include_guard(GLOBAL)
33
option(USERVER_MONGODB_USE_CMAKE_CONFIG "Use mongoc cmake configuration" ON)
44

55
if(USERVER_MONGODB_USE_CMAKE_CONFIG)
6+
# Try to find via modern mongo-c-driver 2.x.x way first
7+
find_package(mongoc 2.0.0 QUIET CONFIG)
8+
if(mongoc_FOUND)
9+
message(STATUS "Mongoc: using config version: (bson: ${bson_VERSION}, mongoc: ${mongoc_VERSION})")
10+
11+
# prefer static libs here for compat
12+
# https://github.com/mongodb/mongo-c-driver/blob/2.0.0/src/libmongoc/etc/mongocConfig.cmake.in#L7-L12
13+
# mongoc::mongoc is mongoc::static first then mongoc::shared. Same for bson.
14+
set(USERVER_MONGO_LIBMONGOC_NAME mongoc::mongoc)
15+
set(USERVER_MONGO_LIBBSON_NAME bson::bson)
16+
17+
return()
18+
endif()
19+
20+
# Go back to 1.x.x
621
find_package(mongoc-1.0 QUIET CONFIG)
722
if(mongoc-1.0_FOUND)
823
message(STATUS "Mongoc: using config version: (bson: ${bson-1.0_VERSION}, mongoc: ${mongoc-1.0_VERSION})")

mongo/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
project(userver-mongo CXX)
22

3+
set(USERVER_MONGO_LIBMONGOC_NAME mongo::mongoc_static)
4+
set(USERVER_MONGO_LIBBSON_NAME mongo::bson_static)
5+
36
if(USERVER_CONAN)
47
find_package(mongoc-1.0 REQUIRED)
58
else()
@@ -9,8 +12,8 @@ endif()
912
userver_module(
1013
mongo
1114
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
12-
LINK_LIBRARIES mongo::bson_static
13-
LINK_LIBRARIES_PRIVATE mongo::mongoc_static
15+
LINK_LIBRARIES "${USERVER_MONGO_LIBBSON_NAME}"
16+
LINK_LIBRARIES_PRIVATE "${USERVER_MONGO_LIBMONGOC_NAME}"
1417
UTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*_test.cpp"
1518
DBTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*_mongotest.cpp"
1619
DBTEST_DATABASES mongo

0 commit comments

Comments
 (0)