From 3f17cc7b2e4ca8eea704792216676892f45419dc Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 24 Mar 2021 13:46:45 +0000 Subject: [PATCH] CMake: Add juce_enable_copy_plugin_step function --- docs/CMake API.md | 18 ++++++++++ extras/Build/CMake/JUCEUtils.cmake | 56 +++++++++++++++++++++--------- 2 files changed, 57 insertions(+), 17 deletions(-) diff --git a/docs/CMake API.md b/docs/CMake API.md index 1fd2f241db..d6e1594ff0 100644 --- a/docs/CMake API.md +++ b/docs/CMake API.md @@ -589,6 +589,24 @@ disabled by setting the compile definitions `DONT_SET_USING_JUCE_NAMESPACE` and JuceHeader.h is optional. Instead, module headers can be included directly in source files that require them. +#### `juce_enable_copy_plugin_step` + + juce_enable_copy_plugin_step() + +As an alternative to the JUCE_COPY_PLUGIN_AFTER_BUILD property, you may call this function to +manually enable post-build copy on a plugin. The argument to this function should be a target +previously created with `juce_add_plugin`. + +JUCE_COPY_PLUGIN_AFTER_BUILD will cause plugins to be installed 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 install. In such cases, you should leave JUCE_COPY_PLUGIN_AFTER_BUILD +disabled, use `add_custom_command(TARGET POST_BUILD)` to add your own post-build steps, and then +finally call `juce_enable_copy_plugin_step`. + +If your custom build steps need to use the location of the plugin artefact, you can extract this +by querying the property `JUCE_PLUGIN_ARTEFACT_FILE` on a plugin target (*not* the shared code +target!). + #### `juce_set__sdk_path` juce_set_aax_sdk_path() diff --git a/extras/Build/CMake/JUCEUtils.cmake b/extras/Build/CMake/JUCEUtils.cmake index 87929c467c..3b1f566a27 100644 --- a/extras/Build/CMake/JUCEUtils.cmake +++ b/extras/Build/CMake/JUCEUtils.cmake @@ -1291,20 +1291,36 @@ function(_juce_copy_dir target from to) VERBATIM) endfunction() -function(_juce_copy_after_build shared_code target from to) - get_target_property(wants_copy ${shared_code} JUCE_COPY_PLUGIN_AFTER_BUILD) +function(_juce_set_copy_properties shared_code target from to_property) + get_target_property(destination "${shared_code}" "${to_property}") - if(wants_copy) - get_target_property(dest ${shared_code} ${to}) - - if(NOT dest) - message(FATAL_ERROR "Target '${target}' wants to be copied, but its property '${to}' is not set") - endif() - - _juce_copy_dir(${target} "${from}" "$>") + if(destination) + set_target_properties("${target}" PROPERTIES JUCE_PLUGIN_COPY_DIR "${destination}") endif() + + set_target_properties("${target}" PROPERTIES JUCE_PLUGIN_ARTEFACT_FILE "${from}") endfunction() +function(juce_enable_copy_plugin_step shared_code_target) + get_target_property(active_targets "${shared_code_target}" JUCE_ACTIVE_PLUGIN_TARGETS) + + foreach(target IN LISTS active_targets) + get_target_property(source "${target}" JUCE_PLUGIN_ARTEFACT_FILE) + + if(source) + get_target_property(dest "${target}" JUCE_PLUGIN_COPY_DIR) + + if(dest) + _juce_copy_dir("${target}" "${source}" "$") + else() + message(WARNING "Target '${target}' requested copy but no destination is set") + endif() + endif() + endforeach() +endfunction() + +# ================================================================================================== + function(_juce_set_plugin_target_properties shared_code_target kind) set(target_name ${shared_code_target}_${kind}) @@ -1336,7 +1352,7 @@ function(_juce_set_plugin_target_properties shared_code_target kind) LIBRARY_OUTPUT_DIRECTORY "${output_path}/Contents/${JUCE_LINUX_TARGET_ARCHITECTURE}-linux") endif() - _juce_copy_after_build(${shared_code_target} ${target_name} "${output_path}" JUCE_VST3_COPY_DIR) + _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 @@ -1351,7 +1367,7 @@ function(_juce_set_plugin_target_properties shared_code_target kind) set(output_path "$") endif() - _juce_copy_after_build(${shared_code_target} ${target_name} "${output_path}" JUCE_VST_COPY_DIR) + _juce_set_copy_properties(${shared_code_target} ${target_name} "${output_path}" JUCE_VST_COPY_DIR) elseif(kind STREQUAL "AU") set_target_properties(${target_name} PROPERTIES BUNDLE_EXTENSION component @@ -1361,7 +1377,7 @@ function(_juce_set_plugin_target_properties shared_code_target kind) XCODE_ATTRIBUTE_GENERATE_PKGINFO_FILE YES) set(output_path "$") - _juce_copy_after_build(${shared_code_target} ${target_name} "${output_path}" JUCE_AU_COPY_DIR) + _juce_set_copy_properties(${shared_code_target} ${target_name} "${output_path}" JUCE_AU_COPY_DIR) elseif(kind STREQUAL "AUv3") set_target_properties(${target_name} PROPERTIES XCODE_PRODUCT_TYPE "com.apple.product-type.app-extension" @@ -1382,7 +1398,7 @@ function(_juce_set_plugin_target_properties shared_code_target kind) _juce_create_windows_package(${shared_code_target} ${target_name} aaxplugin "${default_icon}" Win32 x64) set(output_path "${products_folder}/${product_name}.aaxplugin") - _juce_copy_after_build(${shared_code_target} ${target_name} "${output_path}" JUCE_AAX_COPY_DIR) + _juce_set_copy_properties(${shared_code_target} ${target_name} "${output_path}" JUCE_AAX_COPY_DIR) elseif(kind STREQUAL "Unity") set_target_properties(${target_name} PROPERTIES BUNDLE_EXTENSION bundle @@ -1399,7 +1415,7 @@ function(_juce_set_plugin_target_properties shared_code_target kind) if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(output_path "$") - _juce_copy_after_build(${shared_code_target} ${target_name} "${output_path}" JUCE_UNITY_COPY_DIR) + _juce_set_copy_properties(${shared_code_target} ${target_name} "${output_path}" JUCE_UNITY_COPY_DIR) else() # On windows and linux, the gui script needs to be copied next to the unity output add_custom_command(TARGET ${target_name} POST_BUILD @@ -1407,11 +1423,11 @@ function(_juce_set_plugin_target_properties shared_code_target kind) DEPENDS "${script_file}" VERBATIM) - _juce_copy_after_build(${shared_code_target} + _juce_set_copy_properties(${shared_code_target} ${target_name} "$" JUCE_UNITY_COPY_DIR) - _juce_copy_after_build(${shared_code_target} + _juce_set_copy_properties(${shared_code_target} ${target_name} "${script_file}" JUCE_UNITY_COPY_DIR) @@ -1658,6 +1674,12 @@ function(_juce_configure_plugin_targets target) "$" "$/PlugIns") endif() + + get_target_property(wants_copy "${target}" JUCE_COPY_PLUGIN_AFTER_BUILD) + + if(wants_copy) + juce_enable_copy_plugin_step("${target}") + endif() endfunction() # ==================================================================================================