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.

2395 lines
95KB

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