JUCE CMake Instruction Not Working with VSCode OSX

Hi, I downloaded a JUCE Cmake project and was trying to build it in VSCode on my OSX machine

I followed the instructions for setting up a JUCE project with CMake that I found here, specifically those for the find package method:

Using find_package

To install JUCE globally on your system, you’ll need to tell CMake where to place the installed files.

# Go to JUCE directory
cd /path/to/clone/JUCE
# Configure build with library components only
cmake -B cmake-build-install -DCMAKE_INSTALL_PREFIX=/path/to/JUCE/install
# Run the installation
cmake --build cmake-build-install --target install

In your project which consumes JUCE, make sure the project CMakeLists.txt contains the line find_package(JUCE CONFIG REQUIRED). This will make the JUCE modules and CMake helper functions available for use in the rest of your build. Then, run the build like so:

# Go to project directory
cd /path/to/my/project
# Configure build, passing the JUCE install path you used earlier
cmake -B cmake-build -DCMAKE_PREFIX_PATH=/path/to/JUCE/install
# Build the project
cmake --build cmake-build

They seem to have worked until I reach the final build step in VSCode. When I run build it still says that the JUCE modules aren’t found. I get the following error message:

CMake Error at CMakeLists.txt:7 (find_package):Could not find a package configuration file provided by "JUCE" with any of
the following names:

  JUCEConfig.cmake
  juce-config.cmake

Add the installation prefix of "JUCE" to CMAKE_PREFIX_PATH or set
"JUCE_DIR" to a directory containing one of the above files.  If "JUCE"
provides a separate development package or SDK, be sure it has been
installed.

Does anybody know how I can fix this and get the project to build in VSCode?

If you following the instructions above, you already should have a build in the cmake-build folder. Is that correct?

In the instructions in the link you posted, there are 2 ways of using juce. The first (an easier) way is to clone juce into your project folder and set

add_subdirectory(JUCE)

Where JUCE the path to your juce clone is.

The second way is what you choosed. You cloned, build and install juce globally on your system and added

find_package(JUCE CONFIG REQUIRED)

To your CmakeLists.txt.

I would choose the first approach.

When I try this approach I get the error:

> [cmake] CMake Error at CMakeLists.txt:9 (find_package):
> [cmake]   Could not find a package configuration file provided by "JUCE" with any of
> [cmake]   the following names:
> [cmake] 
> [cmake]     JUCEConfig.cmake
> [cmake]     juce-config.cmake
> [cmake] 
> [cmake]   Add the installation prefix of "JUCE" to CMAKE_PREFIX_PATH or set
> [cmake]   "JUCE_DIR" to a directory containing one of the above files.  If "JUCE"
> [cmake]   provides a separate development package or SDK, be sure it has been
> [cmake]   installed.
> [cmake] 
> [cmake] 
> [cmake] -- Configuring incomplete, errors occurred!

JUCEConfig.cmake is generated in the cmake-build-install folder.

If I move it into the main juce folder the project still does not recognize it and I get the same error.

Here is my complete CMake.txt file for the main project. What is causing this error?

cmake_minimum_required(VERSION 3.15)
project(PhaseVocoder VERSION 0.0.1)

set (CMAKE_CXX_STANDARD 20)
set (CMAKE_CXX_STANDARD_REQUIRED ON)

add_subdirectory(JUCE)

find_package(JUCE CONFIG REQUIRED)

juce_add_plugin(PhaseVocoder
    # VERSION 0.0.1
    # ICON_BIG ...                              # ICON_* arguments specify a path to an image file to use as an icon for the Standalone
    # ICON_SMALL ...
    COMPANY_NAME Stephen kyne
    # NEEDS_MIDI_INPUT TRUE/FALSE               # Does the plugin need midi input?
    # EDITOR_WANTS_KEYBOARD_FOCUS TRUE/FALSE
    # COPY_PLUGIN_AFTER_BUILD TRUE/FALSE
    PLUGIN_MANUFACTURER_CODE SKST
    PLUGIN_CODE Pvoc0
    FORMATS AU VST3 Standalone                  # The formats to build. Other valid formats are: AAX Unity VST AU AUv3
    PRODUCT_NAME "Phase Vocoder"
)

target_sources(PhaseVocoder
    PRIVATE
        PluginEditor.cpp
        PluginProcessor.cpp)

