Conan vs vcpkg vs CPM vs System Packages
You've now used all three tools. They solve overlapping problems with different philosophies, and none is best everywhere. This lesson puts them side by side, together with the two options that need no package manager at all: system packages and plain FetchContent.
One CMakeLists.txt, three package managers
A well-written CMakeLists.txt doesn't care where fmt comes from: it calls find_package(fmt CONFIG REQUIRED) and links fmt::fmt. Conan and vcpkg both satisfy that through a toolchain file; CPM can too, if you add the package before the build (here through a tiny wrapper that runs CPMAddPackage first):
mkdir -p app && cd app
cat > CMakeLists.txt <<'TXT'
cmake_minimum_required(VERSION 3.25)
project(app CXX)
if(USE_CPM)
include(/opt/cpm/CPM.cmake)
CPMAddPackage("gh:fmtlib/fmt#12.1.0")
else()
find_package(fmt CONFIG REQUIRED)
endif()
add_executable(app main.cpp)
target_link_libraries(app PRIVATE fmt::fmt)
TXT
printf '#include <fmt/core.h>\nint main() { fmt::print("fmt {}\\n", FMT_VERSION); }\n' > main.cpp
printf '[requires]\nfmt/12.1.0\n[generators]\nCMakeDeps\nCMakeToolchain\n' > conanfile.txt
echo '{ "builtin-baseline": "5d4a3dc90c0b3773f3bac81bf41297b54328f471", "dependencies": [ "fmt" ] }' > vcpkg.json
echo -n "Conan: "
conan install . -of build-conan -c tools.build:jobs=1 > /dev/null 2>&1
cmake -B build-conan -DCMAKE_TOOLCHAIN_FILE=build-conan/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release > /dev/null
cmake --build build-conan > /dev/null && ./build-conan/app
echo -n "vcpkg: "
cmake -B build-vcpkg -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DCMAKE_BUILD_TYPE=Release > /dev/null 2>&1
cmake --build build-vcpkg > /dev/null && ./build-vcpkg/app
echo -n "CPM: "
cmake -B build-cpm -DUSE_CPM=ON -DCMAKE_BUILD_TYPE=Release > /dev/null 2>&1
cmake --build build-cpm > /dev/null && ./build-cpm/app
echo -n "system: "
cmake -B build-sys -DCMAKE_BUILD_TYPE=Release 2>&1 | grep -m1 -o 'Could not find a package configuration file provided by "fmt"'Conan: fmt 120100
vcpkg: fmt 120200
CPM: fmt 120100
system: Could not find a package configuration file provided by "fmt"
Three working builds from one file (with different fmt versions: Conan and CPM got 12.1.0 because we asked for it, vcpkg's baseline has 12.2.0). The fourth attempt is "system packages": the container has no libfmt-dev installed, so find_package fails, which is the usual first experience of relying on the system.
The comparison
| Conan 2 | vcpkg | CPM.cmake | FetchContent | System packages | |
|---|---|---|---|---|---|
| What it is | Python tool + recipes + servers | C++ tool + curated port tree | one CMake script | built into CMake | apt, dnf, brew, pacman |
| Package count | ~1,500+ on ConanCenter | 2,500+ ports | any CMake project on Git | any CMake project | thousands, distro-dependent |
| Binaries | yes: per package ID, from remotes | yes: binary cache keyed by ABI hash (you host it) | no (source cache only) | no | yes, one build per distro |
| Versions | exact, ranges, overrides, lockfiles | baseline + version>= + overrides |
Git tags, first declaration wins | Git tags | one per distro release |
| Configurations | profiles: any settings/options combination | triplets + features | whatever your build uses | same | whatever the distro built |
| Build systems for packages | any (CMake, Meson, Autotools, MSBuild, …) | any, via portfiles | CMake only (realistically) | CMake only | n/a |
| Private packages | remotes: Artifactory, conan_server, local index | overlays, git/filesystem registries | any Git URL | any Git URL | own apt/rpm repos |
| Cross-compiling | first-class (host/build profiles) | triplets + chainloaded toolchains | your toolchain | your toolchain | sysroots, multiarch |
| Learning curve | steepest | moderate | minimal | minimal | minimal |
| Lockfile | conan.lock |
not needed (baseline) | package-lock.cmake (optional) |
none | none |
Choosing
- System packages are right for software that a Linux distribution will package, and for tools like compilers. They're wrong as the only source for a cross-platform app: Ubuntu 24.04, Fedora, macOS and Windows will each give you a different version, or none.
- FetchContent / CPM are right for small, light, CMake-friendly dependency sets and for libraries that want zero setup (When CPM Is Enough).
- vcpkg is right when you want a large, consistent catalogue with little configuration, especially with Visual Studio/MSBuild, and when "one version of everything, tested together" is a feature for you.
- Conan is right when you need fine control: many configurations, prebuilt binaries for your own packages, a private server, cross-compiling for embedded targets, or packages built with anything other than CMake.
Large organisations often use more than one: Conan for in-house binary packages and embedded targets, vcpkg in Windows desktop teams, CPM in open-source libraries that want to be easy to consume. What makes that possible is the rule from the session above: CMakeLists.txt talks to find_package and namespaced targets, never to the package manager.
Questions to ask before choosing
- How long would a clean build of all dependencies from source take? If it's more than a few minutes, you need binaries (Conan or vcpkg with a binary cache).
- How many configurations do you build (OS × arch × build type × compiler)? Conan's profiles scale best here.
- Do you publish your own C++ libraries to other teams? Then you need a server: a Conan remote, or a vcpkg registry plus a binary cache.
- Must builds work offline or air-gapped? All three can, but you must plan mirrors (Conan remote proxy, vcpkg asset + binary caching, CPM source cache).
- Who maintains the recipes/ports? ConanCenter and vcpkg's curators maintain public ones; your own need an owner.
Test yourself
Why did the same CMakeLists.txt work with Conan and vcpkg?
- Both patch CMakeLists.txt
- It only uses find_package(fmt CONFIG) and fmt::fmt; both tools provide those through their toolchain files
- They share one cache
- CMake has built-in Conan support
Which option provides prebuilt binaries for your own private packages via a server out of the box?
- CPM.cmake
- FetchContent
- Conan with a remote such as Artifactory
- System packages
What is the main weakness of relying only on system packages for a cross-platform app?
- They're slow
- Each OS and distro release gives a different version, or none
- They can't be used with CMake
- They require Conan