summaryrefslogtreecommitdiffstats
path: root/cmake/QtPlugins.cmake.in
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-10-08 18:13:03 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-10-09 09:22:27 +0000
commit87ba355d958c8d96023a095f0305e1517ce89155 (patch)
treedd01547ab9d6efce37fbc4577d3b6799ed662f5a /cmake/QtPlugins.cmake.in
parentf95988261631a47fcc5cacf57a1226cb8e391c64 (diff)
Fix automatic plugin importing in static builds
QtPlugins.cmake.in uses file(GENERATE) and target_sources() to propagate the generated cpp files which contain plugin initialization code to their consuming targets. Unfortunately due to a bug in CMake, if the file is generated in a different scope than the consuming target, the CMake generation step will fail saying that the source file can not be found. See https://gitlab.kitware.com/cmake/cmake/issues/18399 for details. In the case of qtdeclarative, find_package(Qt6) is called at the top level scope (this is when the file gets generated), but the targets are created in subdirectory scopes, and the GENERATED source file property is not propagated across scropes. Circumvent the issue by instead using file(WRITE) and configure_file() which create the file at configure time rather than generate time. This will pollute the current binary directory with some more files, but at least successfully fixes the build. Change-Id: I3ab3b12dcbf6a9d0ab9ee87173e4a1952325b37b Reviewed-by: Leander Beernaert <leander.beernaert@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Qt CMake Build Bot
Diffstat (limited to 'cmake/QtPlugins.cmake.in')
-rw-r--r--cmake/QtPlugins.cmake.in20
1 files changed, 14 insertions, 6 deletions
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 <QtPlugin>\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 <QtPlugin>\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()