1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

CMake: Use juce_add_modules to import modules from install tree

This change means that imported juce modules will be made available both
with and without a namespace prefix, e.g. `juce_core` and
`juce::juce_core` will both be created.

This change allows custom modules to specify dependencies without a
juce:: prefix, which allows the modules to be used with the Projucer, or
under CMake with JUCE in a subdirectory, or under CMake with JUCE
installed to the system.
This commit is contained in:
reuk 2020-05-04 12:29:25 +01:00
parent 6f016aa03b
commit bf51d2c076
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11
5 changed files with 69 additions and 34 deletions

View file

@ -31,3 +31,59 @@ endif()
check_required_components("@PROJECT_NAME@")
include("@PACKAGE_UTILS_INSTALL_DIR@/JUCEUtils.cmake")
set(_juce_modules
juce_analytics
juce_audio_basics
juce_audio_devices
juce_audio_formats
juce_audio_plugin_client
juce_audio_processors
juce_audio_utils
juce_blocks_basics
juce_box2d
juce_core
juce_cryptography
juce_data_structures
juce_dsp
juce_events
juce_graphics
juce_gui_basics
juce_gui_extra
juce_opengl
juce_osc
juce_product_unlocking
juce_video)
set(_targets_defined)
set(_targets_expected)
foreach(_juce_module IN LISTS _juce_modules)
list(APPEND _targets_expected ${_juce_module} juce::${_juce_modules})
if(TARGET ${_juce_module})
list(APPEND _targets_defined ${_juce_module})
endif()
if(TARGET juce::${_juce_module})
list(APPEND _targets_defined juce::${_juce_module})
endif()
endforeach()
if("${_targets_defined}" STREQUAL "${_targets_expected}")
unset(_targets_defined)
unset(_targets_expected)
return()
endif()
if(NOT "${_targets_defined}" STREQUAL "")
message(FATAL_ERROR "Some targets in this export set were already defined.")
endif()
unset(_targets_defined)
unset(_targets_expected)
foreach(_juce_module IN LISTS _juce_modules)
juce_add_module("@PACKAGE_JUCE_MODULE_PATH@/${_juce_module}" ALIAS_NAMESPACE juce)
endforeach()
unset(_juce_modules)

View file

@ -431,7 +431,7 @@ endfunction()
# ==================================================================================================
function(juce_add_module module_path)
set(one_value_args INSTALL_PATH INSTALL_EXPORT ALIAS_NAMESPACE)
set(one_value_args INSTALL_PATH ALIAS_NAMESPACE)
cmake_parse_arguments(JUCE_ARG "" "${one_value_args}" "" ${ARGN})
_juce_make_absolute(module_path)
@ -455,20 +455,13 @@ function(juce_add_module module_path)
list(APPEND all_module_sources "${base_path}/${module_name}/${module_header_name}")
set(install_export_args)
if(JUCE_ARG_INSTALL_EXPORT)
set(install_export_args INSTALL_EXPORT "${JUCE_ARG_INSTALL_EXPORT}")
endif()
if(${module_name} STREQUAL "juce_audio_plugin_client")
_juce_get_platform_plugin_kinds(plugin_kinds)
foreach(kind IN LISTS plugin_kinds)
_juce_add_plugin_wrapper_target(FORMAT ${kind}
PATH "${module_path}"
OUT_PATH "${base_path}"
${install_export_args})
OUT_PATH "${base_path}")
endforeach()
list(APPEND all_module_sources "${base_path}/${module_name}/juce_audio_plugin_client_utils.cpp")
@ -497,10 +490,6 @@ function(juce_add_module module_path)
"${base_path}/juce_audio_processors/format_types/VST3_SDK")
target_link_libraries(juce_audio_processors INTERFACE juce_vst3_headers)
if(JUCE_ARG_INSTALL_EXPORT)
install(TARGETS juce_vst3_headers EXPORT "${JUCE_ARG_INSTALL_EXPORT}")
endif()
if(JUCE_ARG_ALIAS_NAMESPACE)
add_library(${JUCE_ARG_ALIAS_NAMESPACE}::juce_vst3_headers ALIAS juce_vst3_headers)
endif()
@ -568,9 +557,8 @@ function(juce_add_module module_path)
_juce_get_metadata("${metadata_dict}" dependencies module_dependencies)
target_link_libraries(${module_name} INTERFACE ${module_dependencies})
if(JUCE_ARG_INSTALL_PATH OR JUCE_ARG_INSTALL_EXPORT)
if(installed_module_path)
install(DIRECTORY "${module_path}" DESTINATION "${installed_module_path}")
install(TARGETS ${module_name} EXPORT "${JUCE_ARG_INSTALL_EXPORT}")
endif()
if(JUCE_ARG_ALIAS_NAMESPACE)
@ -579,13 +567,12 @@ function(juce_add_module module_path)
endfunction()
function(juce_add_modules)
set(one_value_args INSTALL_PATH INSTALL_EXPORT ALIAS_NAMESPACE)
set(one_value_args INSTALL_PATH ALIAS_NAMESPACE)
cmake_parse_arguments(JUCE_ARG "" "${one_value_args}" "" ${ARGN})
foreach(path IN LISTS JUCE_ARG_UNPARSED_ARGUMENTS)
juce_add_module(${path}
INSTALL_PATH "${JUCE_ARG_INSTALL_PATH}"
INSTALL_EXPORT "${JUCE_ARG_INSTALL_EXPORT}"
ALIAS_NAMESPACE "${JUCE_ARG_ALIAS_NAMESPACE}")
endforeach()
endfunction()
@ -2063,13 +2050,8 @@ function(juce_add_pip header)
set(discovered_module)
# If we're building a PIP from outside the current build tree, the JUCE modules
# might be namespaced, so we try adding a namespace if we can't find a target with
# the name given in the metadata block.
if(TARGET "${module}")
set(discovered_module "${module}")
elseif(TARGET "juce::${module}")
set(discovered_module "juce::${module}")
else()
message(FATAL_ERROR "No such module: ${module}")
endif()