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.

2115 lines
87KB

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