diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake index 65059125ae..b46af365b5 100644 --- a/src/qml/Qt6QmlMacros.cmake +++ b/src/qml/Qt6QmlMacros.cmake @@ -1828,6 +1828,35 @@ function(_qt_internal_qml_get_symbols_to_keep set(${out_var_constructor} "${constructor_content}" PARENT_SCOPE) endfunction() +function(_qt_internal_set_qml_target_multi_config_output_directory target output_directory) + # In multi-config builds we need to make sure that at least one configuration has the dynamic + # plugin that is located next to qmldir file, otherwise QML engine won't be able to load the + # plugin. + get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG) + if(is_multi_config) + # We don't care about static plugins here since, they are linked at build time and + # their location doesn't affect the runtime. + get_target_property(target_type ${target} TYPE) + if(target_type STREQUAL "SHARED_LIBRARY" OR target_type STREQUAL "MODULE_LIBRARY") + if(NOT "${output_directory}") + set(output_directory "${CMAKE_CURRENT_BINARY_DIR}") + endif() + + list(GET CMAKE_CONFIGURATION_TYPES 0 default_config) + string(JOIN "" output_directory_with_default_config + "$," + "${output_directory}," + "${output_directory}/$" + ">" + ) + set_target_properties(${target} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${output_directory_with_default_config}" + LIBRARY_OUTPUT_DIRECTORY "${output_directory_with_default_config}" + ) + endif() + endif() +endfunction() + function(qt6_add_qml_plugin target) set(args_option STATIC @@ -2106,6 +2135,8 @@ function(qt6_add_qml_plugin target) ) endif() + _qt_internal_set_qml_target_multi_config_output_directory(${target} "${arg_OUTPUT_DIRECTORY}") + if(NOT arg_NO_GENERATE_PLUGIN_SOURCE) set(generated_cpp_file_name_base "${target}_${arg_CLASS_NAME}") set(register_types_function_name "qml_register_types_${escaped_uri}")