From e6a09e9d8bc118c783252e6860c454867552a4a9 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 10 Oct 2024 20:50:38 -0400 Subject: [PATCH] If MACOSX_EMBEDDED is there, use it for plist (#317) * If MACOSX_EMBEDDED is there, use it for plist MACOSX_EMBEDDED_ allows you to embed a clap as a subordinate framework of your wrapped component, but we didn't use that handed in clap to generate the Plist. Fix that by using it if available. Also make both macOS and macOSx work as names, since the latter is the cmake standard elsewhere --- cmake/shared_prologue.cmake | 19 +++++++++-- cmake/wrap_auv2.cmake | 32 ++++++++++++++++++- src/detail/auv2/build-helper/build-helper.cpp | 14 ++++++-- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/cmake/shared_prologue.cmake b/cmake/shared_prologue.cmake index a8c4de3b..03b22a39 100644 --- a/cmake/shared_prologue.cmake +++ b/cmake/shared_prologue.cmake @@ -190,16 +190,31 @@ endfunction(macos_bundle_flag) # location optionally. Called by the target_add_xyz_wrapper functions to allow self contained # non relinked macos bundles function(macos_include_clap_in_bundle) - set(oneValueArgs TARGET MACOS_EMBEDDED_CLAP_LOCATION) + set(oneValueArgs + TARGET + MACOS_EMBEDDED_CLAP_LOCATION + MACOSX_EMBEDDED_CLAP_LOCATION + ) + cmake_parse_arguments(MBC "" "${oneValueArgs}" "" ${ARGN}) + if (NOT DEFINED MBC_MACOS_EMBEDDED_CLAP_LOCATION AND DEFINED MBC_MACOSX_EMBEDDED_CLAP_LOCATION) + # resolve the alias + set(MBC_MACOS_EMBEDDED_CLAP_LOCATION ${MBC_MACOSX_EMBEDDED_CLAP_LOCATION}) + endif() + + if (NOT DEFINED MBC_MACOSX_EMBEDDED_CLAP_LOCATION AND DEFINED MBC_MACOS_EMBEDDED_CLAP_LOCATION) + # resolve the alias + set(MBC_MACOSX_EMBEDDED_CLAP_LOCATION ${MBC_MACOS_EMBEDDED_CLAP_LOCATION}) + endif() + if (NOT APPLE) message(WARNING "Calling macos_include_clap_in_bundle on non APPLE system. Is this intentional?") return() endif() if (NOT ${MBC_MACOS_EMBEDDED_CLAP_LOCATION} STREQUAL "") - message(STATUS "clap-wraiier: including embedded clap in target ${MBC_TARGET}") + message(STATUS "clap-wrapper: including embedded clap in target ${MBC_TARGET}") add_custom_command(TARGET ${MBC_TARGET} PRE_BUILD WORKING_DIRECTORY $ COMMAND ${CMAKE_COMMAND} -E echo "Installing ${MBC_MACOS_EMBEDDED_CLAP_LOCATION} in $.$/Contents/PlugIns/$.clap" diff --git a/cmake/wrap_auv2.cmake b/cmake/wrap_auv2.cmake index 70b64855..0f6f7c2a 100644 --- a/cmake/wrap_auv2.cmake +++ b/cmake/wrap_auv2.cmake @@ -24,10 +24,24 @@ function(target_add_auv2_wrapper) # - JUCE (use the JUCE AUV2 default) DICTIONARY_STREAM_FORMAT + # These two are aliases of each other but the one without the X + # came first and doesn't match the rest of CMake naming standards MACOS_EMBEDDED_CLAP_LOCATION + MACOSX_EMBEDDED_CLAP_LOCATION ) cmake_parse_arguments(AUV2 "" "${oneValueArgs}" "" ${ARGN}) + + if (NOT DEFINED AUV2_MACOS_EMBEDDED_CLAP_LOCATION AND DEFINED AUV2_MACOSX_EMBEDDED_CLAP_LOCATION) + # resolve the alias + set(AUV2_MACOS_EMBEDDED_CLAP_LOCATION ${AUV2_MACOSX_EMBEDDED_CLAP_LOCATION}) + endif() + + if (NOT DEFINED AUV2_MACOSX_EMBEDDED_CLAP_LOCATION AND DEFINED AUV2_MACOS_EMBEDDED_CLAP_LOCATION) + # resolve the alias + set(AUV2_MACOSX_EMBEDDED_CLAP_LOCATION ${AUV2_MACOS_EMBEDDED_CLAP_LOCATION}) + endif() + if (NOT APPLE) message(STATUS "clap-wrapper: auv2 is only available on macOS") return() @@ -90,6 +104,22 @@ function(target_add_auv2_wrapper) "$" "${AUV2_BUNDLE_VERSION}" "${AUV2_MANUFACTURER_CODE}" "${AUV2_MANUFACTURER_NAME}" ) + elseif (DEFINED AUV2_MACOSX_EMBEDDED_CLAP_LOCATION) + message(STATUS "clap-wrapper: building auv2 based on clap ${AUV2_MACOSX_EMBEDDED_CLAP_LOCATION}") + set(AUV2_SUBTYPE_CODE "----") + set(AUV2_INSTRUMENT_TYPE "aumu") + + add_custom_command( + TARGET ${bhtg} + POST_BUILD + WORKING_DIRECTORY ${bhtgoutdir} + BYPRODUCTS ${bhtgoutdir}/auv2_Info.plist ${bhtgoutdir}/generated_entrypoints.hxx + COMMAND codesign -s - -f "$" + COMMAND $ --fromclap + "${AUV2_OUTPUT_NAME}" + "${AUV2_MACOSX_EMBEDDED_CLAP_LOCATION}" "${AUV2_BUNDLE_VERSION}" + "${AUV2_MANUFACTURER_CODE}" "${AUV2_MANUFACTURER_NAME}" + ) else () if (NOT DEFINED AUV2_OUTPUT_NAME) message(FATAL_ERROR "clap-wrapper: target_add_auv2_wrapper requires an output name") @@ -215,7 +245,7 @@ function(target_add_auv2_wrapper) set_target_properties(${AUV2_TARGET} PROPERTIES XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "${AUV2_BUNDLE_IDENTIFIER}.component") macos_include_clap_in_bundle(TARGET ${AUV2_TARGET} - MACOS_EMBEDDED_CLAP_LOCATION ${AUV2_MACOS_EMBEDDED_CLAP_LOCATION}) + MACOS_EMBEDDED_CLAP_LOCATION ${AUV2_MACOSX_EMBEDDED_CLAP_LOCATION}) macos_bundle_flag(TARGET ${AUV2_TARGET}) if (${CLAP_WRAPPER_COPY_AFTER_BUILD}) diff --git a/src/detail/auv2/build-helper/build-helper.cpp b/src/detail/auv2/build-helper/build-helper.cpp index 9b99e7db..b623a00d 100644 --- a/src/detail/auv2/build-helper/build-helper.cpp +++ b/src/detail/auv2/build-helper/build-helper.cpp @@ -236,9 +236,17 @@ int main(int argc, char **argv) try { auto p = fs::path{clapfile}; - // This is a hack for now - we get to the dll - p = p.parent_path().parent_path().parent_path(); - clapfile = p.u8string(); + if (fs::is_directory(p)) + { + std::cout << " - CLAP is a directory. Assuming bundle\n"; + } + else + { + // This is a hack for now - we get to the dll + std::cout << " - CLAP is a regular file. Assuming dll in bundle\n"; + p = p.parent_path().parent_path().parent_path(); + clapfile = p.u8string(); + } } catch (const fs::filesystem_error &e) {