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.

2248 lines
90KB

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