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.

2166 lines
86KB

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