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.

654 lines
26KB

  1. # ==============================================================================
  2. #
  3. # This file is part of the JUCE 7 technical preview.
  4. # Copyright (c) 2022 - Raw Material Software Limited
  5. #
  6. # You may use this code under the terms of the GPL v3
  7. # (see www.gnu.org/licenses).
  8. #
  9. # For the technical preview this file cannot be licensed commercially.
  10. #
  11. # JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  12. # EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  13. # DISCLAIMED.
  14. #
  15. # ==============================================================================
  16. # ==================================================================================================
  17. # JUCE Modules Support Helper Functions
  18. #
  19. # In this file, functions intended for use by end-users have the prefix `juce_`.
  20. # Functions beginning with an underscore should be considered private and susceptible to
  21. # change, so don't call them directly.
  22. #
  23. # See the readme at `docs/CMake API.md` for more information about CMake usage,
  24. # including documentation of the public functions in this file.
  25. # ==================================================================================================
  26. include_guard(GLOBAL)
  27. cmake_minimum_required(VERSION 3.15)
  28. # ==================================================================================================
  29. set(JUCE_CMAKE_UTILS_DIR ${CMAKE_CURRENT_LIST_DIR}
  30. CACHE INTERNAL "The path to the folder holding this file and other resources")
  31. include("${JUCE_CMAKE_UTILS_DIR}/JUCEHelperTargets.cmake")
  32. include("${JUCE_CMAKE_UTILS_DIR}/JUCECheckAtomic.cmake")
  33. # Tries to discover the target platform architecture, which is necessary for
  34. # naming VST3 bundle folders and including bundled libraries from modules
  35. function(_juce_find_target_architecture result)
  36. set(test_file "${JUCE_CMAKE_UTILS_DIR}/juce_runtime_arch_detection.cpp")
  37. try_compile(compile_result "${CMAKE_CURRENT_BINARY_DIR}" "${test_file}"
  38. OUTPUT_VARIABLE compile_output)
  39. string(REGEX REPLACE ".*JUCE_ARCH ([a-zA-Z0-9_-]*).*" "\\1" match_result "${compile_output}")
  40. set("${result}" "${match_result}" PARENT_SCOPE)
  41. endfunction()
  42. if((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD") OR MSYS OR MINGW)
  43. # If you really need to override the detected arch for some reason,
  44. # you can configure the build with -DJUCE_TARGET_ARCHITECTURE=<custom arch>
  45. if(NOT DEFINED JUCE_TARGET_ARCHITECTURE)
  46. _juce_find_target_architecture(target_arch)
  47. set(JUCE_TARGET_ARCHITECTURE "${target_arch}"
  48. CACHE INTERNAL "The target architecture, used to name internal folders in VST3 bundles, and to locate bundled libraries in modules")
  49. endif()
  50. endif()
  51. # ==================================================================================================
  52. function(_juce_add_interface_library target)
  53. add_library(${target} INTERFACE)
  54. target_sources(${target} INTERFACE ${ARGN})
  55. endfunction()
  56. # ==================================================================================================
  57. function(_juce_add_standard_defs juce_target)
  58. target_compile_definitions(${juce_target} INTERFACE
  59. JUCE_GLOBAL_MODULE_SETTINGS_INCLUDED=1
  60. $<IF:$<CONFIG:DEBUG>,DEBUG=1 _DEBUG=1,NDEBUG=1 _NDEBUG=1>
  61. $<$<PLATFORM_ID:Android>:JUCE_ANDROID=1>)
  62. endfunction()
  63. # ==================================================================================================
  64. macro(_juce_make_absolute path)
  65. if(NOT IS_ABSOLUTE "${${path}}")
  66. get_filename_component("${path}" "${${path}}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}")
  67. endif()
  68. endmacro()
  69. macro(_juce_make_absolute_and_check path)
  70. _juce_make_absolute("${path}")
  71. if(NOT EXISTS "${${path}}")
  72. message(FATAL_ERROR "No file at path ${${path}}")
  73. endif()
  74. endmacro()
  75. # ==================================================================================================
  76. # This creates an imported interface library with a random name, and then adds
  77. # the fields from a JUCE module header to the target as INTERFACE_ properties.
  78. # We can extract properties later using `_juce_get_metadata`.
  79. # This way, the interface library ends up behaving a bit like a dictionary,
  80. # and we don't have to parse the module header from scratch every time we
  81. # want to find a specific key.
  82. function(_juce_extract_metadata_block delim_str file_with_block out_dict)
  83. string(RANDOM LENGTH 16 random_string)
  84. set(target_name "${random_string}_dict")
  85. set(${out_dict} "${target_name}" PARENT_SCOPE)
  86. add_library(${target_name} INTERFACE IMPORTED)
  87. if(NOT EXISTS ${file_with_block})
  88. message(FATAL_ERROR "Unable to find file ${file_with_block}")
  89. endif()
  90. file(STRINGS ${file_with_block} module_header_contents)
  91. set(last_written_key)
  92. set(append NO)
  93. foreach(line IN LISTS module_header_contents)
  94. if(NOT append)
  95. if(line MATCHES "[\t ]*BEGIN_${delim_str}[\t ]*")
  96. set(append YES)
  97. endif()
  98. continue()
  99. endif()
  100. if(append AND (line MATCHES "[\t ]*END_${delim_str}[\t ]*"))
  101. break()
  102. endif()
  103. if(line MATCHES "^[\t ]*([a-zA-Z]+):")
  104. set(last_written_key "${CMAKE_MATCH_1}")
  105. endif()
  106. string(REGEX REPLACE "^[\t ]*${last_written_key}:[\t ]*" "" line "${line}")
  107. string(REGEX REPLACE "[\t ,]+" ";" line "${line}")
  108. set_property(TARGET ${target_name} APPEND PROPERTY
  109. "INTERFACE_JUCE_${last_written_key}" "${line}")
  110. endforeach()
  111. endfunction()
  112. # Fetches properties attached to a metadata target.
  113. function(_juce_get_metadata target key out_var)
  114. get_target_property(content "${target}" "INTERFACE_JUCE_${key}")
  115. if(NOT "${content}" STREQUAL "content-NOTFOUND")
  116. set(${out_var} "${content}" PARENT_SCOPE)
  117. endif()
  118. endfunction()
  119. # ==================================================================================================
  120. function(_juce_should_build_module_source filename output_var)
  121. get_filename_component(trimmed_name "${filename}" NAME_WE)
  122. set(result TRUE)
  123. set(pairs
  124. "OSX\;Darwin"
  125. "Windows\;Windows"
  126. "Linux\;Linux"
  127. "Android\;Android"
  128. "iOS\;iOS")
  129. foreach(pair IN LISTS pairs)
  130. list(GET pair 0 suffix)
  131. list(GET pair 1 system_name)
  132. if((trimmed_name MATCHES "_${suffix}$") AND NOT (CMAKE_SYSTEM_NAME STREQUAL "${system_name}"))
  133. set(result FALSE)
  134. endif()
  135. endforeach()
  136. set("${output_var}" "${result}" PARENT_SCOPE)
  137. endfunction()
  138. function(_juce_module_sources module_path output_path built_sources other_sources)
  139. get_filename_component(module_parent_path ${module_path} DIRECTORY)
  140. get_filename_component(module_glob ${module_path} NAME)
  141. file(GLOB_RECURSE all_module_files
  142. CONFIGURE_DEPENDS LIST_DIRECTORIES FALSE
  143. RELATIVE "${module_parent_path}"
  144. "${module_path}/*")
  145. set(base_path "${module_glob}/${module_glob}")
  146. set(module_cpp ${all_module_files})
  147. list(FILTER module_cpp INCLUDE REGEX "^${base_path}[^/]*\\.(c|cc|cpp|cxx|s|asm)$")
  148. if(APPLE)
  149. set(module_mm ${all_module_files})
  150. list(FILTER module_mm INCLUDE REGEX "^${base_path}[^/]*\\.mm$")
  151. if(module_mm)
  152. set(module_mm_replaced ${module_mm})
  153. list(TRANSFORM module_mm_replaced REPLACE "\\.mm$" ".cpp")
  154. list(REMOVE_ITEM module_cpp ${module_mm_replaced})
  155. endif()
  156. set(module_apple_files ${all_module_files})
  157. list(FILTER module_apple_files INCLUDE REGEX "${base_path}[^/]*\\.(m|mm|metal|r|swift)$")
  158. list(APPEND module_cpp ${module_apple_files})
  159. endif()
  160. set(headers ${all_module_files})
  161. set(module_files_to_build)
  162. foreach(filename IN LISTS module_cpp)
  163. _juce_should_build_module_source("${filename}" should_build_file)
  164. if(should_build_file)
  165. list(APPEND module_files_to_build "${filename}")
  166. endif()
  167. endforeach()
  168. if(NOT "${module_files_to_build}" STREQUAL "")
  169. list(REMOVE_ITEM headers ${module_files_to_build})
  170. endif()
  171. foreach(source_list IN ITEMS module_files_to_build headers)
  172. list(TRANSFORM ${source_list} PREPEND "${output_path}/")
  173. endforeach()
  174. set(${built_sources} ${module_files_to_build} PARENT_SCOPE)
  175. set(${other_sources} ${headers} PARENT_SCOPE)
  176. endfunction()
  177. # ==================================================================================================
  178. function(_juce_get_all_plugin_kinds out)
  179. set(${out} AU AUv3 AAX LV2 Standalone Unity VST VST3 PARENT_SCOPE)
  180. endfunction()
  181. function(_juce_get_platform_plugin_kinds out)
  182. set(result Standalone)
  183. if(APPLE AND (CMAKE_GENERATOR STREQUAL "Xcode"))
  184. list(APPEND result AUv3)
  185. endif()
  186. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  187. list(APPEND result AU)
  188. endif()
  189. if(NOT CMAKE_SYSTEM_NAME STREQUAL "iOS" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
  190. list(APPEND result AAX Unity VST VST3 LV2)
  191. endif()
  192. set(${out} ${result} PARENT_SCOPE)
  193. endfunction()
  194. function(_juce_add_plugin_definitions target visibility)
  195. _juce_get_all_plugin_kinds(options)
  196. cmake_parse_arguments(JUCE_ARG "${options}" "" "" ${ARGN})
  197. foreach(opt IN LISTS options)
  198. set(flag_value 0)
  199. if(JUCE_ARG_${opt})
  200. set(flag_value 1)
  201. endif()
  202. target_compile_definitions(${target} ${visibility} "JucePlugin_Build_${opt}=${flag_value}")
  203. endforeach()
  204. endfunction()
  205. # ==================================================================================================
  206. # Takes a target, a link visibility, if it should be a weak link, and a variable-length list of
  207. # framework names. On macOS, for non-weak links, this finds the requested frameworks using
  208. # `find_library`.
  209. function(_juce_link_frameworks target visibility)
  210. set(options WEAK)
  211. cmake_parse_arguments(JUCE_LINK_FRAMEWORKS "${options}" "" "" ${ARGN})
  212. foreach(framework IN LISTS JUCE_LINK_FRAMEWORKS_UNPARSED_ARGUMENTS)
  213. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  214. if(JUCE_LINK_FRAMEWORKS_WEAK)
  215. set(framework_flags "-weak_framework ${framework}")
  216. else()
  217. find_library("juce_found_${framework}" "${framework}" REQUIRED)
  218. set(framework_flags "${juce_found_${framework}}")
  219. endif()
  220. elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
  221. # CoreServices is only available on iOS 12+, we must link it weakly on earlier platforms
  222. if(JUCE_LINK_FRAMEWORKS_WEAK OR ((framework STREQUAL "CoreServices") AND (CMAKE_OSX_DEPLOYMENT_TARGET LESS 12.0)))
  223. set(framework_flags "-weak_framework ${framework}")
  224. else()
  225. set(framework_flags "-framework ${framework}")
  226. endif()
  227. endif()
  228. if(NOT framework_flags STREQUAL "")
  229. target_link_libraries("${target}" "${visibility}" "${framework_flags}")
  230. endif()
  231. endforeach()
  232. endfunction()
  233. # ==================================================================================================
  234. function(_juce_add_plugin_wrapper_target format path out_path)
  235. _juce_module_sources("${path}" "${out_path}" out_var headers)
  236. list(FILTER out_var EXCLUDE REGEX "/juce_audio_plugin_client_utils.cpp$")
  237. set(target_name juce_audio_plugin_client_${format})
  238. _juce_add_interface_library("${target_name}" ${out_var})
  239. _juce_add_plugin_definitions("${target_name}" INTERFACE ${format})
  240. _juce_add_standard_defs("${target_name}")
  241. target_compile_features("${target_name}" INTERFACE cxx_std_14)
  242. add_library("juce::${target_name}" ALIAS "${target_name}")
  243. if(format STREQUAL "AUv3")
  244. _juce_link_frameworks("${target_name}" INTERFACE AVFoundation)
  245. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  246. _juce_link_frameworks("${target_name}" INTERFACE AudioUnit)
  247. endif()
  248. elseif(format STREQUAL "AU")
  249. _juce_link_frameworks("${target_name}" INTERFACE AudioUnit CoreAudioKit)
  250. endif()
  251. endfunction()
  252. # ==================================================================================================
  253. function(_juce_link_libs_from_metadata module_name dict key)
  254. _juce_get_metadata("${dict}" "${key}" libs)
  255. if(libs)
  256. target_link_libraries(${module_name} INTERFACE ${libs})
  257. endif()
  258. endfunction()
  259. # ==================================================================================================
  260. function(_juce_create_pkgconfig_target name)
  261. if(TARGET juce::pkgconfig_${name})
  262. return()
  263. endif()
  264. find_package(PkgConfig REQUIRED)
  265. pkg_check_modules(${name} ${ARGN})
  266. add_library(pkgconfig_${name} INTERFACE)
  267. add_library(juce::pkgconfig_${name} ALIAS pkgconfig_${name})
  268. install(TARGETS pkgconfig_${name} EXPORT JUCE)
  269. set(pairs
  270. "INCLUDE_DIRECTORIES\;INCLUDE_DIRS"
  271. "LINK_LIBRARIES\;LINK_LIBRARIES"
  272. "LINK_OPTIONS\;LDFLAGS_OTHER"
  273. "COMPILE_OPTIONS\;CFLAGS_OTHER")
  274. foreach(pair IN LISTS pairs)
  275. list(GET pair 0 key)
  276. list(GET pair 1 value)
  277. if(${name}_${value})
  278. set_target_properties(pkgconfig_${name} PROPERTIES INTERFACE_${key} "${${name}_${value}}")
  279. endif()
  280. endforeach()
  281. endfunction()
  282. # ==================================================================================================
  283. function(_juce_add_library_path target path)
  284. if(EXISTS "${path}")
  285. target_link_directories(${target} INTERFACE ${path})
  286. endif()
  287. endfunction()
  288. function(_juce_add_module_staticlib_paths module_target module_path)
  289. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  290. _juce_add_library_path(${module_target} "${module_path}/libs/MacOSX")
  291. elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
  292. _juce_add_library_path(${module_target} "${module_path}/libs/iOS")
  293. elseif((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD"))
  294. _juce_add_library_path(${module_target} "${module_path}/libs/Linux/${JUCE_TARGET_ARCHITECTURE}")
  295. elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  296. if(CMAKE_GENERATOR MATCHES "Visual Studio [0-9]+ (20[0-9]+)")
  297. set(arch "$<IF:$<EQUAL:${CMAKE_SIZEOF_VOID_P},8>,x64,Win32>")
  298. if(NOT CMAKE_GENERATOR_PLATFORM STREQUAL "")
  299. set(arch ${CMAKE_GENERATOR_PLATFORM})
  300. endif()
  301. set(runtime_lib "$<GENEX_EVAL:$<TARGET_PROPERTY:MSVC_RUNTIME_LIBRARY>>")
  302. set(subfolder "MDd")
  303. set(subfolder "$<IF:$<STREQUAL:${runtime_lib},MultiThreadedDebug>,MTd,${subfolder}>")
  304. set(subfolder "$<IF:$<STREQUAL:${runtime_lib},MultiThreadedDLL>,MD,${subfolder}>")
  305. set(subfolder "$<IF:$<STREQUAL:${runtime_lib},MultiThreaded>,MT,${subfolder}>")
  306. target_link_directories(${module_target} INTERFACE
  307. "${module_path}/libs/VisualStudio${CMAKE_MATCH_1}/${arch}/${subfolder}")
  308. elseif(MSYS OR MINGW)
  309. _juce_add_library_path(${module_target} "${module_path}/libs/MinGW/${JUCE_TARGET_ARCHITECTURE}")
  310. endif()
  311. elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
  312. _juce_add_library_path(${module_target} "${module_path}/libs/Android/${CMAKE_ANDROID_ARCH_ABI}")
  313. endif()
  314. endfunction()
  315. # ==================================================================================================
  316. function(_juce_remove_empty_list_elements arg)
  317. list(FILTER ${arg} EXCLUDE REGEX "^$")
  318. set(${arg} ${${arg}} PARENT_SCOPE)
  319. endfunction()
  320. function(juce_add_module module_path)
  321. set(one_value_args INSTALL_PATH ALIAS_NAMESPACE)
  322. cmake_parse_arguments(JUCE_ARG "" "${one_value_args}" "" ${ARGN})
  323. _juce_make_absolute(module_path)
  324. get_filename_component(module_name ${module_path} NAME)
  325. get_filename_component(module_parent_path ${module_path} DIRECTORY)
  326. set(module_header_name "${module_name}.h")
  327. if(NOT EXISTS "${module_path}/${module_header_name}")
  328. set(module_header_name "${module_header_name}pp")
  329. endif()
  330. if(NOT EXISTS "${module_path}/${module_header_name}")
  331. message(FATAL_ERROR "Could not locate module header for module '${module_path}'")
  332. endif()
  333. set(base_path "${module_parent_path}")
  334. _juce_module_sources("${module_path}" "${base_path}" globbed_sources headers)
  335. if(${module_name} STREQUAL "juce_audio_plugin_client")
  336. _juce_get_platform_plugin_kinds(plugin_kinds)
  337. foreach(kind IN LISTS plugin_kinds)
  338. _juce_add_plugin_wrapper_target(${kind} "${module_path}" "${base_path}")
  339. endforeach()
  340. set(utils_source
  341. "${base_path}/${module_name}/juce_audio_plugin_client_utils.cpp")
  342. add_library(juce_audio_plugin_client_utils INTERFACE)
  343. target_sources(juce_audio_plugin_client_utils INTERFACE "${utils_source}")
  344. if(JUCE_ARG_ALIAS_NAMESPACE)
  345. add_library(${JUCE_ARG_ALIAS_NAMESPACE}::juce_audio_plugin_client_utils
  346. ALIAS juce_audio_plugin_client_utils)
  347. endif()
  348. file(GLOB_RECURSE all_module_files
  349. CONFIGURE_DEPENDS LIST_DIRECTORIES FALSE
  350. RELATIVE "${module_parent_path}"
  351. "${module_path}/*")
  352. else()
  353. list(APPEND all_module_sources ${globbed_sources})
  354. endif()
  355. _juce_add_interface_library(${module_name} ${all_module_sources})
  356. set_property(GLOBAL APPEND PROPERTY _juce_module_names ${module_name})
  357. set_target_properties(${module_name} PROPERTIES
  358. INTERFACE_JUCE_MODULE_SOURCES "${globbed_sources}"
  359. INTERFACE_JUCE_MODULE_HEADERS "${headers}"
  360. INTERFACE_JUCE_MODULE_PATH "${base_path}")
  361. if(JUCE_ENABLE_MODULE_SOURCE_GROUPS)
  362. target_sources(${module_name} INTERFACE ${headers})
  363. endif()
  364. if(${module_name} STREQUAL "juce_core")
  365. _juce_add_standard_defs(${module_name})
  366. target_link_libraries(juce_core INTERFACE juce::juce_atomic_wrapper)
  367. if(CMAKE_SYSTEM_NAME MATCHES ".*BSD")
  368. target_link_libraries(juce_core INTERFACE execinfo)
  369. elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
  370. target_sources(juce_core INTERFACE "${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c")
  371. target_include_directories(juce_core INTERFACE "${ANDROID_NDK}/sources/android/cpufeatures")
  372. target_link_libraries(juce_core INTERFACE android log)
  373. endif()
  374. endif()
  375. if(${module_name} STREQUAL "juce_audio_processors")
  376. add_library(juce_vst3_headers INTERFACE)
  377. target_compile_definitions(juce_vst3_headers INTERFACE "$<$<TARGET_EXISTS:juce_vst3_sdk>:JUCE_CUSTOM_VST3_SDK=1>")
  378. target_include_directories(juce_vst3_headers INTERFACE
  379. "$<$<TARGET_EXISTS:juce_vst3_sdk>:$<TARGET_PROPERTY:juce_vst3_sdk,INTERFACE_INCLUDE_DIRECTORIES>>"
  380. "$<$<NOT:$<TARGET_EXISTS:juce_vst3_sdk>>:${base_path}/juce_audio_processors/format_types/VST3_SDK>")
  381. target_link_libraries(juce_audio_processors INTERFACE juce_vst3_headers)
  382. add_library(juce_lilv_headers INTERFACE)
  383. set(lv2_base_path "${base_path}/juce_audio_processors/format_types/LV2_SDK")
  384. target_include_directories(juce_lilv_headers INTERFACE
  385. "${lv2_base_path}"
  386. "${lv2_base_path}/lv2"
  387. "${lv2_base_path}/serd"
  388. "${lv2_base_path}/sord"
  389. "${lv2_base_path}/sord/src"
  390. "${lv2_base_path}/sratom"
  391. "${lv2_base_path}/lilv"
  392. "${lv2_base_path}/lilv/src")
  393. target_link_libraries(juce_audio_processors INTERFACE juce_lilv_headers)
  394. if(JUCE_ARG_ALIAS_NAMESPACE)
  395. add_library(${JUCE_ARG_ALIAS_NAMESPACE}::juce_vst3_headers ALIAS juce_vst3_headers)
  396. add_library(${JUCE_ARG_ALIAS_NAMESPACE}::juce_lilv_headers ALIAS juce_lilv_headers)
  397. endif()
  398. endif()
  399. target_include_directories(${module_name} INTERFACE ${base_path})
  400. target_compile_definitions(${module_name} INTERFACE JUCE_MODULE_AVAILABLE_${module_name}=1)
  401. if((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD"))
  402. target_compile_definitions(${module_name} INTERFACE LINUX=1)
  403. endif()
  404. if((${module_name} STREQUAL "juce_audio_devices") AND (CMAKE_SYSTEM_NAME STREQUAL "Android"))
  405. add_subdirectory("${module_path}/native/oboe")
  406. target_link_libraries(${module_name} INTERFACE oboe)
  407. endif()
  408. if((${module_name} STREQUAL "juce_opengl") AND (CMAKE_SYSTEM_NAME STREQUAL "Android"))
  409. set(platform_supports_gl3 0)
  410. if(CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL 18)
  411. set(platform_supports_gl3 1)
  412. endif()
  413. if(platform_supports_gl3)
  414. target_compile_definitions(${module_name} INTERFACE JUCE_ANDROID_GL_ES_VERSION_3_0=1)
  415. endif()
  416. target_link_libraries(${module_name} INTERFACE EGL $<IF:${platform_supports_gl3},GLESv3,GLESv2>)
  417. endif()
  418. _juce_extract_metadata_block(JUCE_MODULE_DECLARATION "${module_path}/${module_header_name}" metadata_dict)
  419. _juce_get_metadata("${metadata_dict}" minimumCppStandard module_cpp_standard)
  420. if(module_cpp_standard)
  421. target_compile_features(${module_name} INTERFACE cxx_std_${module_cpp_standard})
  422. else()
  423. target_compile_features(${module_name} INTERFACE cxx_std_11)
  424. endif()
  425. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  426. _juce_get_metadata("${metadata_dict}" OSXFrameworks module_osxframeworks)
  427. _juce_remove_empty_list_elements(module_osxframeworks)
  428. foreach(module_framework IN LISTS module_osxframeworks)
  429. _juce_link_frameworks("${module_name}" INTERFACE "${module_framework}")
  430. endforeach()
  431. _juce_get_metadata("${metadata_dict}" WeakOSXFrameworks module_weakosxframeworks)
  432. _juce_remove_empty_list_elements(module_weakosxframeworks)
  433. foreach(module_framework IN LISTS module_weakosxframeworks)
  434. _juce_link_frameworks("${module_name}" INTERFACE WEAK "${module_framework}")
  435. endforeach()
  436. _juce_link_libs_from_metadata("${module_name}" "${metadata_dict}" OSXLibs)
  437. elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
  438. _juce_get_metadata("${metadata_dict}" iOSFrameworks module_iosframeworks)
  439. _juce_remove_empty_list_elements(module_iosframeworks)
  440. foreach(module_framework IN LISTS module_iosframeworks)
  441. _juce_link_frameworks("${module_name}" INTERFACE "${module_framework}")
  442. endforeach()
  443. _juce_get_metadata("${metadata_dict}" WeakiOSFrameworks module_weakiosframeworks)
  444. _juce_remove_empty_list_elements(module_weakiosframeworks)
  445. foreach(module_framework IN LISTS module_weakiosframeworks)
  446. _juce_link_frameworks("${module_name}" INTERFACE WEAK "${module_framework}")
  447. endforeach()
  448. _juce_link_libs_from_metadata("${module_name}" "${metadata_dict}" iOSLibs)
  449. elseif((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD"))
  450. _juce_get_metadata("${metadata_dict}" linuxPackages module_linuxpackages)
  451. if(module_linuxpackages)
  452. _juce_create_pkgconfig_target(${module_name}_LINUX_DEPS ${module_linuxpackages})
  453. target_link_libraries(${module_name} INTERFACE juce::pkgconfig_${module_name}_LINUX_DEPS)
  454. endif()
  455. _juce_link_libs_from_metadata("${module_name}" "${metadata_dict}" linuxLibs)
  456. elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  457. if((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") OR (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC"))
  458. if(module_name STREQUAL "juce_gui_basics")
  459. target_compile_options(${module_name} INTERFACE /bigobj)
  460. endif()
  461. _juce_link_libs_from_metadata("${module_name}" "${metadata_dict}" windowsLibs)
  462. elseif(MSYS OR MINGW)
  463. if(module_name STREQUAL "juce_gui_basics")
  464. target_compile_options(${module_name} INTERFACE "-Wa,-mbig-obj")
  465. endif()
  466. _juce_link_libs_from_metadata("${module_name}" "${metadata_dict}" mingwLibs)
  467. endif()
  468. endif()
  469. _juce_get_metadata("${metadata_dict}" dependencies module_dependencies)
  470. target_link_libraries(${module_name} INTERFACE ${module_dependencies})
  471. _juce_get_metadata("${metadata_dict}" searchpaths module_searchpaths)
  472. if(NOT module_searchpaths STREQUAL "")
  473. foreach(module_searchpath IN LISTS module_searchpaths)
  474. target_include_directories(${module_name}
  475. INTERFACE "${module_path}/${module_searchpath}")
  476. endforeach()
  477. endif()
  478. _juce_add_module_staticlib_paths("${module_name}" "${module_path}")
  479. if(JUCE_ARG_INSTALL_PATH)
  480. install(DIRECTORY "${module_path}" DESTINATION "${JUCE_ARG_INSTALL_PATH}")
  481. endif()
  482. if(JUCE_ARG_ALIAS_NAMESPACE)
  483. add_library(${JUCE_ARG_ALIAS_NAMESPACE}::${module_name} ALIAS ${module_name})
  484. endif()
  485. endfunction()
  486. function(juce_add_modules)
  487. set(one_value_args INSTALL_PATH ALIAS_NAMESPACE)
  488. cmake_parse_arguments(JUCE_ARG "" "${one_value_args}" "" ${ARGN})
  489. foreach(path IN LISTS JUCE_ARG_UNPARSED_ARGUMENTS)
  490. juce_add_module(${path}
  491. INSTALL_PATH "${JUCE_ARG_INSTALL_PATH}"
  492. ALIAS_NAMESPACE "${JUCE_ARG_ALIAS_NAMESPACE}")
  493. endforeach()
  494. endfunction()
  495. # When source groups are enabled, this function sets the HEADER_FILE_ONLY property on any module
  496. # source files that should not be built. This is called automatically by the juce_add_* functions.
  497. function(_juce_fixup_module_source_groups)
  498. if(JUCE_ENABLE_MODULE_SOURCE_GROUPS)
  499. get_property(all_modules GLOBAL PROPERTY _juce_module_names)
  500. foreach(module_name IN LISTS all_modules)
  501. get_target_property(path ${module_name} INTERFACE_JUCE_MODULE_PATH)
  502. get_target_property(header_files ${module_name} INTERFACE_JUCE_MODULE_HEADERS)
  503. get_target_property(source_files ${module_name} INTERFACE_JUCE_MODULE_SOURCES)
  504. source_group(TREE ${path} PREFIX "JUCE Modules" FILES ${header_files} ${source_files})
  505. set_source_files_properties(${header_files} PROPERTIES HEADER_FILE_ONLY TRUE)
  506. endforeach()
  507. endif()
  508. endfunction()