CMake example compiles but standalone .app will not run

I need to use CMake in order to include some binaries for an external library my VST needs.

I pulled down the JUCE repo, made a new folder with just the contents here:

And then I put in that same dir a copy of the JUCE install folder, and edited the CMakeLists.txt as follows:

cmake_minimum_required(VERSION 3.15)
project(AUDIO_PLUGIN_EXAMPLE VERSION 0.0.1)

### THIS IS ONLY LINE I CHANGED ####
add_subdirectory(JUCE)                    # If you've put JUCE in a subdirectory called JUCE
### ####### ####### ####### ####### ####### ####

juce_add_plugin(AudioPluginExample
    PLUGIN_MANUFACTURER_CODE Juce               # A four-character manufacturer id with at least one upper-case character
    PLUGIN_CODE Dem0                            # A unique four-character plugin id with exactly one upper-case character
    FORMATS AU VST3 Standalone                  # The formats to build. Other valid formats are: AAX Unity VST AU AUv3
    PRODUCT_NAME "MyTestJuceCmake")        # The name of the final executable, which can differ from the target name

target_sources(AudioPluginExample
    PRIVATE
        PluginEditor.cpp
        PluginProcessor.cpp)

target_compile_definitions(AudioPluginExample
    PUBLIC
        # JUCE_WEB_BROWSER and JUCE_USE_CURL would be on by default, but you might not need them.
        JUCE_WEB_BROWSER=0  # If you remove this, add `NEEDS_WEB_BROWSER TRUE` to the `juce_add_plugin` call
        JUCE_USE_CURL=0     # If you remove this, add `NEEDS_CURL TRUE` to the `juce_add_plugin` call
        JUCE_VST3_CAN_REPLACE_VST2=0)

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

then I build with cmake . in the directory with PluginEditor.h and so on.

It works, with this output:

