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.

2351 lines
94KB

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