juce-framework / JUCE

JUCE is an open-source cross-platform C++ application framework for desktop and mobile applications, including VST, VST3, AU, AUv3, LV2 and AAX audio plug-ins.
https://juce.com
Other
6.64k stars 1.75k forks source link

CMake generated code hits Windows command line length limit on resources compilation #861

Closed Archie3d closed 3 years ago

Archie3d commented 3 years ago

Hi, Using latest JUCE (6.0.7+) with CMake on Windows. The project I am maintaining contains a lot of resource files. When configuring the project with CMake (for ninja) the custom command for the resources compilation generated by function(juce_add_binary_data target) (from JUCEUtils.cmake) results in a very long command line (>32k characters) that fails to execute on Windows:

...
    add_custom_command(OUTPUT ${binary_file_names}
        COMMAND juce::juceaide binarydata "${JUCE_ARG_NAMESPACE}" "${JUCE_ARG_HEADER_NAME}"
            ${juce_binary_data_folder} ${JUCE_ARG_SOURCES}  # <------- *here*
        WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
        DEPENDS ${JUCE_ARG_SOURCES}
        VERBATIM)
...

I'd propose to modify the juceaide tool to optionally accept --files= argument that takes a file containing the list of all resource files to be compiled (as an alternative to passing them on the command line) for the binarydata command:

// Changes to jcueaide
// int writeBinaryData (juce::ArgumentList&& args)
...
    auto fileList = args.getFileForOptionAndRemove ("--files");
    if (fileList.exists())
    {
        juce::StringArray files;
        files.addLines (fileList.loadFileAsString());

        for (const auto& file : files)
        {
            if (file.isNotEmpty())
                resourceFile.addFile (file);
        }
    }
...

with an equivalent change in JUCEUtils.cmake function(juce_add_binary_data target):

...
    set(files_list "")
    foreach(src IN LISTS JUCE_ARG_SOURCES)
        string(APPEND files_list "${src}\n")
    endforeach()
    file(WRITE ${juce_binary_data_folder}/resources.txt ${files_list})

    add_custom_command(OUTPUT ${binary_file_names}
        COMMAND juce::juceaide binarydata "${JUCE_ARG_NAMESPACE}" "${JUCE_ARG_HEADER_NAME}"
            ${juce_binary_data_folder} --files=${juce_binary_data_folder}/resources.txt
        WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
        DEPENDS ${JUCE_ARG_SOURCES}
        VERBATIM)
...

I can make a PR for this if the solution is acceptable. Thanks!

archie3d-spitfireaudio commented 3 years ago

@reuk, This seems to be the fix for the issue. If confirmed, this can be closed then. https://github.com/juce-framework/JUCE/commit/c7d082e770d9286210efd5104d414b6a5dd24b68

reuk commented 3 years ago

Sorry, I missed this issue when you posted it initially, but the same issue was reported on the forum. I believe the commit you linked should resolve the issue, so I'll close this thread.