Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cmake/SetupMongoDeps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ include_guard(GLOBAL)
option(USERVER_MONGODB_USE_CMAKE_CONFIG "Use mongoc cmake configuration" ON)

if(USERVER_MONGODB_USE_CMAKE_CONFIG)
# Try to find via modern mongo-c-driver 2.x.x way first
find_package(mongoc 2.0.0 QUIET CONFIG)
if(mongoc_FOUND)
message(STATUS "Mongoc: using config version: (bson: ${bson_VERSION}, mongoc: ${mongoc_VERSION})")

# prefer static libs here for compat
# https://github.com/mongodb/mongo-c-driver/blob/2.0.0/src/libmongoc/etc/mongocConfig.cmake.in#L7-L12
# mongoc::mongoc is mongoc::static first then mongoc::shared. Same for bson.
set(USERVER_MONGO_LIBMONGOC_NAME mongoc::mongoc)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не будет ли луяше сделать тут интерфейсные библиотеки mongo::mongoc_static и mongo::bson_static, и не трогать тогда файл mongo/CMakeLists.txt ?

Copy link
Copy Markdown
Contributor Author

@botanegg botanegg Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не оч понял, они и есть, если искать через v2 подход
Просто для них есть универсальный (на стороне либки) таргет, который делает то, что нужно (берет в приоритете статику, если статики нет, берет soшку)

А все трогание задумано, чтобы была совместимость между v1 и v2 и возможность сфоллбэчится на шаред либку для v2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем появилась надобность:
у нас на archlinux, нету .a (и вообще поломан cmake для mongo-c-driver)

мейнтейнеры арчи не разрешают добавить
https://gitlab.archlinux.org/archlinux/packaging/packages/mongo-c-driver/-/work_items/4

Чтобы запускать юсервер с монгой нативно (удобно разрабатываться) - нужен фолбэк на шаред версию :(

set(USERVER_MONGO_LIBBSON_NAME bson::bson)

return()
endif()

# Go back to 1.x.x
find_package(mongoc-1.0 QUIET CONFIG)
if(mongoc-1.0_FOUND)
message(STATUS "Mongoc: using config version: (bson: ${bson-1.0_VERSION}, mongoc: ${mongoc-1.0_VERSION})")
Expand Down
7 changes: 5 additions & 2 deletions mongo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
project(userver-mongo CXX)

set(USERVER_MONGO_LIBMONGOC_NAME mongo::mongoc_static)
set(USERVER_MONGO_LIBBSON_NAME mongo::bson_static)

if(USERVER_CONAN)
find_package(mongoc-1.0 REQUIRED)
else()
Expand All @@ -9,8 +12,8 @@ endif()
userver_module(
mongo
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
LINK_LIBRARIES mongo::bson_static
LINK_LIBRARIES_PRIVATE mongo::mongoc_static
LINK_LIBRARIES "${USERVER_MONGO_LIBBSON_NAME}"
LINK_LIBRARIES_PRIVATE "${USERVER_MONGO_LIBMONGOC_NAME}"
UTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*_test.cpp"
DBTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*_mongotest.cpp"
DBTEST_DATABASES mongo
Expand Down
Loading