C++ package management made easy.
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
-
Init an empty repository
git init .
-
Add vcpkg as a submodule
git submodule add https://github.com/microsoft/vcpkg.git git commit -m "Added vcpkg as a submodule"
-
Initialize vcpkg
.\vcpkg\bootstrap-vcpkg.bat -disableMetrics # Windows vcpkg/bootstrap-vcpkg.sh -disableMetrics # macOS, Linus
-
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
-
Add the JUCE package
.\vcpkg\vcpkg.exe add port juce # Windows vcpkg/vcpkg add port juce # macOS, Linux
-
Create a top-level CMakeLists.txt file
cmake_minimum_required(VERSION 3.22) project(JuceVcpkgDemo) find_package(juce CONFIG REQUIRED)
-
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
-
Now you are ready to use JUCE. You can follow their CMake examples to get started, for example,
- copy the AudioPlugin folder and
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.
Comments powered by Talkyard.