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.

2433 lines
97KB

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