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.

2440 lines
97KB

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