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.

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