Skip to content

Commit

Permalink
CMake: Fix argument passing for configure.bat / qt-configure-module.bat
Browse files Browse the repository at this point in the history
Passing arguments with equal signs was broken for configure.bat and
qt-configure-module.bat. An argument FOO=BAR was split at = and written
as
    FOO
    BAR
to config.opt, breaking every attempt of assigning CMake variables.

We must not iterate over %* in batch files to avoid splitting arguments
at equal signs. Instead, pass %* unmodified to a CMake script that
writes config.opt.

Fixes: QTBUG-88019
Change-Id: I7c743a206961d1ed168f2313f864905f6b345b49
Reviewed-by: Alexandru Croitor <[email protected]>
  • Loading branch information
jobor committed Oct 30, 2020
1 parent de3bd64 commit 2a29426
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
13 changes: 2 additions & 11 deletions bin/qt-configure-module.bat.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,9 @@ if not exist "%module_root%\CMakeLists.txt" (
exit /b 1
)

echo. > "config.opt"
set first_iteration=indeed
for %%a in (%*) do (
if defined first_iteration (
:: Drop the first argument, which is the module root.
set first_iteration=
) else (
echo %%a >> "config.opt"
)
)

set cmake_scripts_dir=%script_dir_path%\@__relative_path_to_cmake_scripts_dir@
call "%script_dir_path%"\qt-cmake.bat -DSKIP_ARGS=1 -DOUT_FILE=config.opt ^
-P "%cmake_scripts_dir%\QtWriteArgsFile.cmake" %*
call "%script_dir_path%"\qt-cmake-private.bat -DOPTFILE=config.opt -DMODULE_ROOT="%module_root%" ^
-DCMAKE_COMMAND="%script_dir_path%\qt-cmake-private.bat" ^
-P "%cmake_scripts_dir%\QtProcessConfigureArgs.cmake"
Expand Down
1 change: 1 addition & 0 deletions cmake/QtBaseGlobalTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ qt_copy_or_install(FILES
cmake/QtToolchainHelpers.cmake
cmake/QtToolHelpers.cmake
cmake/QtWrapperScriptHelpers.cmake
cmake/QtWriteArgsFile.cmake
DESTINATION "${__GlobalConfig_install_dir}"
)

Expand Down
31 changes: 31 additions & 0 deletions cmake/QtWriteArgsFile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This script writes its arguments to the file determined by OUT_FILE.
# Each argument appears on a separate line.
# This is used for writing the config.opt file.
#
# This script takes the following arguments:
# OUT_FILE: The output file.
# SKIP_ARGS: Number of arguments to skip from the front of the arguments list.

# Look for the -P argument to determine the start of the actual script arguments
math(EXPR stop "${CMAKE_ARGC} - 1")
set(start 0)
foreach(i RANGE 1 ${stop})
if(CMAKE_ARGV${i} STREQUAL "-P")
math(EXPR start "${i} + 2")
break()
endif()
endforeach()

# Skip arguments if requested
if(DEFINED SKIP_ARGS)
math(EXPR start "${start} + ${SKIP_ARGS}")
endif()

# Write config.opt
set(content "")
if(start LESS_EQUAL stop)
foreach(i RANGE ${start} ${stop})
string(APPEND content "${CMAKE_ARGV${i}}\n")
endforeach()
endif()
file(WRITE "${OUT_FILE}" "${content}")
3 changes: 1 addition & 2 deletions configure.bat
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ goto :eof

rem Write config.opt if we're not currently -redo'ing
if "%rargs%" == "" (
if exist "%TOPQTDIR%\config.opt" del "%TOPQTDIR%\config.opt"
for %%a in (%ARGS%) do echo %%a >> "%TOPQTDIR%\config.opt"
cmake -DOUT_FILE=config.opt -P "%QTSRC%\cmake\QtWriteArgsFile.cmake" %*
)

rem Launch CMake-based configure
Expand Down

0 comments on commit 2a29426

Please sign in to comment.