target_compile_definitions(PhaseVocoder
    PUBLIC
        JUCE_WEB_BROWSER=0
        JUCE_USE_CURL=0
        JUCE_VST3_CAN_REPLACE_VST2=0
)

target_compile_features(PhaseVocoder PUBLIC cxx_std_17)

# If your target needs extra binary assets, you can add them here. The first argument is the name of
# a new static library target that will include all the binary resources. There is an optional
# `NAMESPACE` argument that can specify the namespace of the generated binary data class. Finally,
# the SOURCES argument should be followed by a list of source files that should be built into the
# static library. These source files can be of any kind (wav data, images, fonts, icons etc.).
# Conversion to binary-data will happen when your target is built.

# juce_add_binary_data(AudioPluginData SOURCES ...)

# `target_link_libraries` links libraries and JUCE modules to other libraries or executables. Here,
# we're linking our executable target to the `juce::juce_audio_utils` module. Inter-module
# dependencies are resolved automatically, so `juce_core`, `juce_events` and so on will also be
# linked automatically. If we'd generated a binary data target above, we would need to link to it
# here too. This is a standard CMake command.

target_link_libraries(PhaseVocoder
    PRIVATE
        # AudioPluginData           # If we'd created a binary data target, we'd link to it here
        juce::juce_audio_utils
        juce::juce_dsp
    PUBLIC
        juce::juce_recommended_config_flags
        juce::juce_recommended_lto_flags
        juce::juce_recommended_warning_flags)

Okay, a had a deeper look into this project. Unfortunately it is quite old, so it needs some extra steps for building. Let’s break this down step by step:

At first you clone the project:

git clone https://github.com/stekyne/PhaseVocoder.git

The next step is to clone JUCE into the project folder. You change the dir and clone:

cd PhaseVocoder
git clone https://github.com/juce-framework/JUCE.git

Because the project is a bit older, we need an older version of JUCE. We can checkout an older Version with:

cd JUCE
git checkout 6.0.0
cd ..

Now we modify the CMakeLists.txt to find our juce. change line 7 from:

find_package(JUCE CONFIG REQUIRED)

to:

add_subdirectory(JUCE)

Now we can run cmake and build the project. At first we make a new folder named build. Change into it and start cmake for configure the project:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..

Because of reasons you need to ask the original author of the project, it only builds in DEBUG mode.

Now we are ready to build this:

cmake --build .

If this runs without any errors, a stand alone version is in:

PhaseVocoder/build/PhaseVocoder_artefacts/Debug/Standalone

and a VST3 plugin is located here:

PhaseVocoder/build/PhaseVocoder_artefacts/Debug/VST3

Now you can open the project folder in vscode (you need to install the CMAKE and C++ Extention both from Microsoft) The project should begin to configure.

Thank you for the detailed instructions. This is really helpful.

This all seems to be working, then when I get to the final build stage I get the following errors:

/Users/emmettpalaima/Desktop/WalrusProjects/PhaseVocoder/JUCE/modules/juce_dsp/widgets/juce_WaveShaper.h:78:33: error: no type named 'result_of' in namespace 'std'
static WaveShaper<typename std::result_of<Functor>, Functor> CreateWaveShaper (Functor functionToUse)   { return {functionToUse}; }
                  ~~~~~~~~~~~~~~^~~~~~~~~
/Users/emmettpalaima/Desktop/WalrusProjects/PhaseVocoder/JUCE/modules/juce_dsp/widgets/juce_WaveShaper.h:78:51: error: expected unqualified-id
static WaveShaper<typename std::result_of<Functor>, Functor> CreateWaveShaper (Functor functionToUse)   { return {functionToUse}; }

Which seems to be something embedded deep in the JUCE library. I also get a massive pile of warnings.

I get around this just by deleting the waveshaper widget.

Perhaps you could avoid the compiler error by setting the c++ standard to c++17 instead of delete something in the juce code. To restore the juce code, you move to the JUCE folder:

cd /Users/emmettpalaima/Desktop/WalrusProjects/PhaseVocoder/JUCE/

Now you can checkout the original state:

git checkout -- .

In your CMakeLists.txt set in line 4 from c++20 to c++17:

set (CMAKE_CXX_STANDARD 17)