[CXX-1173] Support users adding mongocxx as a CMake subdirectory Created: 16/Dec/16  Updated: 01/Feb/23  Resolved: 09/Sep/20

Status: Closed
Project: C++ Driver
Component/s: Build
Affects Version/s: None
Fix Version/s: 3.7.0, 3.7.0-beta1

Type: New Feature Priority: Major - P3
Reporter: David Golden Assignee: Roberto Sanchez
Resolution: Done Votes: 0
Labels: internal-woes
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CXX-2036 Improve spec test runners Backlog
Related
related to CXX-991 Make it easier to include mongocxx in... Closed
related to CXX-2104 Document how to use C++ driver via CM... Backlog
related to CDRIVER-3783 compile definitions and include direc... Closed
Epic Link: CXX usability improvements
Quarter: FY24Q3

 Description   

Originally from this Google Group post.

I'm trying to include mongo-cxx-driver into my CMake project.

Here is part of my root CMakeLists.txt

project(testprj)
add_subdirectory(libbson)
add_subdirectory(mongo-c-driver)
add_subdirectory(mongo-cxx-driver)

While libbson, and mongo-c-driver compiles without problems, mongo-cxx-driver returns errors. It seams CMake cannot locate mongo-c-driver.

CMake Error at mongo-cxx-driver/src/mongocxx/CMakeLists.txt:23 (find_package):
By not providing "FindLibMongoC.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"LibMongoC", but CMake did not find one.

Could not find a package configuration file provided by "LibMongoC"
(requested version 1.5.0) with any of the following names:

LibMongoCConfig.cmake
libmongoc-config.cmake

Add the installation prefix of "LibMongoC" to CMAKE_PREFIX_PATH or set
"LibMongoC_DIR" to a directory containing one of the above files. If
"LibMongoC" provides a separate development package or SDK, be sure it has
been installed.



 Comments   
Comment by Githook User [ 09/Sep/20 ]

Author:

{'name': 'Roberto C. Sánchez', 'email': 'roberto@connexer.com', 'username': 'rcsanchez97'}

Message: CXX-1173 support integration via CMake add_subdirectory()
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/da9ba45a1d64f63e10e0749116486b541bb71e91

Comment by Mathias Stearn [ 23/Jul/19 ]

Can this be scheduled then? It is fairly difficult to consume the C++ driver right now. It can't be integrated with a common cmake build tree, and requires separately building and installing the driver before it can be used. At the very least we should make it possible to consume the driver(s) directly from the source+build tree after building without an install step to yet another location, but making it possible to have a unified single-command build tree would be even better.

Comment by Roberto Sanchez [ 23/Jul/19 ]

redbeard0531, The short answer is, "no." The work for CXX-1707 (which is currently in progress alongside CDRIVER-3047) will improve the CMake package configuration scripts to provide proper CMake targets instead of just autoconf-style variables pointing to the locations of includes and libraries. That improvement could be further built upon to provide the functionality described in this ticket, but it would most likely require additional work.

Comment by Mathias Stearn [ 23/Jul/19 ]

Will this be handled by CXX-1707?

Comment by Jonathan Wang [ 16/Dec/16 ]

I would recommend using CMake's External Project (include(ExternalProject), externalproject_add()) functionality instead of directly importing the source code into the project. This way, you can include the MongoDB C/C++ tar.gz archive in your project and specify commands to configure and build MongoDB.

Generated at Wed Feb 07 22:01:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.