From 308ae318105837c102b7c6d25b5adcc80eb0b237 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 15 Aug 2023 13:41:38 +0100 Subject: [PATCH] CMake: Allow VST3 manifest generation to run later in the build --- docs/CMake API.md | 24 ++++++++ extras/Build/CMake/JUCEUtils.cmake | 89 +++++++++++++++++++++++------- 2 files changed, 92 insertions(+), 21 deletions(-) diff --git a/docs/CMake API.md b/docs/CMake API.md index 6586d7783..2bd1d8f85 100644 --- a/docs/CMake API.md +++ b/docs/CMake API.md @@ -644,6 +644,17 @@ attributes directly to these creation functions, rather than adding them later. `kARAPlaybackTransformationContentBasedFadeAtTail`, `kARAPlaybackTransformationContentBasedFadeAtHead` +`VST3_AUTO_MANIFEST` +- May be either TRUE or FALSE (defaults to TRUE). When TRUE, a POST_BUILD step will be added to the + VST3 target which will generate a moduleinfo.json file into the Resources subdirectory of the + plugin bundle. This is normally desirable, but does require that the plugin can be successfully + loaded immediately after building the VST3 target. If the plugin needs further processing before + it can be loaded (e.g. custom signing), then set this option to FALSE to disable the automatic + manifest generation. To generate the manifest at a later point in the build, use the + `juce_enable_vst3_manifest_step` function. It is strongly recommended to generate a manifest for + your plugin, as this allows compatible hosts to scan the plugin much more quickly, leading to + an improved experience for users. + #### `juce_add_binary_data` juce_add_binary_data( @@ -704,6 +715,19 @@ If your custom build steps need to use the location of the plugin artefact, you by querying the property `JUCE_PLUGIN_ARTEFACT_FILE` on a plugin target (*not* the shared code target!). +#### `juce_enable_vst3_manifest_step` + + juce_enable_vst3_manifest_step() + +You may call this function to manually enable VST3 manifest generation on a plugin. The argument to +this function should be a target previously created with `juce_add_plugin`. + +VST3_AUTO_MANIFEST TRUE will cause the VST3 manifest to be generated immediately after building. +This is not always appropriate, if extra build steps (such as signing or modifying the plugin +bundle) must be executed before the plugin can be loaded. In such cases, you should set +VST3_AUTO_MANIFEST FALSE, use `add_custom_command(TARGET POST_BUILD)` to add your own post-build +steps, and then finally call `juce_enable_vst3_manifest_step`. + #### `juce_set__sdk_path` juce_set_aax_sdk_path() diff --git a/extras/Build/CMake/JUCEUtils.cmake b/extras/Build/CMake/JUCEUtils.cmake index ad26b7979..0a6218f32 100644 --- a/extras/Build/CMake/JUCEUtils.cmake +++ b/extras/Build/CMake/JUCEUtils.cmake @@ -886,6 +886,15 @@ function(_juce_set_copy_properties shared_code target from to_property) endfunction() function(juce_enable_copy_plugin_step shared_code_target) + get_target_property(step_added ${shared_code_target} _JUCE_PLUGIN_COPY_STEP_ADDED) + + if(step_added) + message(WARNING "Plugin copy step requested multiple times for ${shared_code_target}") + return() + endif() + + set_target_properties(${shared_code_target} PROPERTIES _JUCE_PLUGIN_COPY_STEP_ADDED TRUE) + get_target_property(active_targets "${shared_code_target}" JUCE_ACTIVE_PLUGIN_TARGETS) foreach(target IN LISTS active_targets) @@ -981,6 +990,55 @@ function(_juce_add_vst3_manifest_helper_target) target_link_libraries(juce_vst3_helper PRIVATE Threads::Threads ${CMAKE_DL_LIBS} juce_recommended_config_flags) endfunction() +function(juce_enable_vst3_manifest_step shared_code_target) + get_target_property(manifest_step_added ${shared_code_target} _JUCE_VST3_MANIFEST_STEP_ADDED) + + if(manifest_step_added) + message(WARNING "VST3 manifest generation has already been enabled for target ${shared_code_target}. " + "You may need to set VST3_AUTO_MANIFEST FALSE in juce_add_plugin, and/or check that you're " + "not calling juce_enable_vst3_manifest_step multiple times.") + return() + endif() + + get_target_property(copy_step_added ${shared_code_target} _JUCE_PLUGIN_COPY_STEP_ADDED) + + if(copy_step_added) + message(FATAL "VST3 manifest generation would run after plugin copy step, so it has been disabled. " + "If you're manually calling juce_enable_vst3_manifest_step, then you probably need to call " + "juce_enable_copy_plugin_step too.") + endif() + + if((MSYS OR MINGW) AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9) + message(WARNING "VST3 manifest generation is disabled for ${shared_code_target} because the compiler is not supported.") + return() + endif() + + set(target_name ${shared_code_target}_VST3) + get_target_property(product ${target_name} JUCE_PLUGIN_ARTEFACT_FILE) + + if(NOT product) + message(FATAL "Property JUCE_PLUGIN_ARTEFACT_FILE not set for ${target_name}") + endif() + + # Add a target for the helper tool + _juce_add_vst3_manifest_helper_target() + + get_target_property(target_version_string ${shared_code_target} JUCE_VERSION) + + # Use the helper tool to write out the moduleinfo.json + add_custom_command(TARGET ${target_name} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E remove -f "${product}/Contents/moduleinfo.json" + COMMAND ${CMAKE_COMMAND} -E make_directory "${product}/Contents/Resources" + COMMAND juce_vst3_helper + -create + -version "${target_version_string}" + -path "${product}" + -output "${product}/Contents/Resources/moduleinfo.json" + VERBATIM) + + set_target_properties(${shared_code_target} PROPERTIES _JUCE_VST3_MANIFEST_STEP_ADDED TRUE) +endfunction() + # ================================================================================================== function(_juce_set_plugin_target_properties shared_code_target kind) @@ -1014,7 +1072,6 @@ function(_juce_set_plugin_target_properties shared_code_target kind) _juce_create_windows_package(${shared_code_target} ${target_name} vst3 "" x86-win x86_64-win) - # Forward-slash separator is vital for moduleinfotool to work correctly on Windows! set(output_path "${products_folder}/${product_name}.vst3") if((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD")) @@ -1023,26 +1080,13 @@ function(_juce_set_plugin_target_properties shared_code_target kind) LIBRARY_OUTPUT_DIRECTORY "${output_path}/Contents/${JUCE_TARGET_ARCHITECTURE}-linux") endif() - # The VST3 helper tool requires which is broken before mingw version 9 - if((NOT (MSYS OR MINGW)) OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9) - # Add a target for the helper tool - _juce_add_vst3_manifest_helper_target() + _juce_set_copy_properties(${shared_code_target} ${target_name} "${output_path}" JUCE_VST3_COPY_DIR) - get_target_property(target_version_string ${shared_code_target} JUCE_VERSION) + get_target_property(vst3_auto_manifest ${shared_code_target} JUCE_VST3_AUTO_MANIFEST) - # Use the helper tool to write out the moduleinfo.json - add_custom_command(TARGET ${target_name} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E remove -f "${output_path}/Contents/moduleinfo.json" - COMMAND ${CMAKE_COMMAND} -E make_directory "${output_path}/Contents/Resources" - COMMAND juce_vst3_helper - -create - -version "${target_version_string}" - -path "${output_path}" - -output "${output_path}/Contents/Resources/moduleinfo.json" - VERBATIM) + if(vst3_auto_manifest) + juce_enable_vst3_manifest_step(${shared_code_target}) endif() - - _juce_set_copy_properties(${shared_code_target} ${target_name} "${output_path}" JUCE_VST3_COPY_DIR) elseif(kind STREQUAL "VST") set_target_properties(${target_name} PROPERTIES BUNDLE_EXTENSION vst @@ -1514,9 +1558,11 @@ function(_juce_set_fallback_properties target) _juce_set_property_if_not_set(${target} SUPPRESS_AU_PLIST_RESOURCE_USAGE FALSE) - _juce_set_property_if_not_set(${target} HARDENED_RUNTIME_ENABLED NO) - _juce_set_property_if_not_set(${target} APP_SANDBOX_ENABLED NO) - _juce_set_property_if_not_set(${target} APP_SANDBOX_INHERIT NO) + _juce_set_property_if_not_set(${target} HARDENED_RUNTIME_ENABLED FALSE) + _juce_set_property_if_not_set(${target} APP_SANDBOX_ENABLED FALSE) + _juce_set_property_if_not_set(${target} APP_SANDBOX_INHERIT FALSE) + + _juce_set_property_if_not_set(${target} VST3_AUTO_MANIFEST TRUE) get_target_property(is_synth ${target} JUCE_IS_SYNTH) @@ -1771,6 +1817,7 @@ function(_juce_initialise_target target) HARDENED_RUNTIME_ENABLED APP_SANDBOX_ENABLED APP_SANDBOX_INHERIT + VST3_AUTO_MANIFEST PLUGIN_NAME PLUGIN_MANUFACTURER_CODE