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
26KB

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