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.

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