[CDRIVER-1058] Install CMake 'config' style files for find_package Created: 30/Dec/15  Updated: 16/Nov/21  Resolved: 24/Feb/17

Status: Closed
Project: C Driver
Component/s: Build
Affects Version/s: None
Fix Version/s: 1.7.0

Type: Improvement Priority: Major - P3
Reporter: Andrew Morrow (Inactive) Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CDRIVER-1993 cmake doesn't check libbson minimum v... Closed
Related
related to CXX-1158 Unable to link against SSL libs on MacOS Closed

 Description   

In order to use libbson and libmongo-c easily within CMake projects, you need to find them somehow.

The easiest way to do this is to use the CMake pkg_check_modules (https://cmake.org/cmake/help/v3.1/module/FindPkgConfig.html) functionality, and that works just fine on platforms that support pkg-config.

However, not all platforms commonly use pkg-config, notably windows.

On Windows, it is much more likely that packages will be found via a project local 'module' for libbson and libmongoc. That module will in turn use find_package (https://cmake.org/cmake/help/v3.0/command/find_package.html) to look for an installed .cmake file for each of libbson and libmongoc.

Typically, those files would be generated as part of the libbson and libmongoc build process. See https://cmake.org/cmake/help/v3.0/module/CMakePackageConfigHelpers.html for details on what is expected in those files. As noted on that page, a project built with CMake can use some helpers to generate its config-mode package definition .cmake files

It is unclear whether those files need to be generated from an autoconf build of libbson and libmongoc. Any system where autoconf runs almost certainly has pkg-config. So, maybe libmongoc and libbson can simplify things and only generate and install the config-mode package definition files from the CMake build.



 Comments   
Comment by Olivier Bertrand [X] [ 14/May/17 ]

Thanks. I did so yet and was able to test the driver. However, I needed an automatic way to make it with CMake for distribution. I'll wait for version 1.7.0.

Comment by A. Jesse Jiryu Davis [ 14/May/17 ]

I'm sorry I'm doing a bad job of explaining this.

Once we release 1.7.0, then mongo-c-driver-1.7.0.tar.gz will be available. Installing the C Driver from mongo-c-driver-1.7.0.tar.gz will then create libbson-1.0-config.cmake and libmongoc-1.0-config.cmake in the correct directories. We'll release version 1.7.0 within the next month or two.

Meanwhile, install 1.6.2. Installing 1.6.2 does not install libbson-1.0-config.cmake and libmongoc-1.0-config.cmake, so you'll have to set your include path, library path, and add libbson-1.0.dll and libmongoc-1.0.dll to your CMake target manually.

Comment by Olivier Bertrand [X] [ 14/May/17 ]

I don't understand. I have downloaded the files mongo-c-driver-1.6.2.tar.gz from https://github.com/mongodb/mongo-c-driver/releases both in tar.gz and zip format but after extracting them the files libbson-1.0-config.cmake.in and libmongoc-1.0-config.cmake.in do not exist in them.

Comment by A. Jesse Jiryu Davis [ 13/May/17 ]

In the source directory we only have files named libbson-1.0-config.cmake.in and libmongoc-1.0-config.cmake.in. Those files are converted into libbson-1.0-config.cmake and libmongoc-1.0-config.cmake during installation.

If you install libbson and libmongoc using the current code on master, according to the instructions for building on Windows, then files named libbson-1.0-config.cmake and libmongoc-1.0-config.cmake are generated and installed in:

C:\mongo-c-driver\lib\cmake\libbson-1.0\libbson-1.0-config.cmake
C:\mongo-c-driver\lib\cmake\libmongoc-1.0\libmongoc-1.0-config.cmake

There are instructions here to include and link libmongoc in your program, make sure you do find_package(libmongoc-1.0), not find_package(libmongoc).

Comment by Olivier Bertrand [X] [ 15/Apr/17 ]

I followed your instructions and modified my CMakeLists.txt accordingly but it still fails with the same message.

Indeed, looking in the C:\mongo-c-driver directory and sub-directories, there are no files such as libmongocConfig.cmake or libmongoc-config.cmake. Nor in the C:\mongo-c-driver-1.6.2 tree.

Did as miss installing them? And how to do it?

Comment by A. Jesse Jiryu Davis [ 15/Apr/17 ]

Are you using the latest driver from the "master" branch, or 1.6.2? If you're using "master", install the driver to a location like C:\mongo-c-driver, set CMAKE_PREFIX_PATH to C:\mongo-c-driver then follow these instructions:

https://s3.amazonaws.com/mciuploads/mongo-c-driver/docs/latest/tutorial.html#include-and-link-libmongoc-in-your-c-program

To set CMAKE_PREFIX_PATH you might run cmake like this:

cmake -DCMAKE_PREFIX_PATH=C:\mongo-c-driver .

Comment by Olivier Bertrand [X] [ 12/Apr/17 ]

Copying what is done for XML I added in my CMakeLists.txt the following to build my application with the MongoDB C driver:

OPTION(CONNECT_WITH_MONGO "Compile CONNECT storage engine with MONGO support" ON)
 
IF(CONNECT_WITH_MONGO)
  IF(WIN32)
    # Adding some typical places to search in
    SET(PC_MONGO_INCLUDE_DIRS
        C:/mongo-c-driver/include
	D:/mongo-c-driver/include)
    SET(PC_MONGO_LIBRARY_DIRS
        C:/mongo-c-driver/lib
	D:/mongo-c-driver/lib)
  ENDIF(WIN32)
  FIND_PACKAGE(libmongoc)
  IF (MONGO_FOUND)
    INCLUDE_DIRECTORIES(${MONGO_INCLUDE_DIR})
    SET(MONGO_LIBRARY   ${MONGO_LIBRARIES})
    SET(CONNECT_SOURCES ${CONNECT_SOURCES} mongofam.cpp mongofam.h)
    add_definitions(-DMONGO_SUPPORT)
  ENDIF(MONGO_FOUND)
ENDIF(CONNECT_WITH_MONGO)

However, this fails with CMake displaying the following message:

CMake Warning at storage/connect/CMakeLists.txt:310 (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" 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.

What should I do to make it work as well on Windows and on Linux?

Comment by Githook User [ 25/Feb/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1058 fix cmake test in Evergreen
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/05ba957de29220687e76750d28c9e1f488a89f08

Comment by Githook User [ 24/Feb/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1058 cmake package config

Also fix CDRIVER-1993: cmake now checks libbson version.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/8c900de6ed1b87b22c7f7c104fa362fca727eb8a

Comment by Githook User [ 24/Feb/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1058 don't git-ignore cmake files
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/3b86e7ac18297e1634948ef930f4201a32bf572a

Comment by Githook User [ 24/Feb/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1058 update cmake evergreen script
Branch: master
https://github.com/mongodb/libbson/commit/342189792375db3253d4f84c8674b58bfbdc751e

Comment by Githook User [ 22/Feb/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1058 distribute new cmake files
Branch: master
https://github.com/mongodb/libbson/commit/e5c0f9b2cb2ea751d1a5bc0ba1760f2b5283d7ab

Comment by Githook User [ 22/Feb/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1058 rename cmake.sh->compile-unix-cmake.sh

For consistency with libmongoc.
Branch: master
https://github.com/mongodb/libbson/commit/d61607c026e9d590646f8d7c1e286b6baa5c57d5

Comment by A. Jesse Jiryu Davis [ 22/Feb/17 ]

Before finishing, update the build and install docs. See how the C++ driver documents this.

Comment by Githook User [ 22/Feb/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1058 cmake package config
Branch: master
https://github.com/mongodb/libbson/commit/db3b2824d8276941ea202bd53c450de309719173

Comment by A. Jesse Jiryu Davis [ 16/Dec/16 ]

I'm bumping the priority, CXX-1158 would have been obviated if this were implemented.

Comment by Andrew Morrow (Inactive) [ 27/Mar/16 ]

Hi thawkins - I replied on the mongodb-user list with additional details.

Comment by Tim Hawkins [ 27/Mar/16 ]

Can somebody provide an example of how to include libraries for both mongo-c and mongo-cxx (and their corresponding bson libs) in a CMake project? I can find no examples anywhere.

Comment by Andrew Morrow (Inactive) [ 10/Jan/16 ]

We are doing fine with what we have in the C++ driver repo. 1.4 is just fine for this.

Comment by A. Jesse Jiryu Davis [ 07/Jan/16 ]

Is it worth delaying 1.3.1 release in order to include this, or is 1.4 (first quarter of 2016) soon enough for this improvement?

Generated at Wed Feb 07 21:11:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.