From f19f7295119d96b7606d475814328aac1d78c7cf Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Thu, 14 Oct 2021 12:34:22 +0200 Subject: [PATCH] Improve double call protection of qt_internal_generate_tool_command_wrapper file(GENERATE) might fail if an unrelated configuration error happens, and yet QT_TOOL_COMMAND_WRAPPER_PATH would already be set. Set the cache variable only if generating was successful and replace the QT_TOOL_COMMAND_WRAPPER_PATH valiable check with GLOBAL property to protect the function from double call. For CMake versions higher than or equal to 3.18 replace 'file(GENERATE' call with 'file(CONFIGURE' to generate the wrapper at configure time with the use of a plain semicolon character. Pick-to: 6.2 Fixes: QTBUG-96870 Change-Id: Icf9c40f571d9c069043604f67ffcf2762966f6d0 Reviewed-by: Alexandru Croitor Reviewed-by: Qt CI Bot --- cmake/QtBuild.cmake | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index eff4cc9a266..b2cdd356679 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -266,15 +266,26 @@ endfunction() qt_setup_tool_path_command() function(qt_internal_generate_tool_command_wrapper) - if(NOT CMAKE_HOST_WIN32 OR DEFINED QT_TOOL_COMMAND_WRAPPER_PATH) + get_property(is_called GLOBAL PROPERTY _qt_internal_generate_tool_command_wrapper_called) + if(NOT CMAKE_HOST_WIN32 OR is_called) return() endif() set(bindir "${QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX}/${INSTALL_BINDIR}") file(TO_NATIVE_PATH "${bindir}" bindir) - set(QT_TOOL_COMMAND_WRAPPER_PATH "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/qt_setup_tool_path.bat" + set(tool_command_wrapper_path "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/qt_setup_tool_path.bat") + if(CMAKE_VERSION VERSION_LESS 3.18) + # TODO: It doesn't make sense to generate wrapper at generator stage. Since file(CONFIGURE + # was added in CMake 3.18, keep file(GENERATE for compatibility, until the minimum required + # version is raised to 3.18. + file(GENERATE OUTPUT "${tool_command_wrapper_path}" CONTENT + "@echo off\r\nset PATH=${bindir}$%PATH%\r\n%*") + else() + file(CONFIGURE OUTPUT "${tool_command_wrapper_path}" CONTENT + "@echo off\r\nset PATH=${bindir};%PATH%\r\n%*") + endif() + set(QT_TOOL_COMMAND_WRAPPER_PATH "${tool_command_wrapper_path}" CACHE INTERNAL "Path to the wrapper of the tool commands") - file(GENERATE OUTPUT "${QT_TOOL_COMMAND_WRAPPER_PATH}" CONTENT - "@echo off\r\nset PATH=${bindir}$%PATH%\r\n%*") + set_property(GLOBAL PROPERTY _qt_internal_generate_tool_command_wrapper_called TRUE) endfunction() qt_internal_generate_tool_command_wrapper()