From 60968090adfc7dca78b9d60a0fe79cab4e2e6937 Mon Sep 17 00:00:00 2001 From: Amir Masoud Abdol Date: Fri, 11 Nov 2022 14:48:57 +0100 Subject: [PATCH] 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 --- cmake/QtBuildInformation.cmake | 8 +++++++- cmake/QtBuildInternals/QtBuildInternalsConfig.cmake | 4 ++++ cmake/QtProcessConfigureArgs.cmake | 9 +++++++++ config_help.txt | 4 +++- configure | 6 +++++- configure.bat | 5 ++++- 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/cmake/QtBuildInformation.cmake b/cmake/QtBuildInformation.cmake index 3d4e9cdaf60..111c304267e 100644 --- a/cmake/QtBuildInformation.cmake +++ b/cmake/QtBuildInformation.cmake @@ -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) diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index d547ffe4b6c..8ea8f4431dc 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -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() diff --git a/cmake/QtProcessConfigureArgs.cmake b/cmake/QtProcessConfigureArgs.cmake index 4eb7caa9225..e5b4b36d49c 100644 --- a/cmake/QtProcessConfigureArgs.cmake +++ b/cmake/QtProcessConfigureArgs.cmake @@ -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 diff --git a/config_help.txt b/config_help.txt index a02d60e5ce4..9fc0b380424 100644 --- a/config_help.txt +++ b/config_help.txt @@ -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. diff --git a/configure b/configure index 56999a984ea..a2b67a1d46a 100755 --- a/configure +++ b/configure @@ -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" diff --git a/configure.bat b/configure.bat index 1fb822d60fc..e93e0af318a 100644 --- a/configure.bat +++ b/configure.bat @@ -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"