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.

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