Copy directory of assets to plugin output dir

Hi,

Is it possible to copy a directory of non-code assets to the same place as the compiled plugin? This would make packaging easier for plugins which include files other than just the compiled plugin. For example, in the build directory created by CMake, I have:

./build/Source/MyPlugin_artefacts/
				                 VST3/MyPlugin.vst3/Contents/x86_64-linux/MyPlugin.so
				                 LV2/MyPlugin.lv2/libMyPlugin.so
				                 Standalone/MyPlugin

For each plugin format I’d like to copy a directory of non-code assets next to the .so file, e.g. ./build/Source/MyPlugin_artefacts/VST3/MyPlugin.vst3/Contents/x86_64-linux/myassets. Is this possible? Looking at JUCEUtils.cmake, it seems that the target property ${LIBRARY_OUTPUT_DIRECTORY} should be the answer, but calling get_target_property() on the MyPlugin target just gives the top-level directory (build/Source/MyPlugin_artefacts). Trying to call get_target_property() on the individual plugin targets added by cmake (MyPlugin_VST3, MyPlugin_LV2 etc) doesn’t seem to work; I guess because get_target_property() is called at configure time and those targets don’t exist until build time.

Is there any way to achieve this?

Thanks!

Try something like

add_custom_command(
    TARGET my-plugin
    POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE_DIR:my-plugin> path/to/my-assets/
)

Thanks a lot for the reply, that helped. This is what worked for me in the end:

set(plugin_formats VST3 LV2 Standalone)

juce_add_plugin(MyPlugin
    # ...etc
    FORMATS ${plugin_formats}
)

foreach(pformat ${plugin_formats})
    set(target MyPlugin_${pformat})

    add_custom_command(
        TARGET ${target}
        PRE_BUILD
        COMMENT "copying assets directory for ${target}"
        COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different 
	    ${CMAKE_CURRENT_SOURCE_DIR}/assets 
	    $<TARGET_FILE_DIR:${target}>/assets
    )
endforeach()

The generated plugin targets now exist when the command is run, so it’s possible to use MyPlugin_VST3, MyPlugin_Standalone etc as the target (which is necessary in order to get the full path where the binaries are written to). Hence the foreach() to perform the copy for each plugin target.

1 Like