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.

2297 lines
92KB

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