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.

2184 lines
87KB

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