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.

2015 lines
82KB

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