Fix our usage of CMake script mode in Windows configure

This is a preparation for adding the -help argument to
qt-configure-module.bat.

Consider the call
  qt-configure-module.bat path/to/qt-module -help
Internally, we called
  cmake ... -P .../QtWriteArgsFile.cmake path/to/qt-module -help
which was supposed to separate the arguments and write them into
config.opt.

However, passing arbitrary arguments after "-P script.cmake" only worked
by accident and is not supported.  As soon as arguments are passed that
are valid CMake arguments, like -help or -G, the CMake call would fail.

Now, we let configure.bat and qt-configure-module.bat write the
arguments as is into config.opt.in and let QtWriteArgsFile.cmake read
this file, separate the arguments and write config.opt.

Pick-to: 6.2
Task-number: QTBUG-95943
Change-Id: I80f298a2aaf55b0f79fed86320a055eb2d2b6faa
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2021-08-20 14:34:37 +02:00
parent 4e2ec5ab5d
commit 57ad532e75
3 changed files with 19 additions and 22 deletions

View File

@ -18,8 +18,9 @@ if not exist "%module_root%\CMakeLists.txt" (
) )
set cmake_scripts_dir=%script_dir_path%\@__relative_path_to_cmake_scripts_dir@ 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 ^ echo %*>config.opt.in
-P "%cmake_scripts_dir%\QtWriteArgsFile.cmake" %* call "%script_dir_path%"\qt-cmake.bat -DSKIP_ARGS=1 -DIN_FILE=config.opt.in -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%" ^ call "%script_dir_path%"\qt-cmake-private.bat -DOPTFILE=config.opt -DMODULE_ROOT="%module_root%" ^
-DCMAKE_COMMAND="%script_dir_path%\qt-cmake-private.bat" ^ -DCMAKE_COMMAND="%script_dir_path%\qt-cmake-private.bat" ^
-P "%cmake_scripts_dir%\QtProcessConfigureArgs.cmake" -P "%cmake_scripts_dir%\QtProcessConfigureArgs.cmake"

View File

@ -3,35 +3,30 @@
# This is used for writing the config.opt file. # This is used for writing the config.opt file.
# #
# This script takes the following arguments: # This script takes the following arguments:
# OUT_FILE: The output file. # IN_FILE: The input file. The whole command line as one string.
# OUT_FILE: The output file. One argument per line.
# SKIP_ARGS: Number of arguments to skip from the front of the arguments list. # SKIP_ARGS: Number of arguments to skip from the front of the arguments list.
# IGNORE_ARGS: List of arguments to be ignored, i.e. that are not written. # IGNORE_ARGS: List of arguments to be ignored, i.e. that are not written.
cmake_minimum_required(VERSION 3.3) cmake_minimum_required(VERSION 3.3)
# Look for the -P argument to determine the start of the actual script arguments # Read arguments from IN_FILE and separate them.
math(EXPR stop "${CMAKE_ARGC} - 1") file(READ "${IN_FILE}" raw_args)
set(start 0) separate_arguments(args NATIVE_COMMAND "${raw_args}")
foreach(i RANGE 1 ${stop})
if(CMAKE_ARGV${i} STREQUAL "-P")
math(EXPR start "${i} + 2")
break()
endif()
endforeach()
# Skip arguments if requested # Skip arguments if requested
if(DEFINED SKIP_ARGS) if(DEFINED SKIP_ARGS)
math(EXPR start "${start} + ${SKIP_ARGS}") foreach(i RANGE 1 ${SKIP_ARGS})
list(POP_FRONT args)
endforeach()
endif() endif()
# Write config.opt # Write config.opt
set(content "") set(content "")
if(start LESS_EQUAL stop) foreach(arg IN LISTS args)
foreach(i RANGE ${start} ${stop}) if(NOT arg IN_LIST IGNORE_ARGS)
set(arg ${CMAKE_ARGV${i}}) string(APPEND content "${arg}\n")
if(NOT arg IN_LIST IGNORE_ARGS) endif()
string(APPEND content "${arg}\n") endforeach()
endif()
endforeach()
endif()
file(WRITE "${OUT_FILE}" "${content}") file(WRITE "${OUT_FILE}" "${content}")

View File

@ -104,7 +104,8 @@ cd "%TOPQTDIR%"
rem Write config.opt if we're not currently -redo'ing rem Write config.opt if we're not currently -redo'ing
if "%rargs%" == "" ( if "%rargs%" == "" (
cmake -DOUT_FILE=config.opt -DIGNORE_ARGS=-top-level -P "%QTSRC%\cmake\QtWriteArgsFile.cmake" %* echo %*>config.opt.in
cmake -DIN_FILE=config.opt.in -DOUT_FILE=config.opt -DIGNORE_ARGS=-top-level -P "%QTSRC%\cmake\QtWriteArgsFile.cmake"
) )
rem Launch CMake-based configure rem Launch CMake-based configure