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.

2172 lines
90KB

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