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.

2087 lines
86KB

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