Skip to content

Commit

Permalink
CMake: Generate moduleinfo.json file during VST3 build
Browse files Browse the repository at this point in the history
  • Loading branch information
reuk committed May 2, 2023
1 parent 89f4657 commit 0032e1e
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 1 deletion.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Expand Up @@ -163,11 +163,18 @@ install(FILES "${JUCE_BINARY_DIR}/JUCEConfigVersion.cmake"
"${JUCE_CMAKE_UTILS_DIR}/juce_LinuxSubprocessHelper.cpp"
DESTINATION "${JUCE_INSTALL_DESTINATION}")

if("${CMAKE_SOURCE_DIR}" STREQUAL "${JUCE_SOURCE_DIR}")
if(("${CMAKE_SOURCE_DIR}" STREQUAL "${JUCE_SOURCE_DIR}") AND (NOT JUCE_BUILD_HELPER_TOOLS))
_juce_add_lv2_manifest_helper_target()

if(TARGET juce_lv2_helper)
install(TARGETS juce_lv2_helper EXPORT LV2_HELPER DESTINATION "bin/JUCE-${JUCE_VERSION}")
install(EXPORT LV2_HELPER NAMESPACE juce:: DESTINATION "${JUCE_INSTALL_DESTINATION}")
endif()

_juce_add_vst3_manifest_helper_target()

if(TARGET juce_vst3_helper)
install(TARGETS juce_vst3_helper EXPORT VST3_HELPER DESTINATION "bin/JUCE-${JUCE_VERSION}")
install(EXPORT VST3_HELPER NAMESPACE juce:: DESTINATION "${JUCE_INSTALL_DESTINATION}")
endif()
endif()
11 changes: 11 additions & 0 deletions docs/CMake API.md
Expand Up @@ -527,6 +527,17 @@ attributes directly to these creation functions, rather than adding them later.
`Pitch Shift`, `Restoration`, `Reverb`, `Sampler`, `Spatial`, `Stereo`, `Surround`, `Synth`,
`Tools`, `Up-Downmix`

`VST3_MANIFEST_ENABLED`
- May be either TRUE or FALSE. Defaults to FALSE. Set this to TRUE if you want a moduleinfo.json
file to be generated as part of the VST3 build. This may improve startup/scanning time for hosts
that understand the contents of this file. This setting is disabled by default because the
moduleinfo.json path can cause problems during code signing on macOS. Bundles containing a
moduleinfo.json may be rejected by code signing verification at any point in the future without
notice per https://developer.apple.com/library/archive/technotes/tn2206. If you enable this
setting, be aware that the code signature for the moduleinfo.json will be stored in its extended
file attributes. Therefore, you will need to ensure that these attributes are not changed or
removed when distributing the VST3.

`AU_MAIN_TYPE`
- Should be one of: `kAudioUnitType_Effect`, `kAudioUnitType_FormatConverter`,
`kAudioUnitType_Generator`, `kAudioUnitType_MIDIProcessor`, `kAudioUnitType_Mixer`,
Expand Down
110 changes: 110 additions & 0 deletions extras/Build/CMake/JUCEUtils.cmake
Expand Up @@ -937,6 +937,70 @@ endfunction()

# ==================================================================================================

