File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,7 +2,25 @@ include_guard(GLOBAL)
22
33option (USERVER_MONGODB_USE_CMAKE_CONFIG "Use mongoc cmake configuration" ON )
44
5+ set (USERVER_MONGO_LIBMONGOC_NAME mongo::mongoc_static)
6+ set (USERVER_MONGO_LIBBSON_NAME mongo::bson_static)
7+
58if (USERVER_MONGODB_USE_CMAKE_CONFIG)
9+ # Try to find via modern mongo-c-driver 2.x.x way first
10+ find_package (mongoc 2.0.0 QUIET CONFIG )
11+ if (mongoc_FOUND)
12+ message (STATUS "Mongoc: using config version: (bson: ${bson_VERSION} , mongoc: ${mongoc_VERSION} )" )
13+
14+ # prefer static libs here for compat
15+ # https://github.com/mongodb/mongo-c-driver/blob/2.0.0/src/libmongoc/etc/mongocConfig.cmake.in#L7-L12
16+ # mongoc::mongoc is mongoc::static first then mongoc::shared. Same for bson.
17+ set (USERVER_MONGO_LIBMONGOC_NAME mongoc::mongoc)
18+ set (USERVER_MONGO_LIBBSON_NAME bson::bson)
19+
20+ return ()
21+ endif ()
22+
23+ # Go back to 1.x.x
624 find_package (mongoc-1.0 QUIET CONFIG )
725 if (mongoc-1.0_FOUND)
826 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 99userver_module (
1010 mongo
1111 SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR} "
12- LINK_LIBRARIES mongo::bson_static
13- LINK_LIBRARIES_PRIVATE mongo::mongoc_static
12+ LINK_LIBRARIES " ${USERVER_MONGO_LIBBSON_NAME} "
13+ LINK_LIBRARIES_PRIVATE " ${USERVER_MONGO_LIBMONGOC_NAME} "
1414 UTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR} /src/*_test.cpp"
1515 DBTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR} /src/*_mongotest.cpp"
1616 DBTEST_DATABASES mongo
You can’t perform that action at this time.
0 commit comments