5

I'm using the conan package manager to install my dependencies for a project. That project needs boost system only of all boost libraries, since I'm only using asio and beast.

However, conan installs every part of boost, which is undesirable. If I'm installing it through a docker container on a mac machine, it takes more than an hour and the boost directory in the conan cache is more than one gigabyte on any platform, which is ten time more heavy than all other libraries combined.

I only want to install Boost.system, which in general should be quite lightweight. Is there a way to do that? Here's the conent of my conan file:

[requires]
boost/1.73.0 # here! I'd like something like "boost.system/1.73.0"
nlohmann_json/3.9.0
fmt/7.0.2
# other libs...

[generators]
cmake

[options]
nlohmann_json:implicit_conversions=False

I'm requiring boost 1.73 and I will switch to requiring 1.74 soon.

In my CMake, I do this:

target_link_libraries(my_app PRIVATE Boost::system)

Everything works there, but it's still much much more heavy than it should be, and it slows down deployment significantly.

Guillaume Racicot
  • 39,621
  • 9
  • 77
  • 141

1 Answers1

7

You are looking for Boost 1.73.0 from Conan Center Index, which is the more recent version available in CCI. However, the idea will be using Components instead of creating a new recipe for each module. Why? We learned from Bincrafters that's hard to maintain, some fixes can affect all modules and replicating will require more effort. Thus, the main idea will consuming boost/1.73.0, just like you have, but requiring only what you need:

target_link_libraries(foobar boost::system)

Currently, there is a Pull Request under development to provide Components in Boost. From Bincrafters side, the modular Boost update is stopped due the Conan Center Index's advantage. One of main challenges is solving the cyclical dependency between Boost's modules, in Bincrafters we did "manually", but now in CCI we are using boost-dep, which will be much better.

So if you don't have boost.system available, what can you do now? Use options, disable what you don't want and build from sources. Or, use find_library to list only Boost.System

Update: Now, Pull Request was merged in the CCI, and boost components are available for all conan boost versions (starting from 1.69.0).

Community
  • 1
  • 1
uilianries
  • 3,363
  • 15
  • 28
  • As a follow up to this do you have to specifically call out which Boost libraries are being used or is there a way to do this using the Conan generator based on what is in the conanfile.py? I have been trying things based on the docs but can't anywhere. I wanted to do this for something that depends on more than Boost ASIO without having to explicitly list every library for CMake. – Rob Baily Apr 15 '21 at 22:16
  • 1
    Take a look on Boost test package, it works like a good example how to consume only a specific module: https://github.com/conan-io/conan-center-index/blob/master/recipes/boost/all/test_package/CMakeLists.txt – uilianries Apr 16 '21 at 12:28
  • Based on this then it looks like for CMake the only option is use the specific reference to the library and not any type of Conan variable that is part of the CMake generation. Using the specific libraries seems OK for small projects but if dependencies start adding up then it makes the CMake process a little more tedious and requires consumers to know all of the dependencies in the tree to link correctly. Have then been any discussions around that? Maybe this is expected and accepted which is fine but I have been trying to do the dependency management exclusively with conan and its gens. – Rob Baily Apr 16 '21 at 16:01
  • Meaning what I would really like to do when consuming is specify the component as part of the requirements for the included project and have that translated into the variables in conanbuildinfo.cmake so that I don't need to specify the ones I want in CMakeLists.txt and just use ${CONAN_LIBS} in there and get the components that I want for the project. If there is any place this is being discussed let me know and I can converse there. – Rob Baily Apr 16 '21 at 16:06
  • The consumer don't need to know all dependencies, those dependencies are solved by CMake targets. If Boost.system requires another Boost lib or project, CMake will solve it. Also, you don't need CMake variable if you have Cmake targets, the result is same or even better. – uilianries Apr 16 '21 at 20:27
  • How do you use components? – Kiruahxh Aug 28 '23 at 15:18