-- Configuring juceaide
-- Building juceaide
-- Exporting juceaide
-- Configuring done (1.1s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/me/code/juce_cmake_example

However, when I try to open the .app file, I cannot:

You can’t open the application “MyTestJuceCmake.app” because it may be damaged or incomplete.

Did I do something wrong in my CMakeLists.txt file?

Very interested in the answer from someone that is skilled in CMake (I am not!) – but way is that:

Xcode should be able to link against additional libraries and “shade” them into the final product. Or is that just not working for the VST3 target?

1 Like

This is only configuring the build. It’s not actually running the build process.

To actually build the entire project, you’d need to run

cmake --build .

Note that running cmake . will generate all of the build files directly into your source tree, which can make your directory structure quite messy and difficult to work with. It’s normally better to supply a build directory explicitly:

cmake . -B cmake-build
cmake --build cmake-build --target AudioPluginExample_VST3
1 Like

@reuk ah, thank you for the helpful context.

using the commands you gave, the project indeed seems to compile something more substantial (it takes more time anyway?)

however, the standalone app does not function.

You can’t open the application “MyTestJuceCmake.app” because it may be damaged or incomplete.

Output here:

-- The C compiler identification is AppleClang 14.0.3.14030022
-- The CXX compiler identification is AppleClang 14.0.3.14030022
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring juceaide
-- Building juceaide
-- Exporting juceaide
-- Configuring done (24.7s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/me/code/juce_cmake_example/cmake-build
[  3%] Building CXX object CMakeFiles/AudioPluginExample.dir/PluginEditor.cpp.o
[  6%] Building CXX object CMakeFiles/AudioPluginExample.dir/PluginProcessor.cpp.o
[ 10%] Building CXX object CMakeFiles/AudioPluginExample.dir/JUCE/modules/juce_audio_plugin_client/juce_audio_plugin_client_utils.cpp.o
[ 13%] Building CXX object CMakeFiles/AudioPluginExample.dir/JUCE/modules/juce_audio_utils/juce_audio_utils.mm.o
[ 16%] Building CXX object CMakeFiles/AudioPluginExample.dir/JUCE/modules/juce_audio_processors/juce_audio_processors_ara.cpp.o
[ 20%] Building CXX object CMakeFiles/AudioPluginExample.dir/JUCE/modules/juce_audio_processors/juce_audio_processors_lv2_libs.cpp.o
[ 23%] Building CXX object CMakeFiles/AudioPluginExample.dir/JUCE/modules/juce_audio_processors/juce_audio_processors.mm.o
[ 26%] Building CXX object CMakeFiles/AudioPluginExample.dir/JUCE/modules/juce_gui_extra/juce_gui_extra.mm.o
[ 30%] Building CXX object CMakeFiles/AudioPluginExample.dir/JUCE/modules/juce_gui_basics/juce_gui_basics.mm.o
In file included from /Users/me/code/juce_cmake_example/JUCE/modules/juce_gui_basics/juce_gui_basics.mm:26:
In file included from /Users/me/code/juce_cmake_example/JUCE/modules/juce_gui_basics/juce_gui_basics.cpp:306:
/Users/me/code/juce_cmake_example/JUCE/modules/juce_gui_basics/native/juce_mac_Windowing.mm:370:73: warning: implicit conversion from nullable pointer 'NSEvent * _Nullable' to non-nullable pointer type 'NSEvent * _Nonnull' [-Wnullable-to-nonnull-conversion]
                                                                 event: event
                                                                        ^
/Users/me/code/juce_cmake_example/JUCE/modules/juce_gui_basics/native/juce_mac_Windowing.mm:425:61: warning: implicit conversion from nullable pointer 'NSEvent * _Nullable' to non-nullable pointer type 'NSEvent * _Nonnull' [-Wnullable-to-nonnull-conversion]
                                                     event: event
                                                            ^
In file included from /Users/me/code/juce_cmake_example/JUCE/modules/juce_gui_basics/juce_gui_basics.mm:26:
In file included from /Users/me/code/juce_cmake_example/JUCE/modules/juce_gui_basics/juce_gui_basics.cpp:307:
/Users/me/code/juce_cmake_example/JUCE/modules/juce_gui_basics/native/juce_mac_MainMenu.mm:514:36: warning: implicit conversion from nullable pointer 'NSMenuItem * _Nullable' to non-nullable pointer type 'NSMenuItem * _Nonnull' [-Wnullable-to-nonnull-conversion]
            [parentMenu removeItem:menuItem];
                                   ^
3 warnings generated.
[ 33%] Building CXX object CMakeFiles/AudioPluginExample.dir/JUCE/modules/juce_graphics/juce_graphics.mm.o
[ 36%] Building CXX object CMakeFiles/AudioPluginExample.dir/JUCE/modules/juce_events/juce_events.mm.o
[ 40%] Building CXX object CMakeFiles/AudioPluginExample.dir/JUCE/modules/juce_core/juce_core.mm.o
[ 43%] Building CXX object CMakeFiles/AudioPluginExample.dir/JUCE/modules/juce_data_structures/juce_data_structures.mm.o
[ 46%] Building CXX object CMakeFiles/AudioPluginExample.dir/JUCE/modules/juce_audio_basics/juce_audio_basics.mm.o
[ 50%] Building CXX object CMakeFiles/AudioPluginExample.dir/JUCE/modules/juce_audio_formats/juce_audio_formats.mm.o
[ 53%] Building CXX object CMakeFiles/AudioPluginExample.dir/JUCE/modules/juce_audio_devices/juce_audio_devices.mm.o
[ 56%] Linking CXX static library AudioPluginExample_artefacts/libMyTestJuceCmake_SharedCode.a
[ 56%] Built target AudioPluginExample
[ 60%] Generating AudioPluginExample_artefacts/JuceLibraryCode/AudioPluginExample_VST3/PkgInfo
[ 63%] Building CXX object CMakeFiles/AudioPluginExample_VST3.dir/JUCE/modules/juce_audio_plugin_client/juce_audio_plugin_client_ARA.cpp.o
[ 66%] Building CXX object CMakeFiles/AudioPluginExample_VST3.dir/JUCE/modules/juce_audio_plugin_client/juce_audio_plugin_client_Standalone.cpp.o
[ 70%] Building CXX object CMakeFiles/AudioPluginExample_VST3.dir/JUCE/modules/juce_audio_plugin_client/juce_audio_plugin_client_Unity.cpp.o
[ 73%] Building CXX object CMakeFiles/AudioPluginExample_VST3.dir/JUCE/modules/juce_audio_plugin_client/juce_audio_plugin_client_VST2.cpp.o
[ 76%] Building CXX object CMakeFiles/AudioPluginExample_VST3.dir/JUCE/modules/juce_audio_plugin_client/juce_audio_plugin_client_VST3.cpp.o
[ 80%] Building CXX object CMakeFiles/AudioPluginExample_VST3.dir/JUCE/modules/juce_audio_plugin_client/juce_audio_plugin_client_AAX.mm.o
[ 83%] Building CXX object CMakeFiles/AudioPluginExample_VST3.dir/JUCE/modules/juce_audio_plugin_client/juce_audio_plugin_client_AU_1.mm.o
[ 86%] Building CXX object CMakeFiles/AudioPluginExample_VST3.dir/JUCE/modules/juce_audio_plugin_client/juce_audio_plugin_client_AU_2.mm.o
[ 90%] Building CXX object CMakeFiles/AudioPluginExample_VST3.dir/JUCE/modules/juce_audio_plugin_client/juce_audio_plugin_client_AUv3.mm.o
[ 93%] Building CXX object CMakeFiles/AudioPluginExample_VST3.dir/JUCE/modules/juce_audio_plugin_client/juce_audio_plugin_client_LV2.mm.o
[ 96%] Building CXX object CMakeFiles/AudioPluginExample_VST3.dir/JUCE/modules/juce_audio_plugin_client/juce_audio_plugin_client_VST_utils.mm.o
[100%] Linking CXX CFBundle shared module AudioPluginExample_artefacts/VST3/MyTestJuceCmake.vst3/Contents/MacOS/MyTestJuceCmake
[100%] Built target AudioPluginExample_VST3

What else am I missing?

@Rincewind the library is libtorch, and from previous replies on this forum:

That said, I will definitely miss the debugger in XCode. And would much rather have it be a “click and add this folder” than learning CMake…but don’t know if there’s a way to do that.

You need to replace AudioPluginExample_VST3 in the build command with the name of the target you want to build, which in this case is AudioPluginExample_Standalone

1 Like

Whoa! that worked. THANK YOU. So is the juce_add_plugin``FORMATS entry the things I can build with an underscore in front of them?

juce_add_plugin(AudioPlugin
    PLUGIN_MANUFACTURER_CODE Juce               # A four-character manufacturer id with at least one upper-case character
    PLUGIN_CODE Dem0                            # A unique four-character plugin id with exactly one upper-case character
    FORMATS AU VST3 Standalone                  # The formats to build. Other valid formats are: AAX Unity VST AU AUv3
    PRODUCT_NAME "MyTestJuceCmake")        # The name of the final executable, which can differ from the target name

Wondering where I might find more docs on this, clearly I have some basic stuff to learn about JUCE + Cmake.

For instance I also want to know how to build with juce_audio_formats enabled and JUCE_USE_FLAC type flags enabled.

EDIT: I found some great docs on CMake with JUCE here, but no mention of modules like juce_audio_formats or flags like JUCE_USE_FLAC

A last question I also have: since in CMake I’m no longer inside XCode, is there an easy way to view stdout and stderr when running the standalone app or the VST?

I want to be able to debug and develop with the CMake build process.

A solution I could do is build my own logging and log to some file, ie: /tmp/juce-logs.txt or whatever, but I’m sure there’s a better paved path for working with JUCE + CMake.

So I was doing some research and it seems like lib torch isn’t just a single static library and some include files that you link and off you go. So rebuilding that manually is gonna be a pain, although the Torch.cmake file should of course contain all the information needed to rebuilt this process.

As an alternative: CMake can also generate an Xcode project with the flag -g Xcode. So maybe this works. If you have a CMake file that can compile your source including linking torch, you just generate an Xcode project and abandon the cmake file.