The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2078 lines
85KB

  1. # ==============================================================================
  2. #
  3. # This file is part of the JUCE library.
  4. # Copyright (c) 2022 - Raw Material Software Limited
  5. #
  6. # JUCE is an open source library subject to commercial or open-source
  7. # licensing.
  8. #
  9. # By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  10. # Agreement and JUCE Privacy Policy.
  11. #
  12. # End User License Agreement: www.juce.com/juce-7-licence
  13. # Privacy Policy: www.juce.com/juce-privacy-policy
  14. #
  15. # Or: You may also use this code under the terms of the GPL v3 (see
  16. # www.gnu.org/licenses).
  17. #
  18. # JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  19. # EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  20. # DISCLAIMED.
  21. #
  22. # ==============================================================================
  23. # ==================================================================================================
  24. # JUCE Target Support Helper Functions
  25. #
  26. # In this file, functions intended for use by end-users have the prefix `juce_`.
  27. # Functions beginning with an underscore should be considered private and susceptible to
  28. # change, so don't call them directly.
  29. #
  30. # See the readme at `docs/CMake API.md` for more information about CMake usage,
  31. # including documentation of the public functions in this file.
  32. # ==================================================================================================
  33. include_guard(GLOBAL)
  34. cmake_minimum_required(VERSION 3.15)
  35. define_property(TARGET PROPERTY JUCE_COMPANY_NAME INHERITED
  36. BRIEF_DOCS "The company name for a particular target"
  37. FULL_DOCS "This can be found in ProjectInfo::companyName in a generated JuceHeader.h")
  38. set_property(GLOBAL PROPERTY JUCE_COMPANY_NAME "yourcompany")
  39. define_property(TARGET PROPERTY JUCE_COMPANY_WEBSITE INHERITED
  40. BRIEF_DOCS "The company website for a particular target"
  41. FULL_DOCS "This will be placed in the Info.plist for the target")
  42. set_property(GLOBAL PROPERTY JUCE_COMPANY_WEBSITE "")
  43. define_property(TARGET PROPERTY JUCE_COMPANY_EMAIL INHERITED
  44. BRIEF_DOCS "The company email address for a particular target"
  45. FULL_DOCS "This will be placed in the Info.plist for the target")
  46. set_property(GLOBAL PROPERTY JUCE_COMPANY_EMAIL "")
  47. define_property(TARGET PROPERTY JUCE_COMPANY_COPYRIGHT INHERITED
  48. BRIEF_DOCS "The company copyright for a particular target"
  49. FULL_DOCS "This will be placed in the Info.plist for the target")
  50. set_property(GLOBAL PROPERTY JUCE_COMPANY_COPYRIGHT "")
  51. define_property(TARGET PROPERTY JUCE_VST_COPY_DIR INHERITED
  52. BRIEF_DOCS "Install location for VST2 plugins"
  53. FULL_DOCS "This is where the plugin will be copied if plugin copying is enabled")
  54. define_property(TARGET PROPERTY JUCE_VST3_COPY_DIR INHERITED
  55. BRIEF_DOCS "Install location for VST3 plugins"
  56. FULL_DOCS "This is where the plugin will be copied if plugin copying is enabled")
  57. define_property(TARGET PROPERTY JUCE_AU_COPY_DIR INHERITED
  58. BRIEF_DOCS "Install location for AU plugins"
  59. FULL_DOCS "This is where the plugin will be copied if plugin copying is enabled")
  60. define_property(TARGET PROPERTY JUCE_AAX_COPY_DIR INHERITED
  61. BRIEF_DOCS "Install location for AAX plugins"
  62. FULL_DOCS "This is where the plugin will be copied if plugin copying is enabled")
  63. define_property(TARGET PROPERTY JUCE_UNITY_COPY_DIR INHERITED
  64. BRIEF_DOCS "Install location for Unity plugins"
  65. FULL_DOCS "This is where the plugin will be copied if plugin copying is enabled")
  66. define_property(TARGET PROPERTY JUCE_LV2_COPY_DIR INHERITED
  67. BRIEF_DOCS "Install location for LV2 plugins"
  68. FULL_DOCS "This is where the plugin will be copied if plugin copying is enabled")
  69. define_property(TARGET PROPERTY JUCE_COPY_PLUGIN_AFTER_BUILD INHERITED
  70. BRIEF_DOCS "Whether or not plugins should be copied after building"
  71. FULL_DOCS "Whether or not plugins should be copied after building")
  72. set_property(GLOBAL PROPERTY JUCE_COPY_PLUGIN_AFTER_BUILD FALSE)
  73. if((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD"))
  74. _juce_create_pkgconfig_target(JUCE_CURL_LINUX_DEPS libcurl)
  75. _juce_create_pkgconfig_target(JUCE_BROWSER_LINUX_DEPS webkit2gtk-4.0 gtk+-x11-3.0)
  76. endif()
  77. # We set up default/fallback copy dirs here. If you need different copy dirs, use
  78. # set_directory_properties or set_target_properties to adjust the values of `JUCE_*_COPY_DIR` at
  79. # the appropriate scope.
  80. function(_juce_set_default_properties)
  81. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  82. set_property(GLOBAL PROPERTY JUCE_LV2_COPY_DIR "$ENV{HOME}/Library/Audio/Plug-Ins/LV2")
  83. set_property(GLOBAL PROPERTY JUCE_VST_COPY_DIR "$ENV{HOME}/Library/Audio/Plug-Ins/VST")
  84. set_property(GLOBAL PROPERTY JUCE_VST3_COPY_DIR "$ENV{HOME}/Library/Audio/Plug-Ins/VST3")
  85. set_property(GLOBAL PROPERTY JUCE_AU_COPY_DIR "$ENV{HOME}/Library/Audio/Plug-Ins/Components")
  86. set_property(GLOBAL PROPERTY JUCE_UNITY_COPY_DIR "$ENV{HOME}/Library/Audio/Plug-Ins/Unity")
  87. set_property(GLOBAL PROPERTY JUCE_AAX_COPY_DIR "/Library/Application Support/Avid/Audio/Plug-Ins")
  88. elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  89. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  90. set_property(GLOBAL PROPERTY JUCE_VST_COPY_DIR "$ENV{ProgramW6432}/Steinberg/Vstplugins")
  91. set(prefix "$ENV{CommonProgramW6432}")
  92. else()
  93. set_property(GLOBAL PROPERTY JUCE_VST_COPY_DIR "$ENV{programfiles\(x86\)}/Steinberg/Vstplugins")
  94. set(prefix "$ENV{CommonProgramFiles\(x86\)}")
  95. endif()
  96. set_property(GLOBAL PROPERTY JUCE_VST3_COPY_DIR "${prefix}/VST3")
  97. set_property(GLOBAL PROPERTY JUCE_AAX_COPY_DIR "${prefix}/Avid/Audio/Plug-Ins")
  98. set_property(GLOBAL PROPERTY JUCE_LV2_COPY_DIR "$ENV{APPDATA}/LV2")
  99. set_property(GLOBAL PROPERTY JUCE_UNITY_COPY_DIR "$ENV{APPDATA}/Unity")
  100. elseif((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD"))
  101. set_property(GLOBAL PROPERTY JUCE_LV2_COPY_DIR "$ENV{HOME}/.lv2")
  102. set_property(GLOBAL PROPERTY JUCE_VST_COPY_DIR "$ENV{HOME}/.vst")
  103. set_property(GLOBAL PROPERTY JUCE_VST3_COPY_DIR "$ENV{HOME}/.vst3")
  104. set_property(GLOBAL PROPERTY JUCE_UNITY_COPY_DIR "$ENV{HOME}/.unity")
  105. endif()
  106. endfunction()
  107. _juce_set_default_properties()
  108. # ==================================================================================================
  109. function(juce_add_bundle_resources_directory target folder)
  110. _juce_make_absolute(folder)
  111. if(NOT EXISTS "${folder}")
  112. message(FATAL_ERROR "Could not find resource folder ${folder}")
  113. endif()
  114. get_filename_component(folder_parent_path "${folder}" DIRECTORY)
  115. file(GLOB_RECURSE resources RELATIVE "${folder_parent_path}" "${folder}/*")
  116. foreach(file IN LISTS resources)
  117. target_sources(${target} PRIVATE "${folder_parent_path}/${file}")
  118. get_filename_component(resource_parent_path "${file}" DIRECTORY)
  119. set_source_files_properties("${folder_parent_path}/${file}" PROPERTIES
  120. HEADER_FILE_ONLY TRUE
  121. MACOSX_PACKAGE_LOCATION "Resources/${resource_parent_path}")
  122. endforeach()
  123. endfunction()
  124. # ==================================================================================================
  125. # Ideally, we'd check the preprocessor defs on the target to see whether
  126. # JUCE_USE_CURL, JUCE_WEB_BROWSER, or JUCE_IN_APP_PURCHASES have been explicitly turned off,
  127. # and then link libraries as appropriate.
  128. # Unfortunately, this doesn't work, because linking a new library (curl/webkit/StoreKit)
  129. # updates the target's compile defs, which results in a recursion/circular-dependency.
  130. # Instead, we ask the user to explicitly request curl/webkit/StoreKit linking if they
  131. # know they need it. Otherwise, we won't link anything.
  132. # See the NEEDS_CURL, NEEDS_WEB_BROWSER, and NEEDS_STORE_KIT options in the CMake/readme.md.
  133. function(_juce_link_optional_libraries target)
  134. if((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD"))
  135. get_target_property(needs_curl ${target} JUCE_NEEDS_CURL)
  136. if(needs_curl)
  137. target_link_libraries(${target} PRIVATE juce::pkgconfig_JUCE_CURL_LINUX_DEPS)
  138. endif()
  139. get_target_property(needs_browser ${target} JUCE_NEEDS_WEB_BROWSER)
  140. if(needs_browser)
  141. target_link_libraries(${target} PRIVATE juce::pkgconfig_JUCE_BROWSER_LINUX_DEPS)
  142. endif()
  143. elseif(APPLE)
  144. get_target_property(needs_storekit ${target} JUCE_NEEDS_STORE_KIT)
  145. if(needs_storekit)
  146. _juce_link_frameworks("${target}" PRIVATE StoreKit)
  147. endif()
  148. get_target_property(needs_camera ${target} JUCE_CAMERA_PERMISSION_ENABLED)
  149. if(CMAKE_SYSTEM_NAME STREQUAL "iOS" AND needs_camera)
  150. _juce_link_frameworks("${target}" PRIVATE ImageIO)
  151. endif()
  152. endif()
  153. endfunction()
  154. # ==================================================================================================
  155. function(_juce_get_module_definitions target filter out_var)
  156. set(compile_defs $<TARGET_GENEX_EVAL:${target},$<TARGET_PROPERTY:${target},COMPILE_DEFINITIONS>>)
  157. if(filter)
  158. set(${out_var} $<FILTER:${compile_defs},EXCLUDE,JucePlugin_Build_|JUCE_SHARED_CODE> PARENT_SCOPE)
  159. else()
  160. set(${out_var} ${compile_defs} PARENT_SCOPE)
  161. endif()
  162. endfunction()
  163. function(_juce_append_record output key)
  164. string(ASCII 30 RS)
  165. string(ASCII 31 US)
  166. set(${output} "${${output}}${key}${US}${ARGN}${RS}" PARENT_SCOPE)
  167. endfunction()
  168. function(_juce_append_target_property output key target property)
  169. get_target_property(prop ${target} ${property})
  170. if(prop STREQUAL "prop-NOTFOUND")
  171. set(prop)
  172. endif()
  173. _juce_append_record(${output} ${key} ${prop})
  174. set(${output} "${${output}}" PARENT_SCOPE)
  175. endfunction()
  176. # This is all info that should be known at configure time (i.e. no generator expressions here!)
  177. # We use this info to generate plists and entitlements files, also at configure time.
  178. function(_juce_write_configure_time_info target)
  179. _juce_append_target_property(file_content EXECUTABLE_NAME ${target} JUCE_PRODUCT_NAME)
  180. _juce_append_target_property(file_content VERSION ${target} JUCE_VERSION)
  181. _juce_append_target_property(file_content BUILD_VERSION ${target} JUCE_BUILD_VERSION)
  182. _juce_append_target_property(file_content PLIST_TO_MERGE ${target} JUCE_PLIST_TO_MERGE)
  183. _juce_append_target_property(file_content BUNDLE_ID ${target} JUCE_BUNDLE_ID)
  184. _juce_append_target_property(file_content XCODE_EXTRA_PLIST_ENTRIES ${target} JUCE_XCODE_EXTRA_PLIST_ENTRIES)
  185. _juce_append_target_property(file_content MICROPHONE_PERMISSION_ENABLED ${target} JUCE_MICROPHONE_PERMISSION_ENABLED)
  186. _juce_append_target_property(file_content MICROPHONE_PERMISSION_TEXT ${target} JUCE_MICROPHONE_PERMISSION_TEXT)
  187. _juce_append_target_property(file_content CAMERA_PERMISSION_ENABLED ${target} JUCE_CAMERA_PERMISSION_ENABLED)
  188. _juce_append_target_property(file_content CAMERA_PERMISSION_TEXT ${target} JUCE_CAMERA_PERMISSION_TEXT)
  189. _juce_append_target_property(file_content BLUETOOTH_PERMISSION_ENABLED ${target} JUCE_BLUETOOTH_PERMISSION_ENABLED)
  190. _juce_append_target_property(file_content BLUETOOTH_PERMISSION_TEXT ${target} JUCE_BLUETOOTH_PERMISSION_TEXT)
  191. _juce_append_target_property(file_content SEND_APPLE_EVENTS_PERMISSION_ENABLED ${target} JUCE_SEND_APPLE_EVENTS_PERMISSION_ENABLED)
  192. _juce_append_target_property(file_content SEND_APPLE_EVENTS_PERMISSION_TEXT ${target} JUCE_SEND_APPLE_EVENTS_PERMISSION_TEXT)
  193. _juce_append_target_property(file_content SHOULD_ADD_STORYBOARD ${target} JUCE_SHOULD_ADD_STORYBOARD)
  194. _juce_append_target_property(file_content LAUNCH_STORYBOARD_FILE ${target} JUCE_LAUNCH_STORYBOARD_FILE)
  195. _juce_append_target_property(file_content ICON_FILE ${target} JUCE_ICON_FILE)
  196. _juce_append_target_property(file_content PROJECT_NAME ${target} JUCE_PRODUCT_NAME)
  197. _juce_append_target_property(file_content COMPANY_COPYRIGHT ${target} JUCE_COMPANY_COPYRIGHT)
  198. _juce_append_target_property(file_content COMPANY_NAME ${target} JUCE_COMPANY_NAME)
  199. _juce_append_target_property(file_content DOCUMENT_EXTENSIONS ${target} JUCE_DOCUMENT_EXTENSIONS)
  200. _juce_append_target_property(file_content FILE_SHARING_ENABLED ${target} JUCE_FILE_SHARING_ENABLED)
  201. _juce_append_target_property(file_content DOCUMENT_BROWSER_ENABLED ${target} JUCE_DOCUMENT_BROWSER_ENABLED)
  202. _juce_append_target_property(file_content STATUS_BAR_HIDDEN ${target} JUCE_STATUS_BAR_HIDDEN)
  203. _juce_append_target_property(file_content REQUIRES_FULL_SCREEN ${target} JUCE_REQUIRES_FULL_SCREEN)
  204. _juce_append_target_property(file_content BACKGROUND_AUDIO_ENABLED ${target} JUCE_BACKGROUND_AUDIO_ENABLED)
  205. _juce_append_target_property(file_content BACKGROUND_BLE_ENABLED ${target} JUCE_BACKGROUND_BLE_ENABLED)
  206. _juce_append_target_property(file_content PUSH_NOTIFICATIONS_ENABLED ${target} JUCE_PUSH_NOTIFICATIONS_ENABLED)
  207. _juce_append_target_property(file_content NETWORK_MULTICAST_ENABLED ${target} JUCE_NETWORK_MULTICAST_ENABLED)
  208. _juce_append_target_property(file_content PLUGIN_MANUFACTURER_CODE ${target} JUCE_PLUGIN_MANUFACTURER_CODE)
  209. _juce_append_target_property(file_content PLUGIN_CODE ${target} JUCE_PLUGIN_CODE)
  210. _juce_append_target_property(file_content IPHONE_SCREEN_ORIENTATIONS ${target} JUCE_IPHONE_SCREEN_ORIENTATIONS)
  211. _juce_append_target_property(file_content IPAD_SCREEN_ORIENTATIONS ${target} JUCE_IPAD_SCREEN_ORIENTATIONS)
  212. _juce_append_target_property(file_content PLUGIN_NAME ${target} JUCE_PLUGIN_NAME)
  213. _juce_append_target_property(file_content PLUGIN_MANUFACTURER ${target} JUCE_COMPANY_NAME)
  214. _juce_append_target_property(file_content PLUGIN_DESCRIPTION ${target} JUCE_DESCRIPTION)
  215. _juce_append_target_property(file_content PLUGIN_AU_EXPORT_PREFIX ${target} JUCE_AU_EXPORT_PREFIX)
  216. _juce_append_target_property(file_content PLUGIN_AU_MAIN_TYPE ${target} JUCE_AU_MAIN_TYPE_CODE)
  217. _juce_append_target_property(file_content IS_AU_SANDBOX_SAFE ${target} JUCE_AU_SANDBOX_SAFE)
  218. _juce_append_target_property(file_content IS_PLUGIN_SYNTH ${target} JUCE_IS_SYNTH)
  219. _juce_append_target_property(file_content IS_PLUGIN_ARA_EFFECT ${target} JUCE_IS_ARA_EFFECT)
  220. _juce_append_target_property(file_content SUPPRESS_AU_PLIST_RESOURCE_USAGE ${target} JUCE_SUPPRESS_AU_PLIST_RESOURCE_USAGE)
  221. _juce_append_target_property(file_content HARDENED_RUNTIME_ENABLED ${target} JUCE_HARDENED_RUNTIME_ENABLED)
  222. _juce_append_target_property(file_content APP_SANDBOX_ENABLED ${target} JUCE_APP_SANDBOX_ENABLED)
  223. _juce_append_target_property(file_content APP_SANDBOX_INHERIT ${target} JUCE_APP_SANDBOX_INHERIT)
  224. _juce_append_target_property(file_content HARDENED_RUNTIME_OPTIONS ${target} JUCE_HARDENED_RUNTIME_OPTIONS)
  225. _juce_append_target_property(file_content APP_SANDBOX_OPTIONS ${target} JUCE_APP_SANDBOX_OPTIONS)
  226. _juce_append_target_property(file_content APP_SANDBOX_FILE_ACCESS_HOME_RO ${target} JUCE_APP_SANDBOX_FILE_ACCESS_HOME_RO)
  227. _juce_append_target_property(file_content APP_SANDBOX_FILE_ACCESS_HOME_RW ${target} JUCE_APP_SANDBOX_FILE_ACCESS_HOME_RW)
  228. _juce_append_target_property(file_content APP_SANDBOX_FILE_ACCESS_ABS_RO ${target} JUCE_APP_SANDBOX_FILE_ACCESS_ABS_RO)
  229. _juce_append_target_property(file_content APP_SANDBOX_FILE_ACCESS_ABS_RW ${target} JUCE_APP_SANDBOX_FILE_ACCESS_ABS_RW)
  230. _juce_append_target_property(file_content APP_GROUPS_ENABLED ${target} JUCE_APP_GROUPS_ENABLED)
  231. _juce_append_target_property(file_content APP_GROUP_IDS ${target} JUCE_APP_GROUP_IDS)
  232. _juce_append_target_property(file_content IS_PLUGIN ${target} JUCE_IS_PLUGIN)
  233. _juce_append_target_property(file_content ICLOUD_PERMISSIONS_ENABLED ${target} JUCE_ICLOUD_PERMISSIONS_ENABLED)
  234. if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
  235. _juce_append_record(file_content IS_IOS 1)
  236. else()
  237. _juce_append_record(file_content IS_IOS 0)
  238. endif()
  239. get_target_property(juce_library_code ${target} JUCE_GENERATED_SOURCES_DIRECTORY)
  240. set(info_file "${juce_library_code}/Info.txt")
  241. file(WRITE "${info_file}" "${file_content}")
  242. set_target_properties(${target} PROPERTIES JUCE_INFO_FILE "${info_file}")
  243. endfunction()
  244. # In this file, we put things that CMake is only able to divine at generate time, like preprocessor definitions.
  245. # We use the target preprocessor definitions to work out which JUCE modules should go in the JuceHeader.h.
  246. function(_juce_write_generate_time_info target)
  247. _juce_get_module_definitions(${target} OFF module_defs)
  248. _juce_append_record(defs MODULE_DEFINITIONS ${module_defs})
  249. _juce_append_target_property(defs EXECUTABLE_NAME ${target} JUCE_PRODUCT_NAME)
  250. _juce_append_target_property(defs PROJECT_NAME ${target} JUCE_PRODUCT_NAME)
  251. _juce_append_target_property(defs VERSION ${target} JUCE_VERSION)
  252. _juce_append_target_property(defs COMPANY_NAME ${target} JUCE_COMPANY_NAME)
  253. get_target_property(juce_library_code ${target} JUCE_GENERATED_SOURCES_DIRECTORY)
  254. set(defs_file "${juce_library_code}/$<CONFIG>/Defs.txt")
  255. file(GENERATE OUTPUT "${defs_file}" CONTENT "${defs}")
  256. set_target_properties(${target} PROPERTIES JUCE_DEFS_FILE "${defs_file}")
  257. endfunction()
  258. # ==================================================================================================
  259. function(juce_add_binary_data target)
  260. set(one_value_args NAMESPACE HEADER_NAME)
  261. set(multi_value_args SOURCES)
  262. cmake_parse_arguments(JUCE_ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN})
  263. list(LENGTH JUCE_ARG_SOURCES num_binary_files)
  264. if(${num_binary_files} LESS 1)
  265. message(FATAL_ERROR "juce_add_binary_data must be passed at least one file to encode")
  266. endif()
  267. add_library(${target} STATIC)
  268. set(juce_binary_data_folder "${CMAKE_CURRENT_BINARY_DIR}/juce_binarydata_${target}/JuceLibraryCode")
  269. set(binary_file_names)
  270. foreach(index RANGE 1 ${num_binary_files})
  271. list(APPEND binary_file_names "${juce_binary_data_folder}/BinaryData${index}.cpp")
  272. endforeach()
  273. file(MAKE_DIRECTORY ${juce_binary_data_folder})
  274. if(NOT JUCE_ARG_NAMESPACE)
  275. set(JUCE_ARG_NAMESPACE BinaryData)
  276. endif()
  277. if(NOT JUCE_ARG_HEADER_NAME)
  278. set(JUCE_ARG_HEADER_NAME BinaryData.h)
  279. endif()
  280. list(APPEND binary_file_names "${juce_binary_data_folder}/${JUCE_ARG_HEADER_NAME}")
  281. set(newline_delimited_input)
  282. foreach(name IN LISTS JUCE_ARG_SOURCES)
  283. _juce_make_absolute_and_check(name)
  284. set(newline_delimited_input "${newline_delimited_input}${name}\n")
  285. endforeach()
  286. set(input_file_list "${juce_binary_data_folder}/input_file_list")
  287. file(WRITE "${input_file_list}" "${newline_delimited_input}")
  288. add_custom_command(OUTPUT ${binary_file_names}
  289. COMMAND juce::juceaide binarydata "${JUCE_ARG_NAMESPACE}" "${JUCE_ARG_HEADER_NAME}"
  290. ${juce_binary_data_folder} "${input_file_list}"
  291. WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
  292. DEPENDS "${input_file_list}"
  293. VERBATIM)
  294. target_sources(${target} PRIVATE "${binary_file_names}")
  295. target_include_directories(${target} INTERFACE ${juce_binary_data_folder})
  296. target_compile_features(${target} PRIVATE cxx_std_17)
  297. # This fixes an issue where Xcode is unable to find binary data during archive.
  298. if(CMAKE_GENERATOR STREQUAL "Xcode")
  299. set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "./")
  300. endif()
  301. if(JUCE_ARG_HEADER_NAME STREQUAL "BinaryData.h")
  302. target_compile_definitions(${target} INTERFACE JUCE_TARGET_HAS_BINARY_DATA=1)
  303. endif()
  304. endfunction()
  305. # ==================================================================================================
  306. function(_juce_version_code version_in out_var)
  307. string(REGEX REPLACE "\\." ";" version_list ${version_in})
  308. list(LENGTH version_list num_version_components)
  309. set(version_major 0)
  310. set(version_minor 0)
  311. set(version_patch 0)
  312. if(num_version_components GREATER 0)
  313. list(GET version_list 0 version_major)
  314. endif()
  315. if(num_version_components GREATER 1)
  316. list(GET version_list 1 version_minor)
  317. endif()
  318. if(num_version_components GREATER 2)
  319. list(GET version_list 2 version_patch)
  320. endif()
  321. math(EXPR hex "(${version_major} << 16) + (${version_minor} << 8) + ${version_patch}"
  322. OUTPUT_FORMAT HEXADECIMAL)
  323. set(${out_var} "${hex}" PARENT_SCOPE)
  324. endfunction()
  325. function(_juce_to_char_literal str out_var help_text)
  326. string(LENGTH "${str}" string_length)
  327. if(NOT "${string_length}" EQUAL "4")
  328. message(WARNING "The ${help_text} code must contain exactly four characters, but it was set to '${str}'")
  329. endif()
  330. # Round-tripping through a file is the simplest way to convert a string to hex...
  331. string(SUBSTRING "${str}" 0 4 four_chars)
  332. string(RANDOM LENGTH 16 random_string)
  333. set(scratch_file "${CMAKE_CURRENT_BINARY_DIR}/${random_string}_ascii_conversion.txt")
  334. file(WRITE "${scratch_file}" "${four_chars}")
  335. file(READ "${scratch_file}" four_chars_hex HEX)
  336. file(REMOVE "${scratch_file}")
  337. string(SUBSTRING "${four_chars_hex}00000000" 0 8 four_chars_hex)
  338. set(${out_var} "${four_chars_hex}" PARENT_SCOPE)
  339. endfunction()
  340. # ==================================================================================================
  341. function(juce_generate_juce_header target)
  342. get_target_property(juce_library_code ${target} JUCE_GENERATED_SOURCES_DIRECTORY)
  343. if(NOT juce_library_code)
  344. message(FATAL_ERROR "Target ${target} does not have a generated sources directory. Ensure it was created with a juce_add_* function")
  345. endif()
  346. set(juce_header ${juce_library_code}/JuceHeader.h)
  347. target_sources(${target} PRIVATE ${juce_header})
  348. set(defs_file $<GENEX_EVAL:$<TARGET_PROPERTY:${target},JUCE_DEFS_FILE>>)
  349. set(extra_args)
  350. add_custom_command(OUTPUT "${juce_header}"
  351. COMMAND juce::juceaide header "${defs_file}" "${juce_header}" ${extra_args}
  352. DEPENDS "${defs_file}"
  353. VERBATIM)
  354. endfunction()
  355. # ==================================================================================================
  356. function(_juce_execute_juceaide)
  357. if(NOT TARGET juce::juceaide)
  358. message(FATAL_ERROR "The juceaide target does not exist")
  359. endif()
  360. get_target_property(juceaide_location juce::juceaide IMPORTED_LOCATION)
  361. if(NOT EXISTS "${juceaide_location}")
  362. message(FATAL_ERROR "juceaide was imported, but it doesn't exist!")
  363. endif()
  364. execute_process(COMMAND "${juceaide_location}" ${ARGN}
  365. RESULT_VARIABLE result_variable
  366. OUTPUT_VARIABLE output
  367. ERROR_VARIABLE output)
  368. if(result_variable)
  369. message(FATAL_ERROR "Running juceaide failed:\n${output}")
  370. endif()
  371. endfunction()
  372. function(_juce_set_output_name target name)
  373. if(NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
  374. set_target_properties(${target} PROPERTIES
  375. OUTPUT_NAME ${name}
  376. XCODE_ATTRIBUTE_PRODUCT_NAME ${name})
  377. endif()
  378. endfunction()
  379. function(_juce_check_icon_files_exist icon_files)
  380. foreach(file IN LISTS icon_files)
  381. if(NOT EXISTS "${file}")
  382. message(FATAL_ERROR "Could not find icon file: ${file}")
  383. endif()
  384. endforeach()
  385. endfunction()
  386. function(_juce_generate_icon source_target dest_target)
  387. get_target_property(juce_library_code ${source_target} JUCE_GENERATED_SOURCES_DIRECTORY)
  388. get_target_property(juce_property_icon_big ${source_target} JUCE_ICON_BIG)
  389. get_target_property(juce_property_icon_small ${source_target} JUCE_ICON_SMALL)
  390. set(icon_args)
  391. if(juce_property_icon_big)
  392. list(APPEND icon_args "${juce_property_icon_big}")
  393. endif()
  394. if(juce_property_icon_small)
  395. list(APPEND icon_args "${juce_property_icon_small}")
  396. endif()
  397. set(generated_icon)
  398. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  399. if(NOT icon_args)
  400. return()
  401. endif()
  402. _juce_check_icon_files_exist("${icon_args}")
  403. set(generated_icon "${juce_library_code}/Icon.icns")
  404. # To get compiled properly, we need the icon before the plist is generated!
  405. _juce_execute_juceaide(macicon "${generated_icon}" ${icon_args})
  406. set_source_files_properties(${generated_icon} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
  407. elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  408. if(NOT icon_args)
  409. return()
  410. endif()
  411. _juce_check_icon_files_exist("${icon_args}")
  412. set(generated_icon "${juce_library_code}/icon.ico")
  413. _juce_execute_juceaide(winicon "${generated_icon}" ${icon_args})
  414. elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
  415. get_target_property(generated_icon ${source_target} JUCE_CUSTOM_XCASSETS_FOLDER)
  416. if(icon_args AND (NOT generated_icon))
  417. _juce_check_icon_files_exist("${icon_args}")
  418. set(out_path "${juce_library_code}/${dest_target}")
  419. set(generated_icon "${out_path}/Images.xcassets")
  420. # To get compiled properly, we need iOS assets at configure time!
  421. _juce_execute_juceaide(iosassets "${out_path}" ${icon_args})
  422. endif()
  423. if(NOT generated_icon)
  424. return()
  425. endif()
  426. set_target_properties(${dest_target} PROPERTIES
  427. XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon")
  428. get_target_property(add_storyboard ${source_target} JUCE_SHOULD_ADD_STORYBOARD)
  429. if(NOT add_storyboard)
  430. set_target_properties(${dest_target} PROPERTIES
  431. XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME "LaunchImage")
  432. endif()
  433. endif()
  434. if(generated_icon)
  435. _juce_check_icon_files_exist("${generated_icon}")
  436. target_sources(${dest_target} PRIVATE ${generated_icon})
  437. set_target_properties(${source_target} ${dest_target} PROPERTIES
  438. JUCE_ICON_FILE "${generated_icon}"
  439. RESOURCE "${generated_icon}")
  440. endif()
  441. endfunction()
  442. function(_juce_add_xcode_entitlements source_target dest_target)
  443. get_target_property(juce_kind_string ${dest_target} JUCE_TARGET_KIND_STRING)
  444. get_target_property(input_info_file ${source_target} JUCE_INFO_FILE)
  445. get_target_property(juce_library_code ${source_target} JUCE_GENERATED_SOURCES_DIRECTORY)
  446. set(entitlements_file "${juce_library_code}/${dest_target}.entitlements")
  447. _juce_execute_juceaide(entitlements "${juce_kind_string}" "${input_info_file}" "${entitlements_file}")
  448. set_target_properties(${dest_target} PROPERTIES
  449. XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${entitlements_file}")
  450. endfunction()
  451. function(_juce_configure_bundle source_target dest_target)
  452. _juce_generate_icon(${source_target} ${dest_target})
  453. _juce_write_configure_time_info(${source_target})
  454. if(NOT APPLE)
  455. return()
  456. endif()
  457. get_target_property(generated_icon ${source_target} JUCE_ICON_FILE)
  458. set(icon_dependency)
  459. if(generated_icon)
  460. set(icon_dependency "${generated_icon}")
  461. endif()
  462. get_target_property(juce_library_code ${source_target} JUCE_GENERATED_SOURCES_DIRECTORY)
  463. get_target_property(input_info_file ${source_target} JUCE_INFO_FILE)
  464. set(this_output_info_dir "${juce_library_code}/${dest_target}")
  465. set(this_output_pkginfo "${this_output_info_dir}/PkgInfo")
  466. set(this_output_plist "${this_output_info_dir}/Info.plist")
  467. get_target_property(juce_kind_string ${dest_target} JUCE_TARGET_KIND_STRING)
  468. _juce_execute_juceaide(plist "${juce_kind_string}" "${input_info_file}" "${this_output_plist}")
  469. set_target_properties(${dest_target} PROPERTIES
  470. BUNDLE TRUE
  471. MACOSX_BUNDLE_INFO_PLIST "${this_output_plist}")
  472. add_custom_command(OUTPUT "${this_output_pkginfo}"
  473. COMMAND juce::juceaide pkginfo "${juce_kind_string}" "${this_output_pkginfo}"
  474. VERBATIM)
  475. set(output_folder "$<TARGET_BUNDLE_CONTENT_DIR:${dest_target}>")
  476. target_sources(${dest_target} PRIVATE "${this_output_pkginfo}")
  477. set_source_files_properties("${this_output_pkginfo}" PROPERTIES
  478. HEADER_FILE_ONLY TRUE
  479. GENERATED TRUE)
  480. add_custom_command(TARGET ${dest_target} POST_BUILD
  481. COMMAND "${CMAKE_COMMAND}" -E copy "${this_output_pkginfo}" "${output_folder}"
  482. DEPENDS "${this_output_pkginfo}"
  483. VERBATIM)
  484. _juce_add_xcode_entitlements(${source_target} ${dest_target})
  485. if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
  486. get_target_property(add_storyboard ${source_target} JUCE_SHOULD_ADD_STORYBOARD)
  487. if(add_storyboard)
  488. get_target_property(storyboard_file ${source_target} JUCE_LAUNCH_STORYBOARD_FILE)
  489. if(NOT EXISTS "${storyboard_file}")
  490. message(FATAL_ERROR "Could not find storyboard file: ${storyboard_file}")
  491. endif()
  492. target_sources(${dest_target} PRIVATE "${storyboard_file}")
  493. set_property(TARGET ${dest_target} APPEND PROPERTY RESOURCE "${storyboard_file}")
  494. endif()
  495. endif()
  496. set_target_properties(${dest_target} PROPERTIES
  497. XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME
  498. "$<TARGET_PROPERTY:${source_target},JUCE_HARDENED_RUNTIME_ENABLED>"
  499. XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY
  500. "$<TARGET_PROPERTY:${source_target},JUCE_TARGETED_DEVICE_FAMILY>")
  501. if(juce_kind_string STREQUAL "AUv3 AppExtension")
  502. get_target_property(source_bundle_id ${source_target} JUCE_BUNDLE_ID)
  503. if(source_bundle_id MATCHES "\\.([^.]+)$")
  504. set_target_properties(${dest_target} PROPERTIES
  505. XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER
  506. "${source_bundle_id}.${CMAKE_MATCH_1}AUv3")
  507. else()
  508. message(FATAL_ERROR "Bundle ID should contain at least one `.`!")
  509. endif()
  510. else()
  511. set_target_properties(${dest_target} PROPERTIES
  512. XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER
  513. $<TARGET_PROPERTY:${source_target},JUCE_BUNDLE_ID>)
  514. endif()
  515. if(CMAKE_GENERATOR STREQUAL "Xcode")
  516. get_target_property(product_name ${source_target} JUCE_PRODUCT_NAME)
  517. set(install_path "$(LOCAL_APPS_DIR)")
  518. if(juce_kind_string STREQUAL "AUv3 AppExtension")
  519. set(install_path "${install_path}/${product_name}.app")
  520. if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
  521. set(install_path "${install_path}/PlugIns")
  522. else()
  523. set(install_path "${install_path}/Contents/PlugIns")
  524. endif()
  525. endif()
  526. set_target_properties(${dest_target} PROPERTIES
  527. XCODE_ATTRIBUTE_INSTALL_PATH "${install_path}"
  528. XCODE_ATTRIBUTE_SKIP_INSTALL "NO")
  529. endif()
  530. endfunction()
  531. function(_juce_add_resources_rc source_target dest_target)
  532. if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
  533. return()
  534. endif()
  535. get_target_property(juce_library_code ${source_target} JUCE_GENERATED_SOURCES_DIRECTORY)
  536. set(input_info_file "$<TARGET_PROPERTY:${source_target},JUCE_INFO_FILE>")
  537. get_target_property(generated_icon ${source_target} JUCE_ICON_FILE)
  538. set(dependency)
  539. if(generated_icon)
  540. set(dependency DEPENDS "${generated_icon}")
  541. endif()
  542. set(resource_rc_file "${juce_library_code}/resources.rc")
  543. add_custom_command(OUTPUT "${resource_rc_file}"
  544. COMMAND juce::juceaide rcfile "${input_info_file}" "${resource_rc_file}"
  545. ${dependency}
  546. VERBATIM)
  547. target_sources(${dest_target} PRIVATE "${resource_rc_file}")
  548. endfunction()
  549. function(_juce_configure_app_bundle source_target dest_target)
  550. set_target_properties(${dest_target} PROPERTIES
  551. JUCE_TARGET_KIND_STRING "App"
  552. MACOSX_BUNDLE TRUE
  553. WIN32_EXECUTABLE TRUE)
  554. _juce_add_resources_rc(${source_target} ${dest_target})
  555. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  556. set(nib_path "${JUCE_CMAKE_UTILS_DIR}/RecentFilesMenuTemplate.nib")
  557. target_sources("${dest_target}" PRIVATE "${nib_path}")
  558. set_source_files_properties("${nib_path}" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
  559. endif()
  560. endfunction()
  561. # ==================================================================================================
  562. function(_juce_create_windows_package source_target dest_target extension default_icon x32folder x64folder)
  563. if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
  564. return()
  565. endif()
  566. get_target_property(products_folder ${dest_target} LIBRARY_OUTPUT_DIRECTORY)
  567. set(product_name $<TARGET_PROPERTY:${source_target},JUCE_PRODUCT_NAME>)
  568. set(output_folder "${products_folder}/${product_name}.${extension}")
  569. set(is_x64 $<EQUAL:${CMAKE_SIZEOF_VOID_P},8>)
  570. set(arch_string $<IF:${is_x64},${x64folder},${x32folder}>)
  571. set_target_properties(${dest_target}
  572. PROPERTIES
  573. PDB_OUTPUT_DIRECTORY "${products_folder}"
  574. LIBRARY_OUTPUT_DIRECTORY "${output_folder}/Contents/${arch_string}")
  575. get_target_property(icon_file ${source_target} JUCE_ICON_FILE)
  576. if(NOT icon_file)
  577. set(icon_file "${default_icon}")
  578. endif()
  579. if(icon_file)
  580. set(desktop_ini "${output_folder}/desktop.ini")
  581. set(plugin_ico "${output_folder}/Plugin.ico")
  582. file(GENERATE OUTPUT "${desktop_ini}"
  583. CONTENT
  584. "[.ShellClassInfo]\nIconResource=Plugin.ico,0\nIconFile=Plugin.ico\nIconIndex=0\n")
  585. add_custom_command(TARGET ${dest_target} POST_BUILD
  586. COMMAND "${CMAKE_COMMAND}" -E copy "${icon_file}" "${plugin_ico}"
  587. COMMAND attrib +s "${desktop_ini}"
  588. COMMAND attrib +s "${output_folder}"
  589. DEPENDS "${icon_file}" "${desktop_ini}"
  590. VERBATIM)
  591. endif()
  592. endfunction()
  593. # ==================================================================================================
  594. function(_juce_add_unity_plugin_prefix_if_necessary name out_var)
  595. string(TOLOWER "${name}" lower)
  596. if(NOT lower MATCHES "^audioplugin")
  597. set(${out_var} "audioplugin_${name}" PARENT_SCOPE)
  598. else()
  599. set(${out_var} "${name}" PARENT_SCOPE)
  600. endif()
  601. endfunction()
  602. function(_juce_add_unity_script_file shared_target out_var)
  603. set(script_in "${JUCE_CMAKE_UTILS_DIR}/UnityPluginGUIScript.cs.in")
  604. get_target_property(plugin_name ${shared_target} JUCE_PLUGIN_NAME)
  605. get_target_property(plugin_vendor ${shared_target} JUCE_COMPANY_NAME)
  606. get_target_property(plugin_description ${shared_target} JUCE_DESCRIPTION)
  607. string(REGEX REPLACE " +" "_" plugin_class_name "${plugin_name}")
  608. get_target_property(juce_library_code ${shared_target} JUCE_GENERATED_SOURCES_DIRECTORY)
  609. _juce_add_unity_plugin_prefix_if_necessary("${plugin_name}" script_prefix)
  610. set(script_out "${juce_library_code}/${script_prefix}_UnityScript.cs")
  611. configure_file(${script_in} ${script_out})
  612. set(${out_var} "${script_out}" PARENT_SCOPE)
  613. endfunction()
  614. # ==================================================================================================
  615. function(_juce_copy_dir target from to)
  616. # This is a shim to make CMake copy a whole directory, rather than just
  617. # the contents of a directory
  618. add_custom_command(TARGET ${target} POST_BUILD
  619. COMMAND "${CMAKE_COMMAND}"
  620. "-Dsrc=${from}"
  621. "-Ddest=${to}"
  622. "-P" "${JUCE_CMAKE_UTILS_DIR}/copyDir.cmake"
  623. VERBATIM)
  624. endfunction()
  625. function(_juce_set_copy_properties shared_code target from to_property)
  626. get_target_property(destination "${shared_code}" "${to_property}")
  627. if(destination)
  628. set_target_properties("${target}" PROPERTIES JUCE_PLUGIN_COPY_DIR "${destination}")
  629. endif()
  630. set_target_properties("${target}" PROPERTIES JUCE_PLUGIN_ARTEFACT_FILE "${from}")
  631. endfunction()
  632. function(juce_enable_copy_plugin_step shared_code_target)
  633. get_target_property(active_targets "${shared_code_target}" JUCE_ACTIVE_PLUGIN_TARGETS)
  634. foreach(target IN LISTS active_targets)
  635. get_target_property(target_kind "${target}" JUCE_TARGET_KIND_STRING)
  636. if(target_kind STREQUAL "App")
  637. continue()
  638. endif()
  639. get_target_property(source "${target}" JUCE_PLUGIN_ARTEFACT_FILE)
  640. if(source)
  641. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  642. add_custom_command(TARGET ${target} POST_BUILD
  643. COMMAND "${CMAKE_COMMAND}"
  644. "-Dsrc=${source}"
  645. "-P" "${JUCE_CMAKE_UTILS_DIR}/checkBundleSigning.cmake"
  646. VERBATIM)
  647. endif()
  648. get_target_property(dest "${target}" JUCE_PLUGIN_COPY_DIR)
  649. if(dest)
  650. _juce_copy_dir("${target}" "${source}" "$<GENEX_EVAL:${dest}>")
  651. else()
  652. message(WARNING "Target '${target}' requested copy but no destination is set")
  653. endif()
  654. endif()
  655. endforeach()
  656. endfunction()
  657. # ==================================================================================================
  658. function(_juce_set_plugin_target_properties shared_code_target kind)
  659. set(target_name ${shared_code_target}_${kind})
  660. set_target_properties(${target_name} PROPERTIES
  661. ARCHIVE_OUTPUT_DIRECTORY "$<GENEX_EVAL:$<TARGET_PROPERTY:${shared_code_target},ARCHIVE_OUTPUT_DIRECTORY>>/${kind}"
  662. LIBRARY_OUTPUT_DIRECTORY "$<GENEX_EVAL:$<TARGET_PROPERTY:${shared_code_target},LIBRARY_OUTPUT_DIRECTORY>>/${kind}"
  663. RUNTIME_OUTPUT_DIRECTORY "$<GENEX_EVAL:$<TARGET_PROPERTY:${shared_code_target},RUNTIME_OUTPUT_DIRECTORY>>/${kind}")
  664. get_target_property(products_folder ${target_name} LIBRARY_OUTPUT_DIRECTORY)
  665. set(product_name $<TARGET_PROPERTY:${shared_code_target},JUCE_PRODUCT_NAME>)
  666. if(kind STREQUAL "Standalone")
  667. get_target_property(is_bundle "${target_name}" BUNDLE)
  668. if(is_bundle)
  669. set_target_properties("${target_name}" PROPERTIES JUCE_PLUGIN_ARTEFACT_FILE "$<TARGET_BUNDLE_DIR:${target_name}>")
  670. else()
  671. set_target_properties("${target_name}" PROPERTIES JUCE_PLUGIN_ARTEFACT_FILE "$<TARGET_FILE:${target_name}>")
  672. endif()
  673. elseif(kind STREQUAL "VST3")
  674. set_target_properties(${target_name} PROPERTIES
  675. BUNDLE_EXTENSION vst3
  676. PREFIX ""
  677. SUFFIX .vst3
  678. BUNDLE TRUE
  679. XCODE_ATTRIBUTE_WRAPPER_EXTENSION vst3
  680. XCODE_ATTRIBUTE_LIBRARY_STYLE Bundle
  681. XCODE_ATTRIBUTE_GENERATE_PKGINFO_FILE YES)
  682. _juce_create_windows_package(${shared_code_target} ${target_name} vst3 "" x86-win x86_64-win)
  683. set(output_path "${products_folder}/${product_name}.vst3")
  684. if((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD"))
  685. set_target_properties(${target_name} PROPERTIES
  686. SUFFIX .so
  687. LIBRARY_OUTPUT_DIRECTORY "${output_path}/Contents/${JUCE_TARGET_ARCHITECTURE}-linux")
  688. endif()
  689. _juce_set_copy_properties(${shared_code_target} ${target_name} "${output_path}" JUCE_VST3_COPY_DIR)
  690. elseif(kind STREQUAL "VST")
  691. set_target_properties(${target_name} PROPERTIES
  692. BUNDLE_EXTENSION vst
  693. BUNDLE TRUE
  694. XCODE_ATTRIBUTE_WRAPPER_EXTENSION vst
  695. XCODE_ATTRIBUTE_LIBRARY_STYLE Bundle
  696. XCODE_ATTRIBUTE_GENERATE_PKGINFO_FILE YES)
  697. set(output_path "$<TARGET_FILE:${target_name}>")
  698. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  699. set(output_path "$<TARGET_BUNDLE_DIR:${target_name}>")
  700. endif()
  701. _juce_set_copy_properties(${shared_code_target} ${target_name} "${output_path}" JUCE_VST_COPY_DIR)
  702. elseif(kind STREQUAL "AU")
  703. set_target_properties(${target_name} PROPERTIES
  704. BUNDLE_EXTENSION component
  705. XCODE_ATTRIBUTE_WRAPPER_EXTENSION component
  706. BUNDLE TRUE
  707. XCODE_ATTRIBUTE_LIBRARY_STYLE Bundle
  708. XCODE_ATTRIBUTE_GENERATE_PKGINFO_FILE YES)
  709. set(output_path "$<TARGET_BUNDLE_DIR:${target_name}>")
  710. _juce_set_copy_properties(${shared_code_target} ${target_name} "${output_path}" JUCE_AU_COPY_DIR)
  711. elseif(kind STREQUAL "AUv3")
  712. set_target_properties(${target_name} PROPERTIES
  713. XCODE_PRODUCT_TYPE "com.apple.product-type.app-extension"
  714. BUNDLE_EXTENSION appex
  715. XCODE_ATTRIBUTE_WRAPPER_EXTENSION appex
  716. XCODE_ATTRIBUTE_GENERATE_PKGINFO_FILE YES)
  717. elseif(kind STREQUAL "AAX")
  718. set_target_properties(${target_name} PROPERTIES
  719. BUNDLE_EXTENSION aaxplugin
  720. PREFIX ""
  721. SUFFIX .aaxplugin
  722. XCODE_ATTRIBUTE_WRAPPER_EXTENSION aaxplugin
  723. BUNDLE TRUE
  724. XCODE_ATTRIBUTE_LIBRARY_STYLE Bundle
  725. XCODE_ATTRIBUTE_GENERATE_PKGINFO_FILE YES)
  726. get_target_property(default_icon juce_aax_sdk INTERFACE_JUCE_AAX_DEFAULT_ICON)
  727. _juce_create_windows_package(${shared_code_target} ${target_name} aaxplugin "${default_icon}" Win32 x64)
  728. set(output_path "${products_folder}/${product_name}.aaxplugin")
  729. _juce_set_copy_properties(${shared_code_target} ${target_name} "${output_path}" JUCE_AAX_COPY_DIR)
  730. elseif(kind STREQUAL "Unity")
  731. set_target_properties(${target_name} PROPERTIES
  732. BUNDLE_EXTENSION bundle
  733. XCODE_ATTRIBUTE_WRAPPER_EXTENSION bundle
  734. BUNDLE TRUE
  735. XCODE_ATTRIBUTE_LIBRARY_STYLE Bundle
  736. XCODE_ATTRIBUTE_GENERATE_PKGINFO_FILE YES)
  737. _juce_add_unity_script_file(${shared_code_target} script_file)
  738. target_sources(${target_name} PRIVATE "${script_file}")
  739. set_source_files_properties("${script_file}" PROPERTIES
  740. GENERATED TRUE
  741. MACOSX_PACKAGE_LOCATION Resources)
  742. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  743. set(output_path "$<TARGET_BUNDLE_DIR:${target_name}>")
  744. _juce_set_copy_properties(${shared_code_target} ${target_name} "${output_path}" JUCE_UNITY_COPY_DIR)
  745. else()
  746. # On windows and linux, the gui script needs to be copied next to the unity output
  747. add_custom_command(TARGET ${target_name} POST_BUILD
  748. COMMAND "${CMAKE_COMMAND}" -E copy "${script_file}" "${products_folder}"
  749. DEPENDS "${script_file}"
  750. VERBATIM)
  751. _juce_set_copy_properties(${shared_code_target}
  752. ${target_name}
  753. "$<TARGET_FILE:${target_name}>"
  754. JUCE_UNITY_COPY_DIR)
  755. _juce_set_copy_properties(${shared_code_target}
  756. ${target_name}
  757. "${script_file}"
  758. JUCE_UNITY_COPY_DIR)
  759. endif()
  760. elseif(kind STREQUAL "LV2")
  761. set_target_properties(${target_name} PROPERTIES BUNDLE FALSE)
  762. get_target_property(JUCE_LV2URI "${shared_code_target}" JUCE_LV2URI)
  763. if(NOT JUCE_LV2URI MATCHES "https?://.*")
  764. message(WARNING
  765. "LV2URI should be well-formed with an 'http' prefix. "
  766. "Check the LV2URI argument to juce_add_plugin.")
  767. endif()
  768. set(source_header "${JUCE_CMAKE_UTILS_DIR}/JuceLV2Defines.h.in")
  769. get_target_property(juce_library_code "${shared_code_target}" JUCE_GENERATED_SOURCES_DIRECTORY)
  770. configure_file("${source_header}" "${juce_library_code}/JuceLV2Defines.h")
  771. set(output_path "${products_folder}/${product_name}.lv2")
  772. set_target_properties(${target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${output_path}")
  773. _juce_add_lv2_manifest_helper_target()
  774. add_custom_command(TARGET ${target_name} POST_BUILD
  775. COMMAND juce::juce_lv2_helper "$<TARGET_FILE:${target_name}>"
  776. VERBATIM)
  777. _juce_set_copy_properties(${shared_code_target} ${target_name} "${output_path}" JUCE_LV2_COPY_DIR)
  778. endif()
  779. endfunction()
  780. # Place plugin wrapper targets alongside the shared code target in IDEs
  781. function(_juce_set_plugin_folder_property shared_target wrapper_target)
  782. get_target_property(folder_to_use "${shared_target}" FOLDER)
  783. if(folder_to_use STREQUAL "folder_to_use-NOTFOUND")
  784. set_target_properties("${shared_target}" PROPERTIES FOLDER "${shared_target}")
  785. elseif(NOT folder_to_use MATCHES ".*${shared_target}$")
  786. set_target_properties("${shared_target}" PROPERTIES FOLDER "${folder_to_use}/${shared_target}")
  787. endif()
  788. get_target_property(folder_to_use "${shared_target}" FOLDER)
  789. set_target_properties("${wrapper_target}" PROPERTIES FOLDER "${folder_to_use}")
  790. endfunction()
  791. # Convert the cmake plugin kind ids to strings understood by ProjectType::Target::typeFromName
  792. function(_juce_get_plugin_kind_name kind out_var)
  793. if(kind STREQUAL "AU")
  794. set(${out_var} "AU" PARENT_SCOPE)
  795. elseif(kind STREQUAL "AUv3")
  796. set(${out_var} "AUv3 AppExtension" PARENT_SCOPE)
  797. elseif(kind STREQUAL "AAX")
  798. set(${out_var} "AAX" PARENT_SCOPE)
  799. elseif(kind STREQUAL "LV2")
  800. set(${out_var} "LV2" PARENT_SCOPE)
  801. elseif(kind STREQUAL "Standalone")
  802. set(${out_var} "Standalone Plugin" PARENT_SCOPE)
  803. elseif(kind STREQUAL "Unity")
  804. set(${out_var} "Unity Plugin" PARENT_SCOPE)
  805. elseif(kind STREQUAL "VST")
  806. set(${out_var} "VST" PARENT_SCOPE)
  807. elseif(kind STREQUAL "VST3")
  808. set(${out_var} "VST3" PARENT_SCOPE)
  809. endif()
  810. endfunction()
  811. function(_juce_link_plugin_wrapper shared_code_target kind)
  812. set(target_name ${shared_code_target}_${kind})
  813. if(CMAKE_SYSTEM_NAME STREQUAL "Android")
  814. add_library(${target_name} SHARED)
  815. elseif((kind STREQUAL "Standalone") OR (kind STREQUAL "AUv3"))
  816. add_executable(${target_name} WIN32 MACOSX_BUNDLE)
  817. else()
  818. add_library(${target_name} MODULE)
  819. endif()
  820. if((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD"))
  821. target_link_options(${target_name} PRIVATE "-Wl,--no-undefined")
  822. endif()
  823. # We re-export the shared code's private include dirs, because the wrapper targets need to
  824. # see the module headers. We don't just link publicly, because that would introduce
  825. # conflicting macro definitions.
  826. target_include_directories(${target_name} PRIVATE
  827. $<TARGET_PROPERTY:${shared_code_target},INCLUDE_DIRECTORIES>)
  828. target_link_libraries(${target_name} PRIVATE
  829. ${shared_code_target}
  830. juce::juce_audio_plugin_client_${kind})
  831. _juce_set_output_name(${target_name} $<TARGET_PROPERTY:${shared_code_target},JUCE_PRODUCT_NAME>)
  832. _juce_set_plugin_folder_property("${shared_code_target}" "${target_name}")
  833. _juce_get_plugin_kind_name(${kind} juce_kind_string)
  834. set_target_properties(${target_name} PROPERTIES
  835. XCODE_ATTRIBUTE_CLANG_LINK_OBJC_RUNTIME NO
  836. XCODE_ATTRIBUTE_COMBINE_HIDPI_IMAGES YES
  837. POSITION_INDEPENDENT_CODE TRUE
  838. VISIBILITY_INLINES_HIDDEN TRUE
  839. C_VISIBILITY_PRESET hidden
  840. CXX_VISIBILITY_PRESET hidden
  841. JUCE_TARGET_KIND_STRING "${juce_kind_string}")
  842. # Under the Xcode generator, POST_BUILD commands (including the plugin copy step) run before
  843. # signing, but M1 macs will only load signed binaries. Setting "adhoc_codesign" forces the
  844. # linker to sign bundles, so that they can be loaded even if they are copied before the "real"
  845. # signing step. See issue 21854 on the CMake Gitlab repo.
  846. if("${CMAKE_GENERATOR};${CMAKE_SYSTEM_NAME};${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "Xcode;Darwin;arm64")
  847. target_link_options(${target_name} PRIVATE LINKER:-adhoc_codesign)
  848. endif()
  849. add_dependencies(${shared_code_target}_All ${target_name})
  850. if(NOT kind STREQUAL "LV2")
  851. _juce_configure_bundle(${shared_code_target} ${target_name})
  852. endif()
  853. _juce_set_plugin_target_properties(${shared_code_target} ${kind})
  854. endfunction()
  855. # ==================================================================================================
  856. function(_juce_get_vst3_category_string target out_var)
  857. get_target_property(vst3_categories ${target} JUCE_VST3_CATEGORIES)
  858. if((NOT Fx IN_LIST vst3_categories) AND (NOT Instrument IN_LIST vst3_categories))
  859. get_target_property(is_synth ${target} JUCE_IS_SYNTH)
  860. if(is_synth)
  861. set(first_type Instrument)
  862. else()
  863. set(first_type Fx)
  864. endif()
  865. list(INSERT vst3_categories 0 ${first_type})
  866. else()
  867. if(Instrument IN_LIST vst3_categories)
  868. list(REMOVE_ITEM vst3_categories Instrument)
  869. list(INSERT vst3_categories 0 Instrument)
  870. endif()
  871. if(Fx IN_LIST vst3_categories)
  872. list(REMOVE_ITEM vst3_categories Fx)
  873. list(INSERT vst3_categories 0 Fx)
  874. endif()
  875. endif()
  876. string(REGEX REPLACE ";" "|" result "${vst3_categories}")
  877. set(${out_var} ${result} PARENT_SCOPE)
  878. endfunction()
  879. function(_juce_configure_plugin_targets target)
  880. _juce_set_output_name(${target} $<TARGET_PROPERTY:${target},JUCE_PRODUCT_NAME>_SharedCode)
  881. target_link_libraries(${target} PRIVATE juce::juce_audio_plugin_client_utils)
  882. get_target_property(enabled_formats ${target} JUCE_FORMATS)
  883. set(active_formats)
  884. _juce_get_platform_plugin_kinds(plugin_kinds)
  885. foreach(kind IN LISTS plugin_kinds)
  886. if(kind IN_LIST enabled_formats)
  887. list(APPEND active_formats "${kind}")
  888. endif()
  889. endforeach()
  890. if((VST IN_LIST active_formats) AND (NOT TARGET juce_vst2_sdk))
  891. message(FATAL_ERROR "Use juce_set_vst2_sdk_path to set up the VST sdk before adding VST targets")
  892. elseif((AAX IN_LIST active_formats) AND (NOT TARGET juce_aax_sdk))
  893. message(FATAL_ERROR "Use juce_set_aax_sdk_path to set up the AAX sdk before adding AAX targets")
  894. endif()
  895. _juce_add_standard_defs(${target})
  896. _juce_add_plugin_definitions(${target} PRIVATE ${active_formats})
  897. # The plugin wrappers need to know what other modules are available, especially
  898. # juce_audio_utils and juce_gui_basics. We achieve this by searching for
  899. # JUCE_MODULE_AVAILABLE_ private compile definitions, and reexporting them in
  900. # the interface compile definitions.
  901. _juce_get_module_definitions(${target} ON enabled_modules)
  902. target_compile_definitions(${target} INTERFACE ${enabled_modules})
  903. target_compile_definitions(${target} PRIVATE JUCE_SHARED_CODE=1)
  904. get_target_property(project_version_string ${target} JUCE_VERSION)
  905. _juce_version_code(${project_version_string} project_version_hex)
  906. get_target_property(project_manufacturer_code ${target} JUCE_PLUGIN_MANUFACTURER_CODE)
  907. get_target_property(project_plugin_code ${target} JUCE_PLUGIN_CODE)
  908. get_target_property(use_legacy_compatibility_plugin_code ${target} JUCE_USE_LEGACY_COMPATIBILITY_PLUGIN_CODE)
  909. if(use_legacy_compatibility_plugin_code)
  910. set(project_manufacturer_code "proj")
  911. endif()
  912. _juce_to_char_literal(${project_manufacturer_code} project_manufacturer_code "plugin manufacturer")
  913. _juce_to_char_literal(${project_plugin_code} project_plugin_code "plugin")
  914. _juce_get_vst3_category_string(${target} vst3_category_string)
  915. target_compile_definitions(${target} PUBLIC
  916. JUCE_STANDALONE_APPLICATION=JucePlugin_Build_Standalone
  917. JucePlugin_IsSynth=$<BOOL:$<TARGET_PROPERTY:${target},JUCE_IS_SYNTH>>
  918. JucePlugin_ManufacturerCode=0x${project_manufacturer_code}
  919. JucePlugin_Manufacturer="$<TARGET_PROPERTY:${target},JUCE_COMPANY_NAME>"
  920. JucePlugin_ManufacturerWebsite="$<TARGET_PROPERTY:${target},JUCE_COMPANY_WEBSITE>"
  921. JucePlugin_ManufacturerEmail="$<TARGET_PROPERTY:${target},JUCE_COMPANY_EMAIL>"
  922. JucePlugin_PluginCode=0x${project_plugin_code}
  923. JucePlugin_ProducesMidiOutput=$<BOOL:$<TARGET_PROPERTY:${target},JUCE_NEEDS_MIDI_OUTPUT>>
  924. JucePlugin_IsMidiEffect=$<BOOL:$<TARGET_PROPERTY:${target},JUCE_IS_MIDI_EFFECT>>
  925. JucePlugin_WantsMidiInput=$<BOOL:$<TARGET_PROPERTY:${target},JUCE_NEEDS_MIDI_INPUT>>
  926. JucePlugin_EditorRequiresKeyboardFocus=$<BOOL:$<TARGET_PROPERTY:${target},JUCE_EDITOR_WANTS_KEYBOARD_FOCUS>>
  927. JucePlugin_Name="$<TARGET_PROPERTY:${target},JUCE_PLUGIN_NAME>"
  928. JucePlugin_Desc="$<TARGET_PROPERTY:${target},JUCE_DESCRIPTION>"
  929. JucePlugin_Version=${project_version_string}
  930. JucePlugin_VersionString="${project_version_string}"
  931. JucePlugin_VersionCode=${project_version_hex}
  932. JucePlugin_VSTUniqueID=JucePlugin_PluginCode
  933. JucePlugin_VSTCategory=$<TARGET_PROPERTY:${target},JUCE_VST2_CATEGORY>
  934. JucePlugin_Vst3Category="${vst3_category_string}"
  935. JucePlugin_AUMainType=$<TARGET_PROPERTY:${target},JUCE_AU_MAIN_TYPE_CODE>
  936. JucePlugin_AUSubType=JucePlugin_PluginCode
  937. JucePlugin_AUExportPrefix=$<TARGET_PROPERTY:${target},JUCE_AU_EXPORT_PREFIX>
  938. JucePlugin_AUExportPrefixQuoted="$<TARGET_PROPERTY:${target},JUCE_AU_EXPORT_PREFIX>"
  939. JucePlugin_AUManufacturerCode=JucePlugin_ManufacturerCode
  940. JucePlugin_CFBundleIdentifier=$<TARGET_PROPERTY:${target},JUCE_BUNDLE_ID>
  941. JucePlugin_AAXIdentifier=$<TARGET_PROPERTY:${target},JUCE_AAX_IDENTIFIER>
  942. JucePlugin_AAXManufacturerCode=JucePlugin_ManufacturerCode
  943. JucePlugin_AAXProductId=JucePlugin_PluginCode
  944. JucePlugin_AAXCategory=$<TARGET_PROPERTY:${target},JUCE_AAX_CATEGORY>
  945. JucePlugin_AAXDisableBypass=$<BOOL:$<TARGET_PROPERTY:${target},JUCE_DISABLE_AAX_BYPASS>>
  946. JucePlugin_AAXDisableMultiMono=$<BOOL:$<TARGET_PROPERTY:${target},JUCE_DISABLE_AAX_MULTI_MONO>>
  947. JucePlugin_VSTNumMidiInputs=$<TARGET_PROPERTY:${target},JUCE_VST_NUM_MIDI_INS>
  948. JucePlugin_VSTNumMidiOutputs=$<TARGET_PROPERTY:${target},JUCE_VST_NUM_MIDI_OUTS>
  949. JucePlugin_Enable_ARA=$<BOOL:$<TARGET_PROPERTY:${target},JUCE_IS_ARA_EFFECT>>
  950. JucePlugin_ARAFactoryID=$<TARGET_PROPERTY:${target},JUCE_ARA_FACTORY_ID>
  951. JucePlugin_ARADocumentArchiveID=$<TARGET_PROPERTY:${target},JUCE_ARA_DOCUMENT_ARCHIVE_ID>
  952. JucePlugin_ARACompatibleArchiveIDs=$<TARGET_PROPERTY:${target},JUCE_ARA_COMPATIBLE_ARCHIVE_IDS>
  953. JucePlugin_ARAContentTypes=$<TARGET_PROPERTY:${target},JUCE_ARA_ANALYSIS_TYPES>
  954. JucePlugin_ARATransformationFlags=$<TARGET_PROPERTY:${target},JUCE_ARA_TRANSFORMATION_FLAGS>)
  955. set_target_properties(${target} PROPERTIES
  956. POSITION_INDEPENDENT_CODE TRUE
  957. INTERFACE_POSITION_INDEPENDENT_CODE TRUE
  958. VISIBILITY_INLINES_HIDDEN TRUE
  959. C_VISIBILITY_PRESET hidden
  960. CXX_VISIBILITY_PRESET hidden)
  961. # A convenience target for building all plugin variations at once
  962. add_custom_target(${target}_All)
  963. _juce_set_plugin_folder_property("${target}" "${target}_All")
  964. foreach(kind IN LISTS active_formats)
  965. _juce_link_plugin_wrapper(${target} ${kind})
  966. if(TARGET ${target}_${kind})
  967. list(APPEND active_plugin_targets ${target}_${kind})
  968. endif()
  969. endforeach()
  970. set_target_properties(${target} PROPERTIES JUCE_ACTIVE_PLUGIN_TARGETS "${active_plugin_targets}")
  971. if(TARGET ${target}_Standalone)
  972. _juce_configure_app_bundle(${target} ${target}_Standalone)
  973. endif()
  974. if(TARGET ${target}_AAX)
  975. target_link_libraries(${target}_AAX PRIVATE juce_aax_sdk)
  976. endif()
  977. if((TARGET ${target}_AUv3) AND (TARGET ${target}_Standalone))
  978. add_dependencies(${target}_Standalone ${target}_AUv3)
  979. # Copy the AUv3 into the Standalone app bundle
  980. _juce_copy_dir(${target}_Standalone
  981. "$<TARGET_BUNDLE_DIR:${target}_AUv3>"
  982. "$<TARGET_BUNDLE_CONTENT_DIR:${target}_Standalone>/PlugIns")
  983. endif()
  984. get_target_property(wants_copy "${target}" JUCE_COPY_PLUGIN_AFTER_BUILD)
  985. if(wants_copy)
  986. juce_enable_copy_plugin_step("${target}")
  987. endif()
  988. endfunction()
  989. # ==================================================================================================
  990. function(_juce_set_generic_property_if_not_set target property)
  991. list(LENGTH ARGN num_extra_args)
  992. if(num_extra_args EQUAL 0)
  993. return()
  994. endif()
  995. set(existing_property)
  996. get_target_property(existing_property ${target} ${property})
  997. if(existing_property STREQUAL "existing_property-NOTFOUND")
  998. set_target_properties(${target} PROPERTIES ${property} "${ARGN}")
  999. endif()
  1000. endfunction()
  1001. function(_juce_set_property_if_not_set target property)
  1002. _juce_set_generic_property_if_not_set(${target} JUCE_${property} ${ARGN})
  1003. endfunction()
  1004. function(_juce_make_valid_4cc out_var)
  1005. string(RANDOM LENGTH 1 ALPHABET "ABCDEFGHIJKLMNOPQRSTUVWXYZ" head)
  1006. string(RANDOM LENGTH 3 ALPHABET "abcdefghijklmnopqrstuvwxyz" tail)
  1007. set(${out_var} "${head}${tail}" PARENT_SCOPE)
  1008. endfunction()
  1009. # This function adds some default properties that plugin targets expect to be
  1010. # set, in order to generate the correct compile definitions.
  1011. function(_juce_set_fallback_properties target)
  1012. _juce_set_property_if_not_set(${target} PRODUCT_NAME ${target})
  1013. get_target_property(output_name ${target} JUCE_PRODUCT_NAME)
  1014. _juce_set_property_if_not_set(${target} DESCRIPTION "${output_name}")
  1015. _juce_set_property_if_not_set(${target} PLUGIN_NAME "${output_name}")
  1016. get_target_property(real_company_name ${target} JUCE_COMPANY_NAME)
  1017. _juce_set_property_if_not_set(${target} BUNDLE_ID "com.${real_company_name}.${target}")
  1018. _juce_set_property_if_not_set(${target} VERSION ${PROJECT_VERSION})
  1019. get_target_property(final_version ${target} JUCE_VERSION)
  1020. if(NOT final_version)
  1021. message(FATAL_ERROR "Target ${target} must have its VERSION argument set, or must be part of a project with a PROJECT_VERSION")
  1022. endif()
  1023. _juce_set_property_if_not_set(${target} BUILD_VERSION "${final_version}")
  1024. get_target_property(custom_xcassets ${target} JUCE_CUSTOM_XCASSETS_FOLDER)
  1025. get_target_property(custom_storyboard ${target} JUCE_LAUNCH_STORYBOARD_FILE)
  1026. set(needs_storyboard TRUE)
  1027. if((NOT custom_storyboard) AND custom_xcassets AND (EXISTS "${custom_xcassets}/LaunchImage.launchimage"))
  1028. set(needs_storyboard FALSE)
  1029. endif()
  1030. set_target_properties(${target} PROPERTIES JUCE_SHOULD_ADD_STORYBOARD ${needs_storyboard})
  1031. _juce_set_property_if_not_set(${target} IPHONE_SCREEN_ORIENTATIONS
  1032. UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft
  1033. UIInterfaceOrientationLandscapeRight)
  1034. _juce_set_property_if_not_set(${target} IPAD_SCREEN_ORIENTATIONS
  1035. UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft
  1036. UIInterfaceOrientationLandscapeRight)
  1037. _juce_set_property_if_not_set(${target}
  1038. LAUNCH_STORYBOARD_FILE "${JUCE_CMAKE_UTILS_DIR}/LaunchScreen.storyboard")
  1039. _juce_set_property_if_not_set(${target} PLUGIN_MANUFACTURER_CODE "Manu")
  1040. # The plugin code will change on each run, unless you specify one manually!
  1041. _juce_make_valid_4cc(random_code)
  1042. _juce_set_property_if_not_set(${target} PLUGIN_CODE ${random_code})
  1043. _juce_set_property_if_not_set(${target} IS_SYNTH FALSE)
  1044. _juce_set_property_if_not_set(${target} NEEDS_MIDI_INPUT FALSE)
  1045. _juce_set_property_if_not_set(${target} NEEDS_MIDI_OUTPUT FALSE)
  1046. _juce_set_property_if_not_set(${target} IS_MIDI_EFFECT FALSE)
  1047. _juce_set_property_if_not_set(${target} EDITOR_WANTS_KEYBOARD_FOCUS FALSE)
  1048. _juce_set_property_if_not_set(${target} DISABLE_AAX_BYPASS FALSE)
  1049. _juce_set_property_if_not_set(${target} DISABLE_AAX_MULTI_MONO FALSE)
  1050. _juce_set_property_if_not_set(${target} PLUGINHOST_AU FALSE)
  1051. get_target_property(bundle_id ${target} JUCE_BUNDLE_ID)
  1052. _juce_set_property_if_not_set(${target} AAX_IDENTIFIER ${bundle_id})
  1053. _juce_set_property_if_not_set(${target} VST_NUM_MIDI_INS 16)
  1054. _juce_set_property_if_not_set(${target} VST_NUM_MIDI_OUTS 16)
  1055. _juce_set_property_if_not_set(${target} AU_SANDBOX_SAFE FALSE)
  1056. _juce_set_property_if_not_set(${target} SUPPRESS_AU_PLIST_RESOURCE_USAGE FALSE)
  1057. _juce_set_property_if_not_set(${target} HARDENED_RUNTIME_ENABLED NO)
  1058. _juce_set_property_if_not_set(${target} APP_SANDBOX_ENABLED NO)
  1059. _juce_set_property_if_not_set(${target} APP_SANDBOX_INHERIT NO)
  1060. get_target_property(is_synth ${target} JUCE_IS_SYNTH)
  1061. # VST3_CATEGORIES
  1062. if(is_synth)
  1063. _juce_set_property_if_not_set(${target} VST3_CATEGORIES Instrument Synth)
  1064. else()
  1065. _juce_set_property_if_not_set(${target} VST3_CATEGORIES Fx)
  1066. endif()
  1067. # VST2_CATEGORY
  1068. if(is_synth)
  1069. _juce_set_property_if_not_set(${target} VST2_CATEGORY kPlugCategSynth)
  1070. else()
  1071. _juce_set_property_if_not_set(${target} VST2_CATEGORY kPlugCategEffect)
  1072. endif()
  1073. get_target_property(is_midi_effect ${target} JUCE_IS_MIDI_EFFECT)
  1074. get_target_property(needs_midi_input ${target} JUCE_NEEDS_MIDI_INPUT)
  1075. # AU MAIN TYPE
  1076. if(is_midi_effect)
  1077. _juce_set_property_if_not_set(${target} AU_MAIN_TYPE kAudioUnitType_MIDIProcessor)
  1078. elseif(is_synth)
  1079. _juce_set_property_if_not_set(${target} AU_MAIN_TYPE kAudioUnitType_MusicDevice)
  1080. elseif(needs_midi_input)
  1081. _juce_set_property_if_not_set(${target} AU_MAIN_TYPE kAudioUnitType_MusicEffect)
  1082. else()
  1083. _juce_set_property_if_not_set(${target} AU_MAIN_TYPE kAudioUnitType_Effect)
  1084. endif()
  1085. _juce_set_property_if_not_set(${target} TARGETED_DEVICE_FAMILY "1,2")
  1086. set(au_category_codes
  1087. 'aufx'
  1088. 'aufc'
  1089. 'augn'
  1090. 'aumi'
  1091. 'aumx'
  1092. 'aumu'
  1093. 'aumf'
  1094. 'auol'
  1095. 'auou'
  1096. 'aupn')
  1097. set(au_category_strings
  1098. kAudioUnitType_Effect
  1099. kAudioUnitType_FormatConverter
  1100. kAudioUnitType_Generator
  1101. kAudioUnitType_MIDIProcessor
  1102. kAudioUnitType_Mixer
  1103. kAudioUnitType_MusicDevice
  1104. kAudioUnitType_MusicEffect
  1105. kAudioUnitType_OfflineEffect
  1106. kAudioUnitType_Output
  1107. kAudioUnitType_Panner)
  1108. # AU export prefix
  1109. string(MAKE_C_IDENTIFIER ${output_name} au_prefix)
  1110. set(au_prefix "${au_prefix}AU")
  1111. _juce_set_property_if_not_set(${target} AU_EXPORT_PREFIX ${au_prefix})
  1112. # Find appropriate AU category code
  1113. get_target_property(actual_au_category ${target} JUCE_AU_MAIN_TYPE)
  1114. list(FIND au_category_strings ${actual_au_category} au_index)
  1115. if(au_index GREATER_EQUAL 0)
  1116. list(GET au_category_codes ${au_index} au_code_representation)
  1117. set_target_properties(${target} PROPERTIES JUCE_AU_MAIN_TYPE_CODE ${au_code_representation})
  1118. endif()
  1119. # AAX category
  1120. # The order of these strings is important, as the index of each string
  1121. # will be used to set an appropriate bit in the category bitfield.
  1122. set(aax_category_strings
  1123. ePlugInCategory_None
  1124. ePlugInCategory_EQ
  1125. ePlugInCategory_Dynamics
  1126. ePlugInCategory_PitchShift
  1127. ePlugInCategory_Reverb
  1128. ePlugInCategory_Delay
  1129. ePlugInCategory_Modulation
  1130. ePlugInCategory_Harmonic
  1131. ePlugInCategory_NoiseReduction
  1132. ePlugInCategory_Dither
  1133. ePlugInCategory_SoundField
  1134. ePlugInCategory_HWGenerators
  1135. ePlugInCategory_SWGenerators
  1136. ePlugInCategory_WrappedPlugin
  1137. ePlugInCategory_Effect)
  1138. if(is_synth)
  1139. set(default_aax_category ePlugInCategory_SWGenerators)
  1140. else()
  1141. set(default_aax_category ePlugInCategory_None)
  1142. endif()
  1143. _juce_set_property_if_not_set(${target} AAX_CATEGORY ${default_aax_category})
  1144. # Replace AAX category string with its integral representation
  1145. get_target_property(actual_aax_category ${target} JUCE_AAX_CATEGORY)
  1146. set(aax_category_int "")
  1147. foreach(category_string IN LISTS actual_aax_category)
  1148. list(FIND aax_category_strings ${category_string} aax_index)
  1149. if(aax_index GREATER_EQUAL 0)
  1150. if(aax_index EQUAL 0)
  1151. set(aax_category_bit 0)
  1152. else()
  1153. set(aax_category_bit "1 << (${aax_index} - 1)")
  1154. endif()
  1155. if(aax_category_int STREQUAL "")
  1156. set(aax_category_int 0)
  1157. endif()
  1158. math(EXPR aax_category_int "${aax_category_int} | (${aax_category_bit})")
  1159. endif()
  1160. endforeach()
  1161. if(NOT aax_category_int STREQUAL "")
  1162. set_target_properties(${target} PROPERTIES JUCE_AAX_CATEGORY ${aax_category_int})
  1163. endif()
  1164. # Ensure this matches the Projucer implementation
  1165. get_target_property(company_website ${target} JUCE_COMPANY_WEBSITE)
  1166. get_target_property(plugin_name ${target} JUCE_PLUGIN_NAME)
  1167. string(MAKE_C_IDENTIFIER "${plugin_name}" plugin_name_sanitised)
  1168. _juce_set_property_if_not_set(${target} LV2URI "${company_website}/plugins/${plugin_name_sanitised}")
  1169. # ARA configuration
  1170. # Analysis types
  1171. set(ara_analysis_type_strings
  1172. kARAContentTypeNotes
  1173. kARAContentTypeTempoEntries
  1174. kARAContentTypeBarSignatures
  1175. kARAContentTypeStaticTuning
  1176. kARAContentTypeKeySignatures
  1177. kARAContentTypeSheetChords)
  1178. get_target_property(actual_ara_analysis_types ${target} JUCE_ARA_ANALYSIS_TYPES)
  1179. set(ara_analysis_types_int "")
  1180. foreach(category_string IN LISTS actual_ara_analysis_types)
  1181. list(FIND ara_analysis_type_strings ${category_string} ara_index)
  1182. if(ara_index GREATER_EQUAL 0)
  1183. set(ara_analysis_types_bit "1 << ${ara_index}")
  1184. if(ara_analysis_types_int STREQUAL "")
  1185. set(ara_analysis_types_int 0)
  1186. endif()
  1187. math(EXPR ara_analysis_types_int "${ara_analysis_types_int} | (${ara_analysis_types_bit})")
  1188. endif()
  1189. endforeach()
  1190. if(NOT ara_analysis_types_int STREQUAL "")
  1191. set_target_properties(${target} PROPERTIES JUCE_ARA_ANALYSIS_TYPES ${ara_analysis_types_int})
  1192. endif()
  1193. _juce_set_property_if_not_set(${target} ARA_ANALYSIS_TYPES 0)
  1194. # Transformation flags
  1195. set(ara_transformation_flags_strings
  1196. kARAPlaybackTransformationNoChanges
  1197. kARAPlaybackTransformationTimestretch
  1198. kARAPlaybackTransformationTimestretchReflectingTempo
  1199. kARAPlaybackTransformationContentBasedFadeAtTail
  1200. kARAPlaybackTransformationContentBasedFadeAtHead)
  1201. set(default_ara_transformation_flags kARAPlaybackTransformationNoChanges)
  1202. _juce_set_property_if_not_set(${target} ARA_TRANSFORMATION_FLAGS ${default_ara_transformation_flags})
  1203. get_target_property(actual_ara_transformation_flags ${target} JUCE_ARA_TRANSFORMATION_FLAGS)
  1204. set(ara_transformation_flags_int "")
  1205. foreach(transformation_string IN LISTS actual_ara_transformation_flags)
  1206. list(FIND ara_transformation_flags_strings ${transformation_string} ara_transformation_index)
  1207. if(ara_transformation_index GREATER_EQUAL 0)
  1208. if(ara_transformation_index EQUAL 0)
  1209. set(ara_transformation_bit 0)
  1210. else()
  1211. set(ara_transformation_bit "1 << (${ara_transformation_index} - 1)")
  1212. endif()
  1213. if(ara_transformation_flags_int STREQUAL "")
  1214. set(ara_transformation_flags_int 0)
  1215. endif()
  1216. math(EXPR ara_transformation_flags_int "${ara_transformation_flags_int} | (${ara_transformation_bit})")
  1217. endif()
  1218. endforeach()
  1219. if(NOT ara_transformation_flags_int STREQUAL "")
  1220. set_target_properties(${target} PROPERTIES JUCE_ARA_TRANSFORMATION_FLAGS ${ara_transformation_flags_int})
  1221. endif()
  1222. _juce_set_property_if_not_set(${target} IS_ARA_EFFECT FALSE)
  1223. get_target_property(final_bundle_id ${target} JUCE_BUNDLE_ID)
  1224. _juce_set_property_if_not_set(${target} ARA_FACTORY_ID "\"${final_bundle_id}.arafactory.${final_version}\"")
  1225. _juce_set_property_if_not_set(${target} ARA_DOCUMENT_ARCHIVE_ID "\"${final_bundle_id}.aradocumentarchive.1\"")
  1226. _juce_set_property_if_not_set(${target} ARA_COMPATIBLE_ARCHIVE_IDS "\"\"")
  1227. endfunction()
  1228. # ==================================================================================================
  1229. function(_juce_initialise_target target)
  1230. set(one_value_args
  1231. VERSION
  1232. BUILD_VERSION
  1233. PRODUCT_NAME
  1234. PLIST_TO_MERGE
  1235. BUNDLE_ID
  1236. MICROPHONE_PERMISSION_ENABLED
  1237. MICROPHONE_PERMISSION_TEXT
  1238. CAMERA_PERMISSION_ENABLED
  1239. CAMERA_PERMISSION_TEXT
  1240. SEND_APPLE_EVENTS_PERMISSION_ENABLED
  1241. SEND_APPLE_EVENTS_PERMISSION_TEXT
  1242. BLUETOOTH_PERMISSION_ENABLED
  1243. BLUETOOTH_PERMISSION_TEXT
  1244. FILE_SHARING_ENABLED # iOS only
  1245. DOCUMENT_BROWSER_ENABLED # iOS only
  1246. LAUNCH_STORYBOARD_FILE # iOS only
  1247. APP_GROUPS_ENABLED # iOS only
  1248. ICLOUD_PERMISSIONS_ENABLED # iOS only
  1249. STATUS_BAR_HIDDEN # iOS only
  1250. BACKGROUND_AUDIO_ENABLED # iOS only
  1251. BACKGROUND_BLE_ENABLED # iOS only
  1252. CUSTOM_XCASSETS_FOLDER # iOS only
  1253. TARGETED_DEVICE_FAMILY # iOS only
  1254. REQUIRES_FULL_SCREEN # iOS only
  1255. ICON_BIG
  1256. ICON_SMALL
  1257. COMPANY_COPYRIGHT
  1258. COMPANY_NAME
  1259. COMPANY_WEBSITE
  1260. COMPANY_EMAIL
  1261. NEEDS_CURL # Set this true if you want to link curl on Linux
  1262. NEEDS_WEB_BROWSER # Set this true if you want to link webkit on Linux
  1263. NEEDS_STORE_KIT # Set this true if you want in-app-purchases on Mac
  1264. PUSH_NOTIFICATIONS_ENABLED
  1265. NETWORK_MULTICAST_ENABLED
  1266. HARDENED_RUNTIME_ENABLED
  1267. APP_SANDBOX_ENABLED
  1268. APP_SANDBOX_INHERIT
  1269. PLUGIN_NAME
  1270. PLUGIN_MANUFACTURER_CODE
  1271. PLUGIN_CODE
  1272. DESCRIPTION
  1273. IS_SYNTH
  1274. NEEDS_MIDI_INPUT
  1275. NEEDS_MIDI_OUTPUT
  1276. IS_MIDI_EFFECT
  1277. EDITOR_WANTS_KEYBOARD_FOCUS
  1278. DISABLE_AAX_BYPASS
  1279. DISABLE_AAX_MULTI_MONO
  1280. AAX_IDENTIFIER
  1281. VST_NUM_MIDI_INS
  1282. VST_NUM_MIDI_OUTS
  1283. VST2_CATEGORY
  1284. AU_MAIN_TYPE
  1285. AU_EXPORT_PREFIX
  1286. AU_SANDBOX_SAFE
  1287. SUPPRESS_AU_PLIST_RESOURCE_USAGE
  1288. PLUGINHOST_AU # Set this true if you want to host AU plugins
  1289. USE_LEGACY_COMPATIBILITY_PLUGIN_CODE
  1290. LV2URI
  1291. IS_ARA_EFFECT
  1292. ARA_FACTORY_ID
  1293. ARA_DOCUMENT_ARCHIVE_ID
  1294. VST_COPY_DIR
  1295. VST3_COPY_DIR
  1296. AAX_COPY_DIR
  1297. AU_COPY_DIR
  1298. UNITY_COPY_DIR
  1299. COPY_PLUGIN_AFTER_BUILD)
  1300. set(multi_value_args
  1301. FORMATS
  1302. VST3_CATEGORIES
  1303. HARDENED_RUNTIME_OPTIONS
  1304. APP_SANDBOX_OPTIONS
  1305. APP_SANDBOX_FILE_ACCESS_HOME_RO
  1306. APP_SANDBOX_FILE_ACCESS_HOME_RW
  1307. APP_SANDBOX_FILE_ACCESS_ABS_RO
  1308. APP_SANDBOX_FILE_ACCESS_ABS_RW
  1309. DOCUMENT_EXTENSIONS
  1310. AAX_CATEGORY
  1311. IPHONE_SCREEN_ORIENTATIONS # iOS only
  1312. IPAD_SCREEN_ORIENTATIONS # iOS only
  1313. APP_GROUP_IDS # iOS only
  1314. ARA_COMPATIBLE_ARCHIVE_IDS
  1315. ARA_ANALYSIS_TYPES
  1316. ARA_TRANSFORMATION_FLAGS)
  1317. cmake_parse_arguments(JUCE_ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN})
  1318. set(base_folder "${CMAKE_CURRENT_BINARY_DIR}/${target}_artefacts")
  1319. set(products_folder "${base_folder}/$<CONFIG>")
  1320. set(juce_library_code "${base_folder}/JuceLibraryCode")
  1321. set_target_properties(${target} PROPERTIES JUCE_GENERATED_SOURCES_DIRECTORY "${juce_library_code}")
  1322. set_target_properties(${target} PROPERTIES
  1323. ARCHIVE_OUTPUT_DIRECTORY "${products_folder}"
  1324. LIBRARY_OUTPUT_DIRECTORY "${products_folder}"
  1325. RUNTIME_OUTPUT_DIRECTORY "${products_folder}")
  1326. if(JUCE_ARG_ICON_BIG)
  1327. _juce_make_absolute_and_check(JUCE_ARG_ICON_BIG)
  1328. endif()
  1329. if(JUCE_ARG_ICON_SMALL)
  1330. _juce_make_absolute_and_check(JUCE_ARG_ICON_SMALL)
  1331. endif()
  1332. set(inherited_properties
  1333. COMPANY_NAME
  1334. COMPANY_WEBSITE
  1335. COMPANY_EMAIL
  1336. COMPANY_COPYRIGHT
  1337. VST_COPY_DIR
  1338. VST3_COPY_DIR
  1339. AU_COPY_DIR
  1340. AAX_COPY_DIR
  1341. UNITY_COPY_DIR
  1342. COPY_PLUGIN_AFTER_BUILD)
  1343. # Overwrite any properties that might be inherited
  1344. foreach(prop_string IN LISTS inherited_properties)
  1345. if(NOT ${JUCE_ARG_${prop_string}} STREQUAL "")
  1346. set_target_properties(${target} PROPERTIES JUCE_${prop_string} "${JUCE_ARG_${prop_string}}")
  1347. endif()
  1348. endforeach()
  1349. # Add each of the function arguments as target properties, so that it's easier to
  1350. # extract them in other functions
  1351. foreach(arg_string IN LISTS one_value_args multi_value_args)
  1352. _juce_set_property_if_not_set(${target} ${arg_string} "${JUCE_ARG_${arg_string}}")
  1353. endforeach()
  1354. _juce_set_fallback_properties(${target})
  1355. target_include_directories(${target} PRIVATE
  1356. $<TARGET_PROPERTY:${target},JUCE_GENERATED_SOURCES_DIRECTORY>)
  1357. target_link_libraries(${target} PUBLIC $<$<TARGET_EXISTS:juce_vst2_sdk>:juce_vst2_sdk>)
  1358. get_target_property(is_pluginhost_au ${target} JUCE_PLUGINHOST_AU)
  1359. if(is_pluginhost_au)
  1360. target_compile_definitions(${target} PUBLIC JUCE_PLUGINHOST_AU=1)
  1361. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
  1362. _juce_link_frameworks("${target}" PRIVATE CoreAudioKit)
  1363. endif()
  1364. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  1365. _juce_link_frameworks("${target}" PRIVATE AudioUnit)
  1366. endif()
  1367. endif()
  1368. _juce_write_generate_time_info(${target})
  1369. _juce_link_optional_libraries(${target})
  1370. _juce_fixup_module_source_groups()
  1371. endfunction()
  1372. # ==================================================================================================
  1373. function(_juce_add_lv2_manifest_helper_target)
  1374. if(TARGET juce_lv2_helper)
  1375. return()
  1376. endif()
  1377. get_target_property(module_path juce::juce_audio_plugin_client INTERFACE_JUCE_MODULE_PATH)
  1378. add_executable(juce_lv2_helper "${module_path}/juce_audio_plugin_client/LV2/juce_LV2TurtleDumpProgram.cpp")
  1379. add_executable(juce::juce_lv2_helper ALIAS juce_lv2_helper)
  1380. target_compile_features(juce_lv2_helper PRIVATE cxx_std_17)
  1381. set_target_properties(juce_lv2_helper PROPERTIES BUILD_WITH_INSTALL_RPATH ON)
  1382. target_link_libraries(juce_lv2_helper PRIVATE ${CMAKE_DL_LIBS})
  1383. endfunction()
  1384. # ==================================================================================================
  1385. function(juce_add_console_app target)
  1386. add_executable(${target})
  1387. target_compile_definitions(${target} PRIVATE JUCE_STANDALONE_APPLICATION=1)
  1388. if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  1389. target_compile_definitions(${target} PRIVATE _CONSOLE=1)
  1390. endif()
  1391. _juce_initialise_target(${target} ${ARGN})
  1392. endfunction()
  1393. function(juce_add_gui_app target)
  1394. if(CMAKE_SYSTEM_NAME STREQUAL "Android")
  1395. add_library(${target} SHARED)
  1396. else()
  1397. add_executable(${target})
  1398. endif()
  1399. target_compile_definitions(${target} PRIVATE JUCE_STANDALONE_APPLICATION=1)
  1400. _juce_initialise_target(${target} ${ARGN})
  1401. _juce_set_output_name(${target} $<TARGET_PROPERTY:${target},JUCE_PRODUCT_NAME>)
  1402. set_target_properties(${target} PROPERTIES JUCE_TARGET_KIND_STRING "App")
  1403. _juce_configure_bundle(${target} ${target})
  1404. _juce_configure_app_bundle(${target} ${target})
  1405. endfunction()
  1406. function(juce_add_plugin target)
  1407. add_library(${target} STATIC)
  1408. set_target_properties(${target} PROPERTIES JUCE_IS_PLUGIN TRUE)
  1409. _juce_initialise_target(${target} ${ARGN})
  1410. _juce_configure_plugin_targets(${target})
  1411. endfunction()
  1412. # ==================================================================================================
  1413. function(_juce_target_args_from_plugin_characteristics out_var)
  1414. set(pairs
  1415. "pluginIsSynth\;IS_SYNTH"
  1416. "pluginWantsMidiIn\;NEEDS_MIDI_INPUT"
  1417. "pluginProducesMidiOut\;NEEDS_MIDI_OUTPUT"
  1418. "pluginIsMidiEffectPlugin\;IS_MIDI_EFFECT"
  1419. "pluginEditorRequiresKeys\;EDITOR_WANTS_KEYBOARD_FOCUS")
  1420. set(result)
  1421. foreach(pair IN LISTS pairs)
  1422. list(GET pair 0 old_key)
  1423. if("${old_key}" IN_LIST ARGN)
  1424. list(GET pair 1 new_key)
  1425. list(APPEND result ${new_key} TRUE)
  1426. endif()
  1427. endforeach()
  1428. set(${out_var} ${result} PARENT_SCOPE)
  1429. endfunction()
  1430. # ==================================================================================================
  1431. function(_juce_get_pip_targets pip out_var)
  1432. set(test_targets "${pip}")
  1433. _juce_get_all_plugin_kinds(plugin_kinds)
  1434. foreach(plugin_kind IN LISTS plugin_kinds)
  1435. list(APPEND test_targets "${JUCE_PIP_NAME}_${plugin_kind}")
  1436. endforeach()
  1437. set(${out_var} ${test_targets} PARENT_SCOPE)
  1438. endfunction()
  1439. function(juce_add_pip header)
  1440. _juce_make_absolute(header)
  1441. _juce_extract_metadata_block(JUCE_PIP_METADATA "${header}" metadata_dict)
  1442. _juce_get_metadata("${metadata_dict}" name JUCE_PIP_NAME)
  1443. if(NOT JUCE_PIP_NAME)
  1444. message(FATAL_ERROR "Error in '${header}': PIP headers must declare a `name` field")
  1445. endif()
  1446. string(MAKE_C_IDENTIFIER "${JUCE_PIP_NAME}" pip_name_sanitised)
  1447. if(NOT JUCE_PIP_NAME STREQUAL pip_name_sanitised)
  1448. message(FATAL_ERROR "Error in '${header}': PIP `name` value '${JUCE_PIP_NAME}' must be a valid C identifier")
  1449. endif()
  1450. if(TARGET "${JUCE_PIP_NAME}")
  1451. # We already added a target with this name, let's try using the filename instead
  1452. get_filename_component(JUCE_PIP_NAME "${header}" NAME_WE)
  1453. endif()
  1454. if(TARGET "${JUCE_PIP_NAME}")
  1455. message(FATAL_ERROR "Error in '${header}': Could not create a unique target name for PIP ${header}")
  1456. endif()
  1457. _juce_get_metadata("${metadata_dict}" type pip_kind)
  1458. if(NOT pip_kind)
  1459. message(FATAL_ERROR "Error in '${header}': PIP headers must declare a `type` field")
  1460. endif()
  1461. _juce_get_metadata("${metadata_dict}" pluginCharacteristics pip_charateristics)
  1462. _juce_target_args_from_plugin_characteristics(extra_target_args ${pip_charateristics})
  1463. list(APPEND extra_target_args
  1464. NEEDS_CURL TRUE
  1465. NEEDS_WEB_BROWSER TRUE)
  1466. _juce_get_metadata("${metadata_dict}" moduleFlags pip_moduleflags)
  1467. if("JUCE_IN_APP_PURCHASES=1" IN_LIST pip_moduleflags)
  1468. list(APPEND extra_target_args
  1469. BUNDLE_ID "com.rmsl.juceInAppPurchaseSample"
  1470. NEEDS_STORE_KIT TRUE)
  1471. endif()
  1472. if("JUCE_PLUGINHOST_AU=1" IN_LIST pip_moduleflags)
  1473. list(APPEND extra_target_args PLUGINHOST_AU TRUE)
  1474. endif()
  1475. if(pip_kind STREQUAL "AudioProcessor")
  1476. _juce_get_metadata("${metadata_dict}" documentControllerClass JUCE_PIP_DOCUMENTCONTROLLER_CLASS)
  1477. if(JUCE_PIP_DOCUMENTCONTROLLER_CLASS)
  1478. if(NOT TARGET juce_ara_sdk)
  1479. message(WARNING
  1480. "${header} specifies a documentControllerClass, but the ARA SDK could not be located. "
  1481. "Use juce_set_ara_sdk_path to specify the ARA SDK location. "
  1482. "This PIP will not be configured.")
  1483. endif()
  1484. set(source_main "${JUCE_CMAKE_UTILS_DIR}/PIPAudioProcessorWithARA.cpp.in")
  1485. juce_add_plugin(${JUCE_PIP_NAME}
  1486. FORMATS AU VST3
  1487. IS_ARA_EFFECT TRUE
  1488. ${extra_target_args})
  1489. else()
  1490. set(source_main "${JUCE_CMAKE_UTILS_DIR}/PIPAudioProcessor.cpp.in")
  1491. # We add AAX/VST2 targets too, if the user has set up those SDKs
  1492. set(extra_formats)
  1493. if(TARGET juce_aax_sdk)
  1494. list(APPEND extra_formats AAX)
  1495. endif()
  1496. if(TARGET juce_vst2_sdk)
  1497. list(APPEND extra_formats VST)
  1498. endif()
  1499. # Standalone plugins might want to access the mic
  1500. list(APPEND extra_target_args MICROPHONE_PERMISSION_ENABLED TRUE)
  1501. juce_add_plugin(${JUCE_PIP_NAME}
  1502. FORMATS AU AUv3 LV2 Standalone Unity VST3 ${extra_formats}
  1503. ${extra_target_args})
  1504. endif()
  1505. elseif(pip_kind STREQUAL "Component")
  1506. set(source_main "${JUCE_CMAKE_UTILS_DIR}/PIPComponent.cpp.in")
  1507. juce_add_gui_app(${JUCE_PIP_NAME} ${extra_target_args})
  1508. elseif(pip_kind STREQUAL "Console")
  1509. set(source_main "${JUCE_CMAKE_UTILS_DIR}/PIPConsole.cpp.in")
  1510. juce_add_console_app(${JUCE_PIP_NAME} ${extra_target_args})
  1511. else()
  1512. message(FATAL_ERROR "Error in '${header}': PIP kind must be either AudioProcessor, Component, or Console")
  1513. endif()
  1514. if(NOT ARGV1 STREQUAL "")
  1515. set("${ARGV1}" "${JUCE_PIP_NAME}" PARENT_SCOPE)
  1516. endif()
  1517. # Generate Main.cpp
  1518. _juce_get_metadata("${metadata_dict}" mainClass JUCE_PIP_MAIN_CLASS)
  1519. get_target_property(juce_library_code ${JUCE_PIP_NAME} JUCE_GENERATED_SOURCES_DIRECTORY)
  1520. set(pip_main "${juce_library_code}/Main.cpp")
  1521. set(JUCE_PIP_HEADER "${header}")
  1522. configure_file(${source_main} ${pip_main})
  1523. target_sources(${JUCE_PIP_NAME} PRIVATE ${pip_main})
  1524. _juce_get_metadata("${metadata_dict}" dependencies pip_dependencies)
  1525. juce_generate_juce_header(${JUCE_PIP_NAME})
  1526. foreach(module IN LISTS pip_dependencies)
  1527. if(module STREQUAL "")
  1528. continue()
  1529. endif()
  1530. set(discovered_module)
  1531. if(TARGET "${module}")
  1532. set(discovered_module "${module}")
  1533. else()
  1534. message(FATAL_ERROR "Error in '${header}': No such module: ${module}")
  1535. endif()
  1536. target_link_libraries(${JUCE_PIP_NAME} PRIVATE ${discovered_module})
  1537. endforeach()
  1538. target_compile_definitions(${JUCE_PIP_NAME}
  1539. PRIVATE ${pip_moduleflags}
  1540. PUBLIC
  1541. JUCE_VST3_CAN_REPLACE_VST2=0)
  1542. _juce_get_pip_targets(${JUCE_PIP_NAME} pip_targets)
  1543. # This keeps the PIPs slightly better organised in the JUCE megaproject
  1544. if((DEFINED JUCE_SOURCE_DIR) AND (header MATCHES "^${JUCE_SOURCE_DIR}"))
  1545. file(RELATIVE_PATH folder "${JUCE_SOURCE_DIR}" "${header}")
  1546. get_filename_component(folder_parent "${folder}" DIRECTORY)
  1547. foreach(target_name IN ITEMS ${pip_targets} ${JUCE_PIP_NAME}_All)
  1548. if(TARGET "${target_name}")
  1549. set_target_properties("${target_name}" PROPERTIES
  1550. FOLDER "${folder_parent}/${JUCE_PIP_NAME}")
  1551. endif()
  1552. endforeach()
  1553. endif()
  1554. # We're building JUCE itself
  1555. if(DEFINED JUCE_SOURCE_DIR)
  1556. # PIPs need to know about the resources folder
  1557. target_compile_definitions(${JUCE_PIP_NAME} PRIVATE
  1558. PIP_JUCE_EXAMPLES_DIRECTORY_STRING="${JUCE_SOURCE_DIR}/examples")
  1559. get_filename_component(pip_parent_path "${header}" DIRECTORY)
  1560. target_include_directories(${JUCE_PIP_NAME} PRIVATE "${pip_parent_path}")
  1561. if((CMAKE_SYSTEM_NAME STREQUAL "iOS") AND (header MATCHES "^${JUCE_SOURCE_DIR}"))
  1562. foreach(target_name IN LISTS pip_targets)
  1563. if(TARGET "${target_name}")
  1564. juce_add_bundle_resources_directory("${target_name}" "${JUCE_SOURCE_DIR}/examples/Assets")
  1565. endif()
  1566. endforeach()
  1567. endif()
  1568. endif()
  1569. endfunction()
  1570. # ==================================================================================================
  1571. function(juce_set_aax_sdk_path path)
  1572. if(TARGET juce_aax_sdk)
  1573. message(FATAL_ERROR "juce_set_aax_sdk_path should only be called once")
  1574. endif()
  1575. _juce_make_absolute(path)
  1576. if((NOT EXISTS "${path}")
  1577. OR (NOT EXISTS "${path}/Interfaces")
  1578. OR (NOT EXISTS "${path}/Interfaces/ACF"))
  1579. message(FATAL_ERROR "Could not find AAX SDK at the specified path: ${path}")
  1580. endif()
  1581. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  1582. add_library(juce_aax_sdk STATIC IMPORTED GLOBAL)
  1583. set_target_properties(juce_aax_sdk PROPERTIES
  1584. IMPORTED_LOCATION_DEBUG "${path}/Libs/Debug/libAAXLibrary_libcpp.a"
  1585. IMPORTED_LOCATION "${path}/Libs/Release/libAAXLibrary_libcpp.a")
  1586. elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  1587. add_library(juce_aax_sdk INTERFACE IMPORTED GLOBAL)
  1588. else()
  1589. return()
  1590. endif()
  1591. target_include_directories(juce_aax_sdk INTERFACE
  1592. "${path}"
  1593. "${path}/Interfaces"
  1594. "${path}/Interfaces/ACF")
  1595. target_compile_definitions(juce_aax_sdk INTERFACE JucePlugin_AAXLibs_path="${path}/Libs")
  1596. set_target_properties(juce_aax_sdk PROPERTIES INTERFACE_JUCE_AAX_DEFAULT_ICON "${path}/Utilities/PlugIn.ico")
  1597. endfunction()
  1598. function(juce_set_vst2_sdk_path path)
  1599. if(TARGET juce_vst2_sdk)
  1600. message(FATAL_ERROR "juce_set_vst2_sdk_path should only be called once")
  1601. endif()
  1602. _juce_make_absolute(path)
  1603. if(NOT EXISTS "${path}")
  1604. message(FATAL_ERROR "Could not find VST2 SDK at the specified path: ${path}")
  1605. endif()
  1606. add_library(juce_vst2_sdk INTERFACE IMPORTED GLOBAL)
  1607. # This is a bit of a hack, but we really need the VST2 paths to always follow the VST3 paths.
  1608. target_include_directories(juce_vst2_sdk INTERFACE
  1609. $<TARGET_PROPERTY:juce::juce_vst3_headers,INTERFACE_INCLUDE_DIRECTORIES>
  1610. "${path}")
  1611. endfunction()
  1612. function(juce_set_vst3_sdk_path path)
  1613. if(TARGET juce_vst3_sdk)
  1614. message(FATAL_ERROR "juce_set_vst3_sdk_path should only be called once")
  1615. endif()
  1616. _juce_make_absolute(path)
  1617. if(NOT EXISTS "${path}")
  1618. message(FATAL_ERROR "Could not find VST3 SDK at the specified path: ${path}")
  1619. endif()
  1620. add_library(juce_vst3_sdk INTERFACE IMPORTED GLOBAL)
  1621. target_include_directories(juce_vst3_sdk INTERFACE "${path}")
  1622. endfunction()
  1623. function(juce_set_ara_sdk_path path)
  1624. if(TARGET juce_ara_sdk)
  1625. message(FATAL_ERROR "juce_set_ara_sdk_path should only be called once")
  1626. endif()
  1627. _juce_make_absolute(path)
  1628. if(NOT EXISTS "${path}")
  1629. message(FATAL_ERROR "Could not find ARA SDK at the specified path: ${path}")
  1630. endif()
  1631. add_library(juce_ara_sdk INTERFACE IMPORTED GLOBAL)
  1632. target_include_directories(juce_ara_sdk INTERFACE "${path}")
  1633. endfunction()
  1634. # ==================================================================================================
  1635. function(juce_disable_default_flags)
  1636. set(langs C CXX)
  1637. set(modes DEBUG RELEASE RELWITHDEBINFO MINSIZEREL)
  1638. foreach(lang IN LISTS langs)
  1639. foreach(mode IN LISTS modes)
  1640. list(FILTER CMAKE_${lang}_FLAGS_${mode} INCLUDE REGEX "[/-]M[TD]d?")
  1641. set(CMAKE_${lang}_FLAGS_${mode} "${CMAKE_${lang}_FLAGS_${mode}}" PARENT_SCOPE)
  1642. endforeach()
  1643. endforeach()
  1644. endfunction()