From 9e193862c1956a43054c2f202be95d6ef27d515f Mon Sep 17 00:00:00 2001 From: Tom Poole Date: Fri, 18 Oct 2024 16:54:07 +0100 Subject: [PATCH] CMake: Improve Windows Arm architecture detection --- docs/CMake API.md | 4 +- extras/Build/CMake/JUCEModuleSupport.cmake | 21 +++++- extras/Build/CMake/JUCEUtils.cmake | 68 ++++++++++++++----- .../CMake/juce_runtime_arch_detection.cpp | 29 ++++---- .../Projucer/JuceLibraryCode/BinaryData.cpp | 35 +++++----- extras/Projucer/JuceLibraryCode/BinaryData.h | 2 +- 6 files changed, 103 insertions(+), 56 deletions(-) diff --git a/docs/CMake API.md b/docs/CMake API.md index bdd70addd0..36146ef81f 100644 --- a/docs/CMake API.md +++ b/docs/CMake API.md @@ -799,8 +799,8 @@ CMakeLists in the `modules` directory. This function parses the PIP metadata block in the provided header, and adds appropriate build targets for a console app, GUI app, or audio plugin. For audio plugin targets, it builds as many -plugin formats as possible. To build AAX or VST2 targets, call `juce_set_aax_sdk_path` and/or -`juce_set_vst2_sdk_path` *before* calling `juce_add_pip`. +plugin formats as possible. To build VST2 targets, call `juce_set_vst2_sdk_path` *before* calling +`juce_add_pip`. This is mainly provided to build the built-in example projects in the JUCE repo, and for building quick proof-of-concept demo apps with minimal set-up. For any use-case more complex than a diff --git a/extras/Build/CMake/JUCEModuleSupport.cmake b/extras/Build/CMake/JUCEModuleSupport.cmake index cac20db129..349d7ab9b2 100644 --- a/extras/Build/CMake/JUCEModuleSupport.cmake +++ b/extras/Build/CMake/JUCEModuleSupport.cmake @@ -62,7 +62,11 @@ function(_juce_find_target_architecture result) set("${result}" "${match_result}" PARENT_SCOPE) endfunction() -if((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD") OR MSYS OR MINGW) +if((CMAKE_SYSTEM_NAME STREQUAL "Windows") + OR (CMAKE_SYSTEM_NAME STREQUAL "Linux") + OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD") + OR MSYS + OR MINGW) # If you really need to override the detected arch for some reason, # you can configure the build with -DJUCE_TARGET_ARCHITECTURE= if(NOT DEFINED JUCE_TARGET_ARCHITECTURE) @@ -70,6 +74,17 @@ if((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD") O set(JUCE_TARGET_ARCHITECTURE "${target_arch}" CACHE INTERNAL "The target architecture, used to name internal folders in VST3 bundles, and to locate bundled libraries in modules") endif() + + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + if ((CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "X86" AND NOT JUCE_TARGET_ARCHITECTURE STREQUAL "i386") + OR (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64" + AND NOT (JUCE_TARGET_ARCHITECTURE STREQUAL "i386" + OR JUCE_TARGET_ARCHITECTURE STREQUAL "x86_64"))) + set(JUCE_WINDOWS_HELPERS_CAN_RUN FALSE) + else() + set(JUCE_WINDOWS_HELPERS_CAN_RUN TRUE) + endif() + endif() endif() # ================================================================================================== @@ -270,7 +285,9 @@ function(_juce_get_platform_plugin_kinds out) endif() endif() - if((CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "Windows") AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")) + if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + AND (CMAKE_SYSTEM_NAME STREQUAL "Darwin" + OR (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND JUCE_TARGET_ARCHITECTURE STREQUAL "x86_64"))) list(APPEND result AAX) endif() diff --git a/extras/Build/CMake/JUCEUtils.cmake b/extras/Build/CMake/JUCEUtils.cmake index 9f0614e9be..ef8ebd7266 100644 --- a/extras/Build/CMake/JUCEUtils.cmake +++ b/extras/Build/CMake/JUCEUtils.cmake @@ -851,19 +851,12 @@ endfunction() # ================================================================================================== -function(_juce_create_windows_package source_target dest_target extension default_icon x32folder x64folder) - if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") - return() - endif() - +function(_juce_create_windows_package source_target dest_target extension default_icon arch_string) get_target_property(products_folder ${dest_target} LIBRARY_OUTPUT_DIRECTORY) set(product_name $) set(output_folder "${products_folder}/${product_name}.${extension}") - set(is_x64 $) - set(arch_string $) - set_target_properties(${dest_target} PROPERTIES PDB_OUTPUT_DIRECTORY "${products_folder}" @@ -1090,6 +1083,13 @@ function(juce_enable_vst3_manifest_step shared_code_target) return() endif() + if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND NOT JUCE_WINDOWS_HELPERS_CAN_RUN) + message(WARNING "VST3 manifest generation is disabled for ${shared_code_target} because a " + "${JUCE_TARGET_ARCHITECTURE} manifest helper cannot run on a host system processor detected to be " + "${CMAKE_HOST_SYSTEM_PROCESSOR}.") + return() + endif() + set(target_name ${shared_code_target}_VST3) get_target_property(product ${target_name} JUCE_PLUGIN_ARTEFACT_FILE) @@ -1102,14 +1102,17 @@ function(juce_enable_vst3_manifest_step shared_code_target) get_target_property(target_version_string ${shared_code_target} JUCE_VERSION) + set(ouput_path "${product}/Contents/Resources/moduleinfo.json") + # Use the helper tool to write out the moduleinfo.json add_custom_command(TARGET ${target_name} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "creating ${ouput_path}" 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" + -output "${ouput_path}" VERBATIM) set_target_properties(${shared_code_target} PROPERTIES _JUCE_VST3_MANIFEST_STEP_ADDED TRUE) @@ -1194,7 +1197,21 @@ function(_juce_set_plugin_target_properties shared_code_target kind) XCODE_ATTRIBUTE_LIBRARY_STYLE Bundle XCODE_ATTRIBUTE_GENERATE_PKGINFO_FILE YES) - _juce_create_windows_package(${shared_code_target} ${target_name} vst3 "" x86-win x86_64-win) + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + if(JUCE_TARGET_ARCHITECTURE STREQUAL "x86_64") + set(windows_arch "x86_64") + elseif(JUCE_TARGET_ARCHITECTURE STREQUAL "i386") + set(windows_arch "x86") + elseif(JUCE_TARGET_ARCHITECTURE STREQUAL "arm64ec") + set(windows_arch "arm64ec") + elseif(JUCE_TARGET_ARCHITECTURE STREQUAL "aarch64") + set(windows_arch "arm64") + else() + message(FATAL_ERROR "Unsupported target architecture for VST3: ${JUCE_TARGET_ARCHITECTURE}") + endif() + + _juce_create_windows_package(${shared_code_target} ${target_name} vst3 "" "${windows_arch}-win") + endif() set(output_path "${products_folder}/${product_name}.vst3") @@ -1262,7 +1279,18 @@ function(_juce_set_plugin_target_properties shared_code_target kind) _juce_init_bundled_aax_sdk() get_target_property(default_icon juce_aax_sdk INTERFACE_JUCE_AAX_DEFAULT_ICON) - _juce_create_windows_package(${shared_code_target} ${target_name} aaxplugin "${default_icon}" Win32 x64) + + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + if(JUCE_TARGET_ARCHITECTURE STREQUAL "x86_64") + set(windows_arch "x64") + elseif(JUCE_TARGET_ARCHITECTURE STREQUAL "i386") + set(windows_arch "Win32") + else() + message(FATAL_ERROR "Unsupported target architecture for AAX: ${JUCE_TARGET_ARCHITECTURE}") + endif() + + _juce_create_windows_package(${shared_code_target} ${target_name} aaxplugin "${default_icon}" "${windows_arch}") + endif() set(output_path "${products_folder}/${product_name}.aaxplugin") _juce_set_copy_properties(${shared_code_target} ${target_name} "${output_path}" JUCE_AAX_COPY_DIR) @@ -1300,6 +1328,11 @@ function(_juce_set_plugin_target_properties shared_code_target kind) JUCE_UNITY_COPY_DIR) endif() elseif(kind STREQUAL "LV2") + if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND NOT JUCE_WINDOWS_HELPERS_CAN_RUN) + message(FATAL_ERROR "You cannot build a ${JUCE_TARGET_ARCHITECTURE} LV2 plug-in on a host " + "system processor detected to be ${CMAKE_HOST_SYSTEM_PROCESSOR}.") + endif() + set_target_properties(${target_name} PROPERTIES BUNDLE FALSE) get_target_property(JUCE_LV2URI "${shared_code_target}" JUCE_LV2URI) @@ -2251,23 +2284,22 @@ function(juce_add_pip header) else() set(source_main "${JUCE_CMAKE_UTILS_DIR}/PIPAudioProcessor.cpp.in") + set(formats AAX AU AUv3 LV2 Standalone Unity VST3) + # We add VST2 targets too, if the user has set up those SDKs - - set(extra_formats) - if(TARGET juce_vst2_sdk) - list(APPEND extra_formats VST) + list(APPEND formats VST) endif() - if(NOT (CMAKE_SYSTEM_NAME MATCHES ".*BSD")) - list(APPEND extra_formats VST3) + if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND NOT JUCE_WINDOWS_HELPERS_CAN_RUN) + list(REMOVE_ITEM formats LV2) endif() # Standalone plugins might want to access the mic list(APPEND extra_target_args MICROPHONE_PERMISSION_ENABLED TRUE) juce_add_plugin(${JUCE_PIP_NAME} - FORMATS AU AUv3 LV2 Standalone Unity AAX ${extra_formats} + FORMATS ${formats} ${extra_target_args}) endif() elseif(pip_kind STREQUAL "Component") diff --git a/extras/Build/CMake/juce_runtime_arch_detection.cpp b/extras/Build/CMake/juce_runtime_arch_detection.cpp index 09b4289350..32eb04d6c4 100644 --- a/extras/Build/CMake/juce_runtime_arch_detection.cpp +++ b/extras/Build/CMake/juce_runtime_arch_detection.cpp @@ -32,21 +32,20 @@ ============================================================================== */ -#if defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM) || defined(_M_ARM64) || defined(__aarch64__) || defined(__ARM64__) - - #if defined(_M_ARM64) || defined(__aarch64__) || defined(__ARM64__) - #error JUCE_ARCH aarch64 - #elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 8) || defined(__ARMv8__) || defined(__ARMv8_A__) - #error JUCE_ARCH armv8l - #elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 7) || defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) || defined(_ARM_ARCH_7) || defined(__CORE_CORTEXA__) - #error JUCE_ARCH armv7l - #elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 6) || defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6T2__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6M__) - #error JUCE_ARCH armv6l - #elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 5) || defined(__ARM_ARCH_5TEJ__) - #error JUCE_ARCH armv5l - #else - #error JUCE_ARCH arm - #endif +#if defined(_M_ARM64EC) + #error JUCE_ARCH arm64ec +#elif defined(_M_ARM64) || defined(__aarch64__) || defined(__ARM64__) + #error JUCE_ARCH aarch64 +#elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 8) || defined(__ARMv8__) || defined(__ARMv8_A__) + #error JUCE_ARCH armv8l +#elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 7) || defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) || defined(_ARM_ARCH_7) || defined(__CORE_CORTEXA__) + #error JUCE_ARCH armv7l +#elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 6) || defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6T2__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6M__) + #error JUCE_ARCH armv6l +#elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 5) || defined(__ARM_ARCH_5TEJ__) + #error JUCE_ARCH armv5l +#elif defined(__arm__) || defined(_M_ARM) + #error JUCE_ARCH arm #elif defined(__i386) || defined(__i386__) || defined(_M_IX86) diff --git a/extras/Projucer/JuceLibraryCode/BinaryData.cpp b/extras/Projucer/JuceLibraryCode/BinaryData.cpp index 85dd275a28..5e57dde1b8 100644 --- a/extras/Projucer/JuceLibraryCode/BinaryData.cpp +++ b/extras/Projucer/JuceLibraryCode/BinaryData.cpp @@ -8466,23 +8466,22 @@ static const unsigned char temp_binary_data_66[] = " ==============================================================================\r\n" "*/\r\n" "\r\n" -"#if defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM) || defined(_M_ARM64) || defined(__aarch64__) || defined(__ARM64__)\r\n" -"\r\n" -" #if defined(_M_ARM64) || defined(__aarch64__) || defined(__ARM64__)\r\n" -" #error JUCE_ARCH aarch64\r\n" -" #elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 8) || defined(__ARMv8__) || defined(__ARMv8_A__)\r\n" -" #error JUCE_ARCH armv8l\r\n" -" #elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 7) || defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) || defined(_ARM_ARCH_7) || defined(__CORE_CORTEX" -"A__)\r\n" -" #error JUCE_ARCH armv7l\r\n" -" #elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 6) || defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6T2__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_A" -"RCH_6M__)\r\n" -" #error JUCE_ARCH armv6l\r\n" -" #elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 5) || defined(__ARM_ARCH_5TEJ__)\r\n" -" #error JUCE_ARCH armv5l\r\n" -" #else\r\n" -" #error JUCE_ARCH arm\r\n" -" #endif\r\n" +"#if defined(_M_ARM64EC)\r\n" +" #error JUCE_ARCH arm64ec\r\n" +"#elif defined(_M_ARM64) || defined(__aarch64__) || defined(__ARM64__)\r\n" +" #error JUCE_ARCH aarch64\r\n" +"#elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 8) || defined(__ARMv8__) || defined(__ARMv8_A__)\r\n" +" #error JUCE_ARCH armv8l\r\n" +"#elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 7) || defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) || defined(_ARM_ARCH_7) || defined(__CORE_CORTEXA_" +"_)\r\n" +" #error JUCE_ARCH armv7l\r\n" +"#elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 6) || defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6T2__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARC" +"H_6M__)\r\n" +" #error JUCE_ARCH armv6l\r\n" +"#elif (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM == 5) || defined(__ARM_ARCH_5TEJ__)\r\n" +" #error JUCE_ARCH armv5l\r\n" +"#elif defined(__arm__) || defined(_M_ARM)\r\n" +" #error JUCE_ARCH arm\r\n" "\r\n" "#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)\r\n" "\r\n" @@ -9051,7 +9050,7 @@ const char* getNamedResource (const char* resourceNameUTF8, int& numBytes) case 0x0b16e320: numBytes = 517; return jucer_PIPTemplate_h; case 0x763d39dc: numBytes = 1050; return colourscheme_dark_xml; case 0xe8b08520: numBytes = 1050; return colourscheme_light_xml; - case 0x7c03d519: numBytes = 3658; return juce_runtime_arch_detection_cpp; + case 0x7c03d519: numBytes = 3575; return juce_runtime_arch_detection_cpp; case 0x295b6f43: numBytes = 1865; return juce_LinuxSubprocessHelper_cpp; case 0xef269d3a: numBytes = 12997; return juce_SimpleBinaryBuilder_cpp; default: break; diff --git a/extras/Projucer/JuceLibraryCode/BinaryData.h b/extras/Projucer/JuceLibraryCode/BinaryData.h index 41e185b02e..ccb8811769 100644 --- a/extras/Projucer/JuceLibraryCode/BinaryData.h +++ b/extras/Projucer/JuceLibraryCode/BinaryData.h @@ -207,7 +207,7 @@ namespace BinaryData const int colourscheme_light_xmlSize = 1050; extern const char* juce_runtime_arch_detection_cpp; - const int juce_runtime_arch_detection_cppSize = 3658; + const int juce_runtime_arch_detection_cppSize = 3575; extern const char* juce_LinuxSubprocessHelper_cpp; const int juce_LinuxSubprocessHelper_cppSize = 1865;