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.

2286 lines
91KB

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