qt5base-lts/cmake/QtWriteArgsFile.cmake
Joerg Bornemann 57ad532e75 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>
2021-08-20 19:44:43 +02:00

33 lines
1004 B
CMake

# 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:
# 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.
# IGNORE_ARGS: List of arguments to be ignored, i.e. that are not written.
cmake_minimum_required(VERSION 3.3)
# Read arguments from IN_FILE and separate them.
file(READ "${IN_FILE}" raw_args)
separate_arguments(args NATIVE_COMMAND "${raw_args}")
# Skip arguments if requested
if(DEFINED SKIP_ARGS)
foreach(i RANGE 1 ${SKIP_ARGS})
list(POP_FRONT args)
endforeach()
endif()
# Write config.opt
set(content "")
foreach(arg IN LISTS args)
if(NOT arg IN_LIST IGNORE_ARGS)
string(APPEND content "${arg}\n")
endif()
endforeach()
file(WRITE "${OUT_FILE}" "${content}")