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.

2085 lines
84KB

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