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.

2207 lines
88KB

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