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.

608 lines
23KB

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