summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@qt.io>2021-03-16 12:27:53 +1100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-03-18 06:17:07 +0000
commitf058e494c2200b6a95615c00f30afc9e33306a99 (patch)
tree6227a4fd22ba91cda174986828853be0f301c234 /cmake
parent4cefb50137450b66b8bda98036d880a599b19029 (diff)
Prevent static plugin triggering autogen dependency on reconfigure
A call to file(WRITE) will unconditionally update the file's timestamp even if the file's contents don't change. The *Plugin.cpp file was being written using configure_file() which avoids that, but the .cpp.in file it was configuring from was being written out using file(WRITE) every time CMake ran. Autogen saw that file as a dependency and then regenerated the mocs_compilation.cpp file, which in turn results in unnecessary rebuilds and relinking when nothing is actually changing. The file(WRITE) - configure_file() dance is no longer needed anyway, since the generated *Plugin.cpp file is very simple with no substitutions required. Therefore, we can simplify that file's generation with a single file(WRITE) that only executes if the file contents will change or the file is missing. Change-Id: I2b7d1ff678b85ea7811969d656555592c9b6865f Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> (cherry picked from commit 63a0d263cf233ddf85a60678829298b50e8d1f26) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtPlugins.cmake.in22
1 files changed, 15 insertions, 7 deletions
diff --git a/cmake/QtPlugins.cmake.in b/cmake/QtPlugins.cmake.in
index 6df9541e18..37ab1bb107 100644
--- a/cmake/QtPlugins.cmake.in
+++ b/cmake/QtPlugins.cmake.in
@@ -139,15 +139,23 @@ function(__qt_internal_add_static_plugins_once)
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}")
+ # Generate a source file to import that plug-in. Be careful not to
+ # update the timestamp of the generated file if we are not going to
+ # change anything. Otherwise we will trigger CMake's autogen to re-run
+ # and executables will then need to at least relink.
+ set(need_write TRUE)
+ if(EXISTS ${_generated_qt_plugin_file_name})
+ file(READ ${_generated_qt_plugin_file_name} old_contents)
+ if(old_contents STREQUAL "${_generated_qt_plugin_file_content}")
+ set(need_write FALSE)
+ endif()
+ endif()
+ if(need_write)
+ file(WRITE "${_generated_qt_plugin_file_name}"
+ "${_generated_qt_plugin_file_content}")
+ endif()
target_sources(${_module_target} INTERFACE
"$<${_plugin_condition}:${_generated_qt_plugin_file_name}>")