Skip to content

Commit

Permalink
If MACOSX_EMBEDDED is there, use it for plist (#317)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
baconpaul authored Oct 11, 2024
1 parent cdaf7ac commit e6a09e9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
19 changes: 17 additions & 2 deletions cmake/shared_prologue.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_PROPERTY:${MBC_TARGET},LIBRARY_OUTPUT_DIRECTORY>
COMMAND ${CMAKE_COMMAND} -E echo "Installing ${MBC_MACOS_EMBEDDED_CLAP_LOCATION} in $<TARGET_PROPERTY:${MBC_TARGET},MACOSX_BUNDLE_BUNDLE_NAME>.$<TARGET_PROPERTY:${MBC_TARGET},BUNDLE_EXTENSION>/Contents/PlugIns/$<TARGET_PROPERTY:${MBC_TARGET},MACOSX_BUNDLE_BUNDLE_NAME>.clap"
Expand Down
32 changes: 31 additions & 1 deletion cmake/wrap_auv2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -90,6 +104,22 @@ function(target_add_auv2_wrapper)
"$<TARGET_FILE:${clpt}>" "${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 "$<TARGET_FILE:${bhtg}>"
COMMAND $<TARGET_FILE:${bhtg}> --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")
Expand Down Expand Up @@ -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})
Expand Down
14 changes: 11 additions & 3 deletions src/detail/auv2/build-helper/build-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit e6a09e9

Please sign in to comment.