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.

675 lines
27KB

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