diff --git a/cmake/QtPlugins.cmake.in b/cmake/QtPlugins.cmake.in index 15a16137d4..fb87a54c0d 100644 --- a/cmake/QtPlugins.cmake.in +++ b/cmake/QtPlugins.cmake.in @@ -79,11 +79,19 @@ if(NOT @BUILD_SHARED_LIBS@) set(_plugin_genex "$<${_plugin_condition}:${_plugin_target}>") target_link_libraries(${_module_target} INTERFACE "${_plugin_genex}") - # Generate a source file to import that plug-in - file(GENERATE - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/qt_@QT_MODULE@_${target}.cpp" - CONTENT "#include \nQ_IMPORT_PLUGIN(${_classname})" - ) - target_sources(${_module_target} INTERFACE "$<${_plugin_condition}:${CMAKE_CURRENT_BINARY_DIR}/qt_@QT_MODULE@_${target}.cpp>") + set(_generated_qt_plugin_file_name + "${CMAKE_CURRENT_BINARY_DIR}/qt_@QT_MODULE@_${target}.cpp") + set(_generated_qt_plugin_file_name_template "${_generated_qt_plugin_file_name}.in") + set(_generated_qt_plugin_file_content "#include \nQ_IMPORT_PLUGIN(${_classname})") + + # Generate a source file to import that plug-in. Has to be done with configure_file, + # because file(GENERATE) and target_sources has issues with scopes. + file(WRITE "${_generated_qt_plugin_file_name_template}" + "${_generated_qt_plugin_file_content}") + configure_file("${_generated_qt_plugin_file_name_template}" + "${_generated_qt_plugin_file_name}") + + target_sources(${_module_target} INTERFACE + "$<${_plugin_condition}:${_generated_qt_plugin_file_name}>") endforeach() endif()