Every way to bring in a library
FetchContent, vcpkg, Conan, an installed package, or a C library you wrap yourself. How each gets the code into your build.
Whichever tool fetches it, your CMakeLists.txt ends the same way:
target_link_libraries(<your target> PRIVATE <library's :: target>).
Pick the tool by the library and the project.
- Small, quick to build, one or two of them → FetchContent: CMake downloads and builds it with your project.
- Big, or many, and building each once on your machine is fine → vcpkg in manifest mode.
- Many, on many platforms, and you'd like prebuilt binaries where they exist → Conan 2.
- Already installed, by a package manager or by its own
cmake --install→find_package. - A plain C library with no CMake support → wrap it in a small C++ class so the rest of your code gets RAII and C++ errors.
Before choosing any of them, check whether the library is header-only, static or shared. That decides what has to be found at run time.
What you're bringing in
Section
What a dependency is
Section
A tour of popular libraries
The three tools
Section
FetchContent
Build it from source, inside your own build.
Section
vcpkg in manifest mode
A vcpkg.json lists what you need; the toolchain file makes find_package see it.
Section
Conan 2
A conanfile and a profile, with prebuilt binaries where they match your settings.
Already installed, or your own
The other side of the same deal, making your own library findable.