How CMake, vcpkg, and JSON Work Together: Explained for C++ Developers

How CMake, vcpkg, and JSON Work Together: Explained for C++ Developers

Understand how CMake, vcpkg, and JSON connect in C++ projects. Learn about manifests, toolchains, presets, and how everything links together in practice.

This is Rambod and in this video we explain how CMake, vcpkg, and JSON files actually work together in a C++ project. Instead of just giving steps, the focus here is on understanding the logic so you can apply it to any project with confidence.

1) What is vcpkg?

Think of vcpkg as a package manager for C++ projects.

Example manifest:

{
  "name": "my-physics-project",
  "version-string": "0.1.0",
  "dependencies": [ "raylib", "chipmunk" ]
}

When you run vcpkg install, vcpkg fetches Raylib and Chipmunk, places them in the vcpkg_installed folder, and prepares them for your build.

2) How CMake connects to vcpkg

CMake is not a compiler — it generates build instructions for compilers. To integrate vcpkg, you use a toolchain file so CMake knows where the libraries live.

This is often referenced in CMakePresets.json. For example:

Together this bridges CMake with the libraries vcpkg installed.

3) CMakePresets.json

Presets simplify how you build projects:

Example fields:

With presets, you can configure once and reuse it everywhere.

4) Understanding CMakeLists.txt

This is the central build file for your project. It typically includes:

Notice how simple this is — vcpkg and CMake handle all the linking logic for you.

5) How it comes together

At this point you have:

Because of this setup, you can just #include "raylib.h" or #include "chipmunk.h", and everything works. No manual paths, no extra config — it is all wired through the manifest and CMake.

6) Why this matters

This workflow saves huge amounts of time:

Wrap up

Now you understand the big picture of how CMake, vcpkg, and JSON work together. You can confidently set up projects, manage dependencies, and know what each piece is doing behind the scenes.

For more C++ guides, check rambod.net, subscribe on YouTube, or watch this explanation here: Watch on YouTube.