File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,21 @@ include_guard(GLOBAL)
33option (USERVER_MONGODB_USE_CMAKE_CONFIG "Use mongoc cmake configuration" ON )
44
55if (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})" )
Original file line number Diff line number Diff line change 11project (userver-mongo CXX )
22
3+ set (USERVER_MONGO_LIBMONGOC_NAME mongo::mongoc_static)
4+ set (USERVER_MONGO_LIBBSON_NAME mongo::bson_static)
5+
36if (USERVER_CONAN)
47 find_package (mongoc-1.0 REQUIRED )
58else ()
912userver_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
You can’t perform that action at this time.
0 commit comments