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.

2206 lines
89KB

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