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.

2340 lines
93KB

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