[CXX-871] Is there a way to build/install bsoncxx without mongocxx without editing CMakeLists.txt's? Created: 21/Mar/16  Updated: 11/Sep/19  Resolved: 09/Sep/16

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

Type: Task Priority: Minor - P4
Reporter: MS [X] Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File 0001-Allow-to-turn-on-off-builds-of-bsoncxx-mongocxx-test.patch    

 Description   

I require to build bsoncxx as static library for the client part of an application running on android and iOS. Bsoncxx builds for both platforms without problems, but mongocxx causes issues in the build and I do not need it for the app.

The only solution I have right now is to edit the following files:
./src/CMakeLists.txt:17 #add_subdirectory(mongocxx) #Do not build mongocxx
./src/bsoncxx/CMakeLists.txt:208 #add_subdirectory(test) #Do not build tests

Is there a better way to do this right now?



 Comments   
Comment by Andrew Morrow (Inactive) [ 09/Sep/16 ]

Happy to hear that the suggestion worked for you. I'm closing this ticket, but feel free to re-open if you have further questions.

Comment by MS [X] [ 09/Sep/16 ]

Thanks for this suggestion, with little changes it works perfectly for me.
A difference to my previous setup is that you need both the static and shared libraries built for the install to succeed.
It is no problem to me since both build fine.

For some reason "ninja src/bsoncxx/all" does not work here but this solution works for me now without touching anything else:

	mkdir build
	cd build
	cmake -G Ninja ./../ 			#Omitted any configuration for this example
	ninja bsoncxx bsoncxx_static 		#the same targets work also if you use make instead of ninja
	cmake -P src/bsoncxx/cmake_install.cmake

So I guess this question can be closed,
thanks for your help!

Comment by Andrew Morrow (Inactive) [ 08/Sep/16 ]

I think I've found a way to accomplish what you want to do without needing to modify the CMakeLists, and without our needing to add options for every component. The trick is to invoke the cmake_install.cmake file for libbsoncxx in script mode after doing a normal build. Here is a log of my doing so:

$ git clean -xfd
Removing build/.ninja_deps
Removing build/.ninja_log
Removing build/CMakeCache.txt
Removing build/CMakeFiles/
Removing build/CTestTestfile.cmake
Removing build/build.ninja
Removing build/cmake_install.cmake
Removing build/compile_commands.json
Removing build/examples/
Removing build/install/
Removing build/rules.ninja
Removing build/src/
 
$ cd build
 
$ PKG_CONFIG_PATH=$HOME/opt/lib/pkgconfig cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=./install -G Ninja
-- The CXX compiler identification is AppleClang 7.3.0.7030031
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The C compiler identification is AppleClang 7.3.0.7030031
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Checking for module 'libbson-1.0>=1.3.4'
--   Found libbson-1.0, version 1.4.0-dev
-- Found LIBBSON: TRUE
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Checking for module 'libmongoc-1.0>=1.3.4'
--   Found libmongoc-1.0, version 1.4.0-dev
-- Found LIBMONGOC: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build
 
$ ninja src/bsoncxx/all
[2/51] Performing download step (git clone) for 'EP_mnmlstc_core'
-- EP_mnmlstc_core download command succeeded.  See also /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/src/EP_mnmlstc_core-stamp/EP_mnmlstc_core-download-*.log
[5/51] Performing configure step for 'EP_mnmlstc_core'
-- EP_mnmlstc_core configure command succeeded.  See also /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/src/EP_mnmlstc_core-stamp/EP_mnmlstc_core-configure-*.log
[6/51] Performing build step for 'EP_mnmlstc_core'
-- EP_mnmlstc_core build command succeeded.  See also /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/src/EP_mnmlstc_core-stamp/EP_mnmlstc_core-build-*.log
[7/51] Performing install step for 'EP_mnmlstc_core'
-- EP_mnmlstc_core install command succeeded.  See also /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/src/EP_mnmlstc_core-stamp/EP_mnmlstc_core-install-*.log
[51/51] Linking CXX executable src/bsoncxx/test/test_bson
 
$ cmake -P src/bsoncxx/cmake_install.cmake
-- Install configuration: "Debug"
-- Up-to-date: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/array
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/array/element.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/array/value.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/array/view.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/array/view_or_value.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/basic
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/basic/array.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/basic/document.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/basic/helpers.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/basic/impl.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/basic/kvp.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/basic/sub_array.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/basic/sub_document.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/concatenate.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/core.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/stream
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/stream/array.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/stream/array_context.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/stream/closed_context.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/stream/document.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/stream/helpers.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/stream/key_context.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/stream/single_context.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/builder/stream/value_context.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/cmake
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/config
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/config/compiler.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/config/postlude.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/config/prelude.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/document
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/document/element.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/document/value.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/document/view.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/document/view_or_value.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/enums
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/enums/binary_sub_type.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/enums/type.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/exception
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/exception/error_code.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/exception/exception.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/json.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/oid.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/stdx
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/stdx/make_unique.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/stdx/optional.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/stdx/string_view.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/string
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/string/view_or_value.hpp
-- Up-to-date: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/third_party
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/types
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/types/value.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/types.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/util
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/util/functor.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/validate.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/view_or_value.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/config/export.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/lib/libbsoncxx.3.0.2-rc0-pre.dylib
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/lib/libbsoncxx._noabi.dylib
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/lib/libbsoncxx.dylib
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/lib/libbsoncxx.a
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/lib/cmake/libbsoncxx-3.0.2-rc0-pre/libbsoncxx-config.cmake
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/lib/cmake/libbsoncxx-3.0.2-rc0-pre/libbsoncxx-config-version.cmake
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/config/config.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/include/bsoncxx/v_noabi/bsoncxx/config/version.hpp
-- Installing: /Users/andrew/Documents/10gen/dev/src/mongo-cxx-driver/build/install/lib/pkgconfig/libbsoncxx.pc

Note that no mongocxx components have been installed:

$ find install | grep -c bsoncxx
90
 
$find install | grep -c mongocxx
0

Would this approach work for your purposes?

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

Thanks for the patch. We will give it a look. I want to do some research on the best way to do this. We will try to tackle it in the next minor release.

Comment by MS [X] [ 23/Mar/16 ]

I attached a little patch that allows me to setup the build like i need it to be.
Options default to on so everything should be built like it was before the changes. I did a little testing with it and for my use case it is enough.

For my build the call now looks like: cmake -DBUILD_MONGOCXX=off -DBUILD_TEST=off ./../

I am relatively new to cmake so there is most likely a better solution to this.

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

I've scheduled this for the 3.1 release, expected over the summer, where we will be making several improvements to the build system.

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

No, I don't think there is a better way to do this right now. I agree it should be possible to build and install just the component(s) you want though. Have you seen a good mechanism for achieving this in other CMake projects?

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