JUCE Framework with vcpkg: Quick Guide to C++ Dependency Management

Posted by Jan Wilczek on August 04, 2024 · 3 mins read

C++ package management made easy.

Please accept marketing cookies to access the video player.

If you want to create an audio plugin or a C++ application and you want to use for that purpose the JUCE C++ framework, you always have the problem of how to include JUCE as a dependency.

You can

  • download the sources (don’t!),
  • use git submodules (risky!), or
  • use a C++ package manager.

One of the most popular C++ package managers is vcpkg.

On this blog, I’ve already covered how to use JUCE with the CPM package manager.

Today we’ll see exactly step by step how to use the vcpkg package manager to have JUCE as a dependency.

How to use JUCE with vcpkg

  1. Init an empty repository

    git init .
  2. Add vcpkg as a submodule

    git submodule add https://github.com/microsoft/vcpkg.git
    git commit -m "Added vcpkg as a submodule"
  3. Initialize vcpkg

    .\vcpkg\bootstrap-vcpkg.bat -disableMetrics # Windows
    vcpkg/bootstrap-vcpkg.sh -disableMetrics    # macOS, Linus
  4. Create the vcpkg manifest

    .\vcpkg\vcpkg.exe new --application # Windows
    vcpkg/vcpkg new --application       # macOS, Linux
    • vcpkg-configuration.json is the info of the package registry to download packages from
    • vcpkg.json is the “manifest”: it’s where your dependencies will be listed
  5. Add the JUCE package

    .\vcpkg\vcpkg.exe add port juce  # Windows
    vcpkg/vcpkg add port juce        # macOS, Linux
  6. Create a top-level CMakeLists.txt file

    cmake_minimum_required(VERSION 3.22)
    project(JuceVcpkgDemo)
    
    find_package(juce CONFIG REQUIRED)
  7. Generate the CMake project with the correct toolchain file.

    cmake -S . -B build \
          -DCMAKE_TOOLCHAIN_FILE="vcpkg/scripts/buildsystems/vcpkg.cmake"

    You can simplify this step if you create CMakePresets.json file in the root folder:

    {
      "version": 2,
      "configurePresets": [
        {
          "name": "default",
          "generator": "Visual Studio 17 2022",
          "binaryDir": "${sourceDir}/build",
          "cacheVariables": {
            "CMAKE_TOOLCHAIN_FILE": "vcpkg/scripts/buildsystems/vcpkg.cmake"
          }
        }
      ]
    }

    With CMakePresets.json, you can simply run

    cmake --preset default
  8. Now you are ready to use JUCE. You can follow their CMake examples to get started, for example,

    1. copy the AudioPlugin folder and
    2. add_subdirectory(AudioPlugin) on it in the top-level CMakeLists.txt.

Now you know how to include the JUCE C++ framework as a dependency using the vcpkg package manager.

But… That’s not all!

Want create audio plugins with JUCE? Check what you need to know in my free Audio Developer Checklist.

Share this page on:

Comments powered by Talkyard.

Please accept marketing cookies to access the display and add comments.