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.

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