Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use a package manager with CMake?

Tags:

c++

cmake

I'm currently evaluating C++ package managers for a project at work and am starting to wonder why do I need them when CMake and a remote DVCS server seem to do the trick just fine.

On my personal projects I use ExternalProject to pull and build any dependencies I have. Meanwhile Conan, vcpkg, hunter and possibly others claim to do the same thing.

vcpkg for example seems to require each project to have a .cmake file so it can be used with CMake find_package.

So, why use a package manager at all?

like image 257
ruipacheco Avatar asked Apr 09 '19 09:04

ruipacheco


2 Answers

While using CMake's ExternalProject_Add directly can have advantages such as compile flags that match exactly, correctly configuring packages is not always trivial. Furthermore, package managers allow you to reuse dependency sources and binaries between projects, leading to massively reduced storage requirements. This is true even in package managers like vcpkg that build from source, as they only download sources once (and build once per configuration to generate binaries) and not once per build folder (and per configuration for binaries). And those savings can be significant, especially with dependencies like Qt that are several gigabytes in size. Analogously, you also save a lot of time.

TL;DR:

  • Ease of use
  • Reduced storage requirements (if you use a library more than once)
  • Reduced build times (if the package manager has binary packages or you use a library more than once)
like image 93
Joe Avatar answered Sep 29 '22 00:09

Joe


If you have multiple (independently built) projects, and they use a lot of the same libraries, a package manager like hunter or vcpkg will compile and store libraries only once (per build platform), saving build time and disk space.

But if your projects are built together, and you cross-compile for multiple platforms (Windows x86, Windows x64, macOS, Linux, iOS, Android (4 different ABIs), WebAssembly, etc.), you indeed may be better off using FetchContent or ExternalProject directly.

For me it was the second case (Scapix project), and in the end I created a small and very simple "package manager" (cmodule) specifically for this case: it only shares downloaded and unpacked library sources, while builds are performed as part of the overall project build.

like image 35
Boris Rasin Avatar answered Sep 29 '22 00:09

Boris Rasin