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.

678 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.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_17)
  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. target_include_directories("${target_name}" INTERFACE "${out_path}/juce_audio_plugin_client/AU")
  261. _juce_link_frameworks("${target_name}" INTERFACE AudioUnit CoreAudioKit)
  262. endif()
  263. endfunction()
  264. # ==================================================================================================
  265. function(_juce_link_libs_from_metadata module_name dict key)
  266. _juce_get_metadata("${dict}" "${key}" libs)
  267. if(libs)
  268. target_link_libraries(${module_name} INTERFACE ${libs})
  269. endif()
  270. endfunction()
  271. # ==================================================================================================
  272. function(_juce_create_pkgconfig_target name)
  273. if(TARGET juce::pkgconfig_${name})
  274. return()
  275. endif()
  276. find_package(PkgConfig REQUIRED)
  277. pkg_check_modules(${name} ${ARGN})
  278. add_library(pkgconfig_${name} INTERFACE)
  279. add_library(juce::pkgconfig_${name} ALIAS pkgconfig_${name})
  280. install(TARGETS pkgconfig_${name} EXPORT JUCE)
  281. set(pairs
  282. "INCLUDE_DIRECTORIES\;INCLUDE_DIRS"
  283. "LINK_LIBRARIES\;LINK_LIBRARIES"
  284. "LINK_OPTIONS\;LDFLAGS_OTHER"
  285. "COMPILE_OPTIONS\;CFLAGS_OTHER")
  286. foreach(pair IN LISTS pairs)
  287. list(GET pair 0 key)
  288. list(GET pair 1 value)
  289. if(${name}_${value})
  290. set_target_properties(pkgconfig_${name} PROPERTIES INTERFACE_${key} "${${name}_${value}}")
  291. endif()
  292. endforeach()
  293. endfunction()
  294. # ==================================================================================================
  295. function(_juce_add_library_path target path)
  296. if(EXISTS "${path}")
  297. target_link_directories(${target} INTERFACE ${path})
  298. endif()
  299. endfunction()
  300. function(_juce_add_module_staticlib_paths module_target module_path)
  301. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  302. _juce_add_library_path(${module_target} "${module_path}/libs/MacOSX")
  303. elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
  304. _juce_add_library_path(${module_target} "${module_path}/libs/iOS")
  305. elseif((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD"))
  306. _juce_add_library_path(${module_target} "${module_path}/libs/Linux/${JUCE_TARGET_ARCHITECTURE}")
  307. elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  308. if(CMAKE_GENERATOR MATCHES "Visual Studio [0-9]+ (20[0-9]+)")
  309. set(arch "$<IF:$<EQUAL:${CMAKE_SIZEOF_VOID_P},8>,x64,Win32>")
  310. if(NOT CMAKE_GENERATOR_PLATFORM STREQUAL "")
  311. set(arch ${CMAKE_GENERATOR_PLATFORM})
  312. endif()
  313. set(runtime_lib "$<GENEX_EVAL:$<TARGET_PROPERTY:MSVC_RUNTIME_LIBRARY>>")
  314. set(subfolder "MDd")
  315. set(subfolder "$<IF:$<STREQUAL:${runtime_lib},MultiThreadedDebug>,MTd,${subfolder}>")
  316. set(subfolder "$<IF:$<STREQUAL:${runtime_lib},MultiThreadedDLL>,MD,${subfolder}>")
  317. set(subfolder "$<IF:$<STREQUAL:${runtime_lib},MultiThreaded>,MT,${subfolder}>")
  318. target_link_directories(${module_target} INTERFACE
  319. "${module_path}/libs/VisualStudio${CMAKE_MATCH_1}/${arch}/${subfolder}")
  320. elseif(MSYS OR MINGW)
  321. _juce_add_library_path(${module_target} "${module_path}/libs/MinGW/${JUCE_TARGET_ARCHITECTURE}")
  322. endif()
  323. elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
  324. _juce_add_library_path(${module_target} "${module_path}/libs/Android/${CMAKE_ANDROID_ARCH_ABI}")
  325. endif()
  326. endfunction()
  327. # ==================================================================================================
  328. function(_juce_remove_empty_list_elements arg)
  329. list(FILTER ${arg} EXCLUDE REGEX "^$")
  330. set(${arg} ${${arg}} PARENT_SCOPE)
  331. endfunction()
  332. function(juce_add_module module_path)
  333. set(one_value_args INSTALL_PATH ALIAS_NAMESPACE)
  334. cmake_parse_arguments(JUCE_ARG "" "${one_value_args}" "" ${ARGN})
  335. _juce_make_absolute(module_path)
  336. get_filename_component(module_name ${module_path} NAME)
  337. get_filename_component(module_parent_path ${module_path} DIRECTORY)
  338. set(module_header_name "${module_name}.h")
  339. if(NOT EXISTS "${module_path}/${module_header_name}")
  340. set(module_header_name "${module_header_name}pp")
  341. endif()
  342. if(NOT EXISTS "${module_path}/${module_header_name}")
  343. message(FATAL_ERROR "Could not locate module header for module '${module_path}'")
  344. endif()
  345. set(base_path "${module_parent_path}")
  346. _juce_module_sources("${module_path}" "${base_path}" globbed_sources headers)
  347. if(${module_name} STREQUAL "juce_audio_plugin_client")
  348. list(REMOVE_ITEM headers "${module_path}/LV2/juce_LV2TurtleDumpProgram.cpp")
  349. _juce_get_platform_plugin_kinds(plugin_kinds)
  350. foreach(kind IN LISTS plugin_kinds)
  351. _juce_add_plugin_wrapper_target(${kind} "${module_path}" "${base_path}")
  352. endforeach()
  353. set(utils_source
  354. "${base_path}/${module_name}/juce_audio_plugin_client_utils.cpp")
  355. add_library(juce_audio_plugin_client_utils INTERFACE)
  356. target_sources(juce_audio_plugin_client_utils INTERFACE "${utils_source}")
  357. if(JUCE_ARG_ALIAS_NAMESPACE)
  358. add_library(${JUCE_ARG_ALIAS_NAMESPACE}::juce_audio_plugin_client_utils
  359. ALIAS juce_audio_plugin_client_utils)
  360. endif()
  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 STREQUAL "juce_gui_basics")
  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()