Update -redo option such that it removes CMakeCache.txt and CMakeFiles/

In the case of re-doing, `configure` and `configure.bat` pass an extra
parameter to the `QtProcessConfigureArgs.cmake`. As a result, CMake
removes CMakeCache.txt and CMakeFiles/ before the reconfiguration. If
the user is using CMake 3.24 or newer, this is achieved by passing
the `--fresh` option to CMake call. In older CMake(s), CMakeCache.txt
and CMakeFiles/ found in CMAKE_BINARY_DIR will be removed using a
file(REMOVE_RECURSIVE call.

[ChangeLog] The -redo option now additionally removes existing
CMakeCache.txt file, and CMakeFiles/ directory, and recreates them from
scratch.

Task-number: QTBUG-108287
Change-Id: I11a5c8f9df1247d11eb7097552e6764463583346
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Amir Masoud Abdol 2022-11-11 14:48:57 +01:00
parent 4fb96669e3
commit 60968090ad
6 changed files with 32 additions and 4 deletions

View File

@ -93,7 +93,13 @@ function(qt_print_build_instructions)
"\nTo configure and build other Qt modules, you can use the following convenience script:
${local_install_prefix}/${INSTALL_BINDIR}/${configure_module_command}")
list(APPEND msg "\nIf reconfiguration fails for some reason, try removing 'CMakeCache.txt' \
from the build directory \n")
from the build directory")
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24")
list(APPEND msg "Alternatively, you can add the --fresh flag to your CMake flags.\n")
else()
list(APPEND msg "\n")
endif()
list(JOIN msg "\n" msg)
if(NOT QT_INTERNAL_BUILD_INSTRUCTIONS_SHOWN)

View File

@ -531,6 +531,10 @@ macro(qt_build_repo_end)
qt_internal_save_previously_found_packages()
endif()
if(QT_INTERNAL_FRESH_REQUESTED)
set(QT_INTERNAL_FRESH_REQUESTED "FALSE" CACHE INTERNAL "")
endif()
list(POP_BACK CMAKE_MESSAGE_CONTEXT)
endmacro()

View File

@ -144,6 +144,15 @@ while(NOT "${configure_args}" STREQUAL "")
endif()
endwhile()
if(FRESH_REQUESTED)
push("-DQT_INTERNAL_FRESH_REQUESTED:BOOL=TRUE")
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24")
push("--fresh")
else()
file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/CMakeCache.txt"
"${CMAKE_BINARY_DIR}/CMakeFiles")
endif()
endif()
####################################################################################################
# Define functions/macros that are called in configure.cmake files

View File

@ -44,7 +44,9 @@ options without auto-detection.
Configure meta:
-help, -h ............ Display this help screen
-redo ................ Re-configure with previously used options.
-redo ................ Re-configure with previously used options. In addition,
redo removes CMakeCache.txt file and CMakeFiles/ directory
and recreates them from scratch.
Additional options may be passed, but will not be
saved for later use by -redo.

6
configure vendored
View File

@ -221,6 +221,8 @@ checkTopLevelBuild "$@"
parseCommandline "$@"
handleHelp
determineOptFilePath "$@"
fresh_requested_arg=
optfilename=config.opt
if [ -z "$optfile" ]; then # only write optfile if not currently redoing
optfilepath=${outpathPrefix}${optfilename}
@ -231,6 +233,8 @@ if [ -z "$optfile" ]; then # only write optfile if not currently redoing
fi
echo $arg >> "$optfilepath"
done
else
fresh_requested_arg=-DFRESH_REQUESTED=TRUE
fi
top_level_arg=
@ -239,4 +243,4 @@ if [ -n "$CFG_TOPLEVEL" ]; then
cd ..
fi
cmake "-DOPTFILE=$optfilename" $top_level_arg -P "$relpath/cmake/QtProcessConfigureArgs.cmake"
cmake "-DOPTFILE=$optfilename" $top_level_arg $fresh_requested_arg -P "$relpath/cmake/QtProcessConfigureArgs.cmake"

View File

@ -78,12 +78,15 @@ goto doneargs
cd "%TOPQTDIR%"
rem Write config.opt if we're not currently -redo'ing
set FRESH_REQUESTED_ARG=
if "!rargs!" == "" (
echo.%*>config.opt.in
cmake -DIN_FILE=config.opt.in -DOUT_FILE=config.opt -DIGNORE_ARGS=-top-level -P "%QTSRC%\cmake\QtWriteArgsFile.cmake"
) else if NOT "!rargs!" == "" (
set FRESH_REQUESTED_ARG=-DFRESH_REQUESTED=TRUE
)
rem Launch CMake-based configure
set TOP_LEVEL_ARG=
if %TOPLEVEL% == true set TOP_LEVEL_ARG=-DTOP_LEVEL=TRUE
cmake -DOPTFILE=config.opt %TOP_LEVEL_ARG% -P "%QTSRC%\cmake\QtProcessConfigureArgs.cmake"
cmake -DOPTFILE=config.opt %TOP_LEVEL_ARG% %FRESH_REQUESTED_ARG% -P "%QTSRC%\cmake\QtProcessConfigureArgs.cmake"