Including mongocxx in 2020

Viewed 830

When I try to include mongo using

find_package(libmongocxx REQUIRED)
find_package(libbsoncxx REQUIRED)

All I get is >

  This CMake target is deprecated.  Use 'mongo::mongocxx_shared' instead.
  Consult the example projects for further details.
  This CMake target is deprecated.  Use 'mongo::bsoncxx_shared' instead.
  Consult the example projects for further details.

How should I properly include mongo? I'm a bit lost.

A note, I can include it and it "works" but I'd like to do it "properly".

1 Answers

Yes you are using old instruction. Now you just can use something like this:

cmake_minimum_required(VERSION 3.16)
project(mongo_test)

set(CMAKE_CXX_STANDARD 17)

add_executable(mongo_test main.cpp)

find_package(mongocxx REQUIRED)
find_package(bsoncxx REQUIRED)
include_directories(${LIBMONGOCXX_INCLUDE_DIR})
include_directories(${LIBBSONCXX_INCLUDE_DIR})

target_link_libraries(${PROJECT_NAME} PRIVATE mongo::bsoncxx_shared)

target_link_libraries(${PROJECT_NAME} PRIVATE mongo::mongocxx_shared)

Works on Fedora 32 (gcc 10.1, cmake version 3.16)

Related