I 'm having trouble understanding how BinaryData works in CMake

Newbie here.
Began to study JUCE since this January and I recently changed my IDE from VS to CLion.
Problem I immediately noticed is that the BinaryData.h seems to work differently at least superficially comparing to previous Projucer-VisualStudio2022 experience. I’m also seeing the BinaryData.h underlined because it was missing.
I was trying to open PNG file and draw it for the “background” but I got no luck understanding or seeing any examples how this thing should be done in CLion.

Thank you for reading. Hope I can address this issue soon.

There are two things to do, one is to create the binary data:

juce_add_binary_data(
        MyProject_data
        SOURCES
        Logo-FF.png
        Logo-FF-text.png
)

And then link it to your target, e.g.:

target_link_libraries(MyProject
        PRIVATE
        MyProject_data
        foleys::foleys_gui_magic
        foleys::foleys_dsp_magic
        juce::juce_core
        juce::juce_audio_processors
        juce::juce_audio_devices
        juce::juce_audio_utils
        juce::juce_gui_basics
        juce::juce_gui_extra
        juce::juce_graphics
        juce::juce_cryptography
        juce::juce_recommended_config_flags
        juce::juce_recommended_lto_flags)
1 Like

You need to add the following to your CMakeLists.txt:

juce_add_binary_data(BinaryData SOURCES
    Logo.png
    Font.ttf
)

and then link to it:

target_link_libraries(${PROJECT_NAME}
    PRIVATE
        BinaryData
        juce::juce_audio_utils
    // ... and so on ...
)

Run cmake again whenever you add new files to the BinaryData.

EDIT: Beaten to it by Daniel! :slight_smile:

2 Likes

Wow I regret hesitating posting questions here. Thanks for the help!

Managed to solved the problem after posting the question here. Thank you so much!