Windows RC Compiler Issues With CMake

My team has a fairly large application that has recently run in to the windows command line character limit issue when compiling with CMake. It is fairly trivial to resolve with response files for clang and ninja, but CMake’s wrapper for the windows RC compiler doesn’t support this feature. Juce’s generated .rc file currently gets all the project files passed in as a dependency even though it isn’t required. The best solution I was able to to come up with requires a modification to JUCEUtils.cmake, but if anyone has a more elegant way to solve it please let me know.

function(_juce_add_resources_rc source_target dest_target)
    if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
        return()
    endif()
    get_target_property(juce_library_code ${source_target} JUCE_GENERATED_SOURCES_DIRECTORY)
    set(input_info_file "$<TARGET_PROPERTY:${source_target},JUCE_INFO_FILE>")
    get_target_property(generated_icon ${source_target} JUCE_ICON_FILE)
    set(dependency)
    if(generated_icon)
        set(dependency DEPENDS "${generated_icon}")
    endif()
    set(resource_rc_file "${juce_library_code}/resources.rc")
    add_custom_command(OUTPUT "${resource_rc_file}"
        COMMAND juce::juceaide rcfile "${input_info_file}" "${resource_rc_file}"
        ${dependency}
        VERBATIM)

    ###################################################################################################################
    # Modified by minimal audio to fix standalone windows builds. The RC compiler does not support response files so
    # we put the resource file in it's own library with no additional includes to avoid the win cmd character limit
    if (NOT TARGET ${source_target}_rc_lib)
        add_library(${source_target}_rc_lib OBJECT ${resource_rc_file})
        set_target_properties(${source_target}_rc_lib PROPERTIES INCLUDE_DIRECTORIES "")
    endif ()

    target_link_libraries(${dest_target} PRIVATE ${source_target}_rc_lib)
    ###################################################################################################################
endfunction()

+1

It looks to me like the bulk of the commandline is made up of preprocessor definitions and include directories. I don’t see project source files being passed.

I’m not sure what the best solution is here. The CMake behaviour (passing the project preprocessor defs and include directories) seems to match the Projucer’s behaviour. The generated .rc file also allows including a user-defined rc file by setting the JUCE_USER_DEFINED_RC_FILE preprocessor definition, so I don’t think we can remove the definitions+includes without potentially breaking user projects.

Perhaps we could check to see whether JUCE_USER_DEFINED_RC_FILE is defined for the target, and avoid carrying over the includes+defines when JUCE_USER_DEFINED_RC_FILE is not defined.