function(_juce_add_vst3_manifest_helper_target)
if(TARGET juce_vst3_helper
OR (CMAKE_SYSTEM_NAME STREQUAL "iOS")
OR (CMAKE_SYSTEM_NAME STREQUAL "Android")
OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD"))
return()
endif()

get_target_property(module_path juce::juce_audio_processors INTERFACE_JUCE_MODULE_PATH)
set(vst3_dir "${module_path}/juce_audio_processors/format_types/VST3_SDK")
set(public_dir "${vst3_dir}/public.sdk")
set(public_vst_dir "${public_dir}/source/vst")
set(hosting_dir "${public_vst_dir}/hosting")

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(extra_source "${hosting_dir}/module_mac.mm")
set_source_files_properties("${extra_source}" PROPERTIES COMPILE_FLAGS "-fobjc-arc")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(extra_source "${hosting_dir}/module_linux.cpp")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(extra_source
"${vst3_dir}/helper.manifest"
"${hosting_dir}/module_win32.cpp")
endif()

add_executable(juce_vst3_helper
"${extra_source}"
"${hosting_dir}/module.cpp"
"${public_dir}/samples/vst-utilities/moduleinfotool/source/main.cpp"
"${public_vst_dir}/moduleinfo/moduleinfocreator.cpp"
"${public_vst_dir}/moduleinfo/moduleinfoparser.cpp"
"${public_vst_dir}/utility/stringconvert.cpp"
"${vst3_dir}/pluginterfaces/base/coreiids.cpp")

add_executable(juce::juce_vst3_helper ALIAS juce_vst3_helper)

target_compile_features(juce_vst3_helper PRIVATE cxx_std_17)
target_include_directories(juce_vst3_helper PRIVATE
"${module_path}/juce_audio_processors/format_types/VST3_SDK")

if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
target_compile_options(juce_vst3_helper PRIVATE
"-Wno-expansion-to-defined"
"-Wno-deprecated-declarations")
endif()

if((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") OR (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC"))
target_compile_options(juce_vst3_helper PRIVATE /EHsc /wd6387 /wd6031)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
_juce_link_frameworks(juce_vst3_helper PRIVATE Cocoa)
endif()

set_target_properties(juce_vst3_helper PROPERTIES BUILD_WITH_INSTALL_RPATH ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(juce_vst3_helper PRIVATE Threads::Threads ${CMAKE_DL_LIBS})
endfunction()

# ==================================================================================================

function(_juce_set_plugin_target_properties shared_code_target kind)
set(target_name ${shared_code_target}_${kind})

Expand Down Expand Up @@ -968,6 +1032,7 @@ 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"))
Expand All @@ -976,6 +1041,48 @@ function(_juce_set_plugin_target_properties shared_code_target kind)
LIBRARY_OUTPUT_DIRECTORY "${output_path}/Contents/${JUCE_TARGET_ARCHITECTURE}-linux")
endif()

set(remove_command remove)

if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.17")
set(remove_command rm)
endif()

# Delete moduleinfo.json if it exists, and repair signing so we can still load the bundle
add_custom_command(TARGET ${target_name} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E ${remove_command} -f "${output_path}/Contents/moduleinfo.json"
COMMAND "${CMAKE_COMMAND}"
"-Dsrc=${output_path}"
"-P" "${JUCE_CMAKE_UTILS_DIR}/checkBundleSigning.cmake"
VERBATIM)

get_target_property(manifest_enabled ${shared_code_target} JUCE_VST3_MANIFEST_ENABLED)

if("${manifest_enabled}")
# 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 juce_vst3_helper
-create
-version "${target_version_string}"
-path "${output_path}"
-output "${output_path}/Contents/moduleinfo.json"
VERBATIM)

# Sign the moduleinfo.json then the full bundle from the inside out
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_custom_command(TARGET ${target_name} POST_BUILD
COMMAND xcrun codesign -f -s "-" "${output_path}/Contents/moduleinfo.json"
COMMAND "${CMAKE_COMMAND}"
"-Dsrc=${output_path}"
"-P" "${JUCE_CMAKE_UTILS_DIR}/checkBundleSigning.cmake"
VERBATIM)
endif()
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
Expand Down Expand Up @@ -1442,6 +1549,8 @@ function(_juce_set_fallback_properties target)
_juce_set_property_if_not_set(${target} VST_NUM_MIDI_INS 16)
_juce_set_property_if_not_set(${target} VST_NUM_MIDI_OUTS 16)

_juce_set_property_if_not_set(${target} VST3_MANIFEST_ENABLED FALSE)

_juce_set_property_if_not_set(${target} AU_SANDBOX_SAFE FALSE)

_juce_set_property_if_not_set(${target} SUPPRESS_AU_PLIST_RESOURCE_USAGE FALSE)
Expand Down Expand Up @@ -1729,6 +1838,7 @@ function(_juce_initialise_target target)
IS_ARA_EFFECT
ARA_FACTORY_ID
ARA_DOCUMENT_ARCHIVE_ID
VST3_MANIFEST_ENABLED

VST_COPY_DIR
VST3_COPY_DIR
Expand Down

0 comments on commit 0032e1e

Please sign in to comment.