[CDRIVER-2083] Distribute CMake config packages for statically linking to libbson and libmongoc Created: 09/Mar/17 Updated: 15/Jun/17 Resolved: 12/Jun/17 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | Build, cmake, libbson, libmongoc |
| Affects Version/s: | None |
| Fix Version/s: | 1.7.0 |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | A. Jesse Jiryu Davis | Assignee: | Hannes Magnusson |
| Resolution: | Done | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Epic Link: | convenient-static | ||||||||||||||||||||||||||||
| Comments |
| Comment by Githook User [ 15/Jun/17 ] | |||||||||||||||
|
Author: {u'username': u'bjori', u'name': u'Hannes Magnusson', u'email': u'bjori@php.net'}Message: | |||||||||||||||
| Comment by Hannes Magnusson [ 12/Jun/17 ] | |||||||||||||||
|
We consider this ticket to be fixed now. The Cmake system is experimental and not intended for production use for platforms other then Windows. That being said, we do distribute now
These can be used in native CMake projects via find_package (). Using the PkgConfig module, even with CMake builds, remains our production recommendation, also on Windows. The mongoc CMakeLists.txt still needs work to get up to par with the autotools build system. | |||||||||||||||
| Comment by Githook User [ 12/Jun/17 ] | |||||||||||||||
|
Author: {u'username': u'bjori', u'name': u'Hannes Magnusson', u'email': u'bjori@php.net'}Message: | |||||||||||||||
| Comment by Githook User [ 12/Jun/17 ] | |||||||||||||||
|
Author: {u'username': u'bjori', u'name': u'Hannes Magnusson', u'email': u'bjori@php.net'}Message: | |||||||||||||||
| Comment by Githook User [ 12/Jun/17 ] | |||||||||||||||
|
Author: {'username': 'bjori', 'name': 'Hannes Magnusson', 'email': 'bjori@php.net'}Message: | |||||||||||||||
| Comment by Githook User [ 12/Jun/17 ] | |||||||||||||||
|
Author: {'username': 'bjori', 'name': 'Hannes Magnusson', 'email': 'bjori@php.net'}Message: | |||||||||||||||
| Comment by J Rassi [ 28/Apr/17 ] | |||||||||||||||
|
One more issue: as of current libbson master, I get the following error when statically linking the bsoncxx tests against libbson on the rhel55-test builders (but not the other C++ driver Evergreen builders):
It seems like explicitly adding -lrt to BSON_STATIC_LIBRARIES is required on certain platforms, when clock_gettime() is available and being used. | |||||||||||||||
| Comment by Githook User [ 28/Apr/17 ] | |||||||||||||||
|
Author: {u'username': u'xdg', u'name': u'David Golden', u'email': u'xdg@xdg.me'}Message: When generating .pc files from CMake, we don't want to put absolute This commit splits absolute paths back into separate -L and -l | |||||||||||||||
| Comment by Githook User [ 28/Apr/17 ] | |||||||||||||||
|
Author: {u'username': u'xdg', u'name': u'David Golden', u'email': u'xdg@xdg.me'}Message: | |||||||||||||||
| Comment by Githook User [ 28/Apr/17 ] | |||||||||||||||
|
Author: {'name': 'David Golden', 'email': 'xdg@xdg.me', 'username': 'xdg'}Message: Fixes two cases that were conditional on MSVC and shouldn't have been:
The latter fix just moves `find_package(Threads)` next to commands | |||||||||||||||
| Comment by Githook User [ 28/Apr/17 ] | |||||||||||||||
|
Author: {'name': 'David Golden', 'email': 'xdg@xdg.me', 'username': 'xdg'}Message: | |||||||||||||||
| Comment by Githook User [ 27/Apr/17 ] | |||||||||||||||
|
Author: {u'username': u'xdg', u'name': u'David Golden', u'email': u'xdg@xdg.me'}Message: | |||||||||||||||
| Comment by A. Jesse Jiryu Davis [ 26/Apr/17 ] | |||||||||||||||
|
I don't mind leaving the message calls, or a subset of them, in the documentation. They may actually be informative to readers, and encourage them to use diagnostic messages in their own CMakeLists when they're trying to link to libbson or libmongoc. | |||||||||||||||
| Comment by David Golden [ 26/Apr/17 ] | |||||||||||||||
|
I've taken this ticket, as there's some additional cleanup work to do once we see how the updated code smokes in the CI system:
| |||||||||||||||
| Comment by Githook User [ 26/Apr/17 ] | |||||||||||||||
|
Author: {u'username': u'xdg', u'name': u'David Golden', u'email': u'xdg@xdg.me'}Message: This commit updates the libbson submodule commit point. libbson already publishes two .cmake files, one for shared builds and one This commit uses those .cmake files directly instead of our own FindBSON This commit also changes the generated .cmake files for libmongoc to mongocxx (and maybe the PHP driver) will need a corresponding update. | |||||||||||||||
| Comment by Githook User [ 26/Apr/17 ] | |||||||||||||||
|
Author: {'name': 'David Golden', 'username': 'xdg', 'email': 'xdg@xdg.me'}Message: | |||||||||||||||
| Comment by Githook User [ 21/Apr/17 ] | |||||||||||||||
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}Message: Same as the CMake fix, now with Autools. | |||||||||||||||
| Comment by Githook User [ 21/Apr/17 ] | |||||||||||||||
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}Message: | |||||||||||||||
| Comment by Githook User [ 21/Apr/17 ] | |||||||||||||||
|
Author: {'name': 'David Golden', 'username': 'xdg', 'email': 'xdg@xdg.me'}Message: This commit changes .cmake files to return libraries with absolute paths, See https://cmake.org/cmake/help/v3.0/command/link_directories.html | |||||||||||||||
| Comment by Githook User [ 21/Apr/17 ] | |||||||||||||||
|
Author: {'name': 'David Golden', 'username': 'xdg', 'email': 'xdg@xdg.me'}Message: | |||||||||||||||
| Comment by Githook User [ 21/Apr/17 ] | |||||||||||||||
|
Author: {'name': 'David Golden', 'username': 'xdg', 'email': 'xdg@xdg.me'}Message: add_definitions() has global effect, so isn't good to include libmongoc will need a corresponding update. | |||||||||||||||
| Comment by Githook User [ 21/Apr/17 ] | |||||||||||||||
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}Message: When libmongoc-1.0.pc and libmongoc-static-1.0.pc were generated by | |||||||||||||||
| Comment by Githook User [ 21/Apr/17 ] | |||||||||||||||
|
Author: {'name': 'A. Jesse Jiryu Davis', 'username': 'ajdavis', 'email': 'jesse@mongodb.com'}Message: When a CMake project links to libbson statically it should do: find_package (libbson-static-1.0) With this change, the above command now sets BSON_STATIC_LIBRARIES, not Also, define BSON_STATIC when building the libbson static library. This | |||||||||||||||
| Comment by A. Jesse Jiryu Davis [ 20/Apr/17 ] | |||||||||||||||
|
rassi you commented April 12. You said that "the libmongoc shared library may be falsely advertising that it exports libbson API functions" because it defines BSON_COMPILATION. That's fixed now, there's a separate MONGOC_COMPILATION macro. "The mongoc_static target (and nearly all libmongoc targets) depends on bson-1.0, not bson-1.0-static." I'll fix that. First, libbson-static-1.0-config.cmake.in should set a different variable, BSON_STATIC_LIBRARIES, instead of BSON_LIBRARIES. The other variables BSON_INCLUDE_DIRS and BSON_LIBRARY_DIRS will always be the same whether you use libbson statically or dynamically. Then libmongoc should run:
Then it will build its own static lib by statically linking to libbson's static lib, while continuing to build its dynamic lib by dynamically linking to libbson's dynamic lib. You also wrote, "The libbson and libmongoc static libraries are marking their API functions for DLL export." I don't think that matters, since when a static library is compiled (with any of our compilers), marking a function for DLL export has no effect. david.golden you wrote, "The C++ driver has worked around these issues by only building static or dynamic and not both." Since our Autotools build system can generate both at once, it must able to generate CMake config files that handle the situation where both static and dynamic libbson libs are install, or both static and dynamic libmongoc libs. I want to generate the same config files when libbson or libmongoc are built and installed with CMake, so the CMake config files generated by CMake must also handle the situation where both static and dynamic libs are installed. Therefore, when you build libbson and libmongoc with CMake, the simplest thing is to always build both static and dynamic libs, and generate CMake config files that can handle the situation where both static and dynamic libs are installed, by defining distinct variables like BSON_LIBRARIES and BSON_STATIC_LIBRARIES. | |||||||||||||||
| Comment by Githook User [ 18/Apr/17 ] | |||||||||||||||
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}Message: Also test static and dynamic linking, with and without SSL, on Windows. | |||||||||||||||
| Comment by J Rassi [ 18/Apr/17 ] | |||||||||||||||
|
There is a variable substitution issue in the CMake-generated pkg-config files that affects libmongoc master. My installed libmongoc-1.0.pc file looks like the following (Mac OS X). Note the invalid semicolon in the "Libs" section:
I can reproduce the issue as follows, from the root of the mongo-c-driver repository on my Mac, against libmongoc master (5857491):
My local temporary fix for this issue is to introduce the following code into CMakeLists.txt, and then to replace @SSL_LIBS@ in the relevant pc.in files with @SSL_LIBS_COPY@:
Note that 1.6.2 is not affected (these libraries are omitted from the "Libs" section in libmongoc-1.0.pc on 1.6.2), and the autotools-generated pkg-config files on master are not affected (in those files, these libraries are listed as "-lssl -lcrypto"). | |||||||||||||||
| Comment by Githook User [ 17/Apr/17 ] | |||||||||||||||
|
Author: {'email': 'jesse@mongodb.com', 'username': 'ajdavis', 'name': 'A. Jesse Jiryu Davis'}Message: Also test linking with cmake config files on Windows in Evergreen. | |||||||||||||||
| Comment by David Golden [ 14/Apr/17 ] | |||||||||||||||
|
libmongoc PR is PR/187 | |||||||||||||||
| Comment by David Golden [ 14/Apr/17 ] | |||||||||||||||
|
The C++ driver has worked around these issues by only building static or dynamic and not both, as controlled by the BUILD_SHARED_LIBS variable. While CMake doesn't exactly have a "standard" way to do things, this approach, toggling static or shared, seems often recommended and is used by large, well known libraries like googletest. In the long run, the C driver could explore making a similar change, but in the short run, not changes are necessary to unblock the C++ driver. However, I do believe that libbson should not globally add -DBSON_STATIC to definitions but should instead publish it to a variable for consumers to use in a targeted way. This is implemented in PR/187. I think this PR (and a corresponding change in libmongoc) should be part of the 1.7.0 release. | |||||||||||||||
| Comment by J Rassi [ 12/Apr/17 ] | |||||||||||||||
|
The CMake config files added in the commits above suffer from the issue that the static and non-static versions both export variables with the same names. We should either change them to export variables with different names, or implement the decision that projects relying on them cannot support linking against both the static and non-static versions of the libraries in a single build. Currently, the mongoc_static target (and nearly all libmongoc targets) depends on bson-1.0, not bson-1.0-static. This is due to the fact that libmongoc only calls find_package() on bson-1.0; it doesn't know about the existence of the bson-static-1.0 library at all. This causes some unintuitive results: for example, the mongoc tests (e.g. "test-libmongoc") are linking against static mongoc, but dynamic libbson. I've also discovered the following additional potential issues with the export macros, as written. Consider these issues to be minor, since I don't yet have evidence that they have user impact.
| |||||||||||||||
| Comment by A. Jesse Jiryu Davis [ 07/Apr/17 ] | |||||||||||||||
|
One more task before this is done: Test static and dynamic linking on Windows in Evergreen for libbson and libmongoc. So far I've only done Linux. | |||||||||||||||
| Comment by Hannes Magnusson [ 28/Mar/17 ] | |||||||||||||||
|
Always distributing the cmake package file sounds like a bad idea to me. The cmake manifest is still very much an afterthought and doesn't support nearly everything it should, not even building against the bundled libbson. Installing the cmake package helpers makes this support though become official and irremovable, which means we now have to spent effort into fixing the platform incompatibilities it has, other then just using it for generating windows manifests | |||||||||||||||
| Comment by Githook User [ 27/Mar/17 ] | |||||||||||||||
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}Message: Whether built with CMake or the Autotools, libmongoc now installs CMake Compile and link an example program with all combinations: libmongoc built with | |||||||||||||||
| Comment by Githook User [ 20/Mar/17 ] | |||||||||||||||
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}Message: | |||||||||||||||
| Comment by Githook User [ 20/Mar/17 ] | |||||||||||||||
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}Message: | |||||||||||||||
| Comment by Githook User [ 20/Mar/17 ] | |||||||||||||||
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}Message: | |||||||||||||||
| Comment by Githook User [ 20/Mar/17 ] | |||||||||||||||
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}Message: Add and test config-version.cmake files, update example CMake style, | |||||||||||||||
| Comment by A. Jesse Jiryu Davis [ 15/Mar/17 ] | |||||||||||||||
|
Done for libbson. Still to do for libmongoc. | |||||||||||||||
| Comment by Githook User [ 15/Mar/17 ] | |||||||||||||||
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}Message: Distribute separate pkg-config files and CMake config packages for |