Skip to content

Commit

Permalink
Improve double call protection of qt_internal_generate_tool_command_w…
Browse files Browse the repository at this point in the history
…rapper

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 <[email protected]>
Reviewed-by: Qt CI Bot <[email protected]>
  • Loading branch information
semlanik committed Oct 15, 2021
1 parent a36c84c commit f19f729
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions cmake/QtBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}$<SEMICOLON>%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}$<SEMICOLON>%PATH%\r\n%*")
set_property(GLOBAL PROPERTY _qt_internal_generate_tool_command_wrapper_called TRUE)
endfunction()
qt_internal_generate_tool_command_wrapper()

Expand Down

0 comments on commit f19f729

Please sign in to comment.