CMake: Windows Resource.rc file for plugin and console targets

I’ve been converting my projects to use the JUCE CMake functions and have noticed there is no Resource.rc file added to the Windows plugin targets or console apps. Only the standalone plugin target and the GUI app target have a Resource.rc file.

In my project I want to include resources in the same way for every target and in console apps for automated tests.

I’m not sure about Projucer, but I’ve previously been using FRUT which I believe does add a Windows RC file to every target.

Would it be possible to add this same behaviour to the JUCE CMake functions?

For now I have some workaround functions - but it’s obviously not ideal to be calling the “private” juce functions.

#------------------------------------------------------------------------------
# When a JUCE console app is created it will not have a resource file on Windows.
# Call this for any JUCE console app that requires embedded resources.
#------------------------------------------------------------------------------
function (add_windows_resource_file_to_juce_console_app targetName)
    if (NOT WIN32)
        return()
    endif()

    # A JUCE console app will not have a configuration info file.
    # We need to create this first so it can be used in the
    # _juce_add_resources_rc function.
    _juce_write_configure_time_info (${targetName})
    _juce_add_resources_rc (${targetName} ${targetName})
endfunction()

#------------------------------------------------------------------------------
# When a JUCE plugin app is created it only add a resource file for the
# Standalone target. This function will add a resource file to all other plugin
# formats.
# Call this for any JUCE plugin app that requires embedded resources.
#------------------------------------------------------------------------------
function (add_windows_resource_file_to_juce_plugin_app pluginName)
    if (NOT WIN32)
        return()
    endif()

    get_target_property (juce_library_code ${pluginName} JUCE_GENERATED_SOURCES_DIRECTORY)
    set (resource_rc_file "${juce_library_code}/resources.rc")

    # If there's no standalone target a resource file build rule won't have been
    # created.
    # The plugin's shared library doesn't need to include the resource file but
    # it's more convenience to create resource file build rule using the shared
    # library target.
    if (NOT TARGET ${pluginName}_Standalone)
        _juce_add_resources_rc (${pluginName} ${pluginName})
    endif()

    # We only need one resource file per plug in. Here we add it as a source to
    # each plugin format.
    foreach (format VST3 AAX)
        if (TARGET ${pluginName}_${format})
            target_sources (${pluginName}_${format} PRIVATE "${resource_rc_file}")
        endif()
    endforeach()
endfunction()
3 Likes

Thanks for reporting, this looks like an oversight and a difference in behaviour between the Projucer and JUCE’s CMake support. I’ll look at adding a resources.rc to all JUCE targets by default.

1 Like

Thanks @reuk

Thanks for reporting, that’s on develop now:

I only just got round to trying this out. From my initial tests it all looks to be working as expected. Thanks again @reuk .

1 Like

Any idea when this will make it into the main branch?

We’re hoping to update the master branch in a week or two, in the absence of any new high-priority bugs.

1 Like

Thank you - we can wait for that - Although having tried to build on the develop branch though I think the SmoothedValue not supporting SIMDRegister any more is a bit of a regression :slight_smile:

A fix for that will be merged before the master update.

1 Like