diff --git a/cmake/QtBuildInformation.cmake b/cmake/QtBuildInformation.cmake index 6929f9134ef..f9495bb0d26 100644 --- a/cmake/QtBuildInformation.cmake +++ b/cmake/QtBuildInformation.cmake @@ -111,6 +111,12 @@ from the build directory") if(QT_SUPERBUILD) qt_internal_save_previously_visited_packages() endif() + + # TODO: Abuse qt_print_build_instructions being called as the last command in a top-level build. + # Instead we should call this explicitly at the end of the top-level project. + if(QT_SUPERBUILD) + qt_internal_qt_configure_end() + endif() endfunction() function(qt_configure_print_summary_helper summary_reports force_show) diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index 3bdb6488318..1067e01e835 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -131,9 +131,10 @@ function(qt_build_internals_disable_pkg_config_if_needed) endif() # Features won't have been evaluated yet if this is the first run, have to evaluate this here - if ((NOT DEFINED "FEATURE_pkg_config") AND (DEFINED "INPUT_pkg_config") - AND (NOT "${INPUT_pkg_config}" STREQUAL "undefined") - AND (NOT "${INPUT_pkg_config}" STREQUAL "")) + if((NOT DEFINED "FEATURE_pkg_config" OR QT_INTERNAL_CALLED_FROM_CONFIGURE) + AND DEFINED INPUT_pkg_config + AND NOT "${INPUT_pkg_config}" STREQUAL "undefined" + AND NOT "${INPUT_pkg_config}" STREQUAL "") if(INPUT_pkg_config) set(FEATURE_pkg_config ON) else() @@ -603,9 +604,27 @@ macro(qt_build_repo_end) set(QT_INTERNAL_FRESH_REQUESTED "FALSE" CACHE INTERNAL "") endif() + if(NOT QT_SUPERBUILD) + qt_internal_qt_configure_end() + endif() + list(POP_BACK CMAKE_MESSAGE_CONTEXT) endmacro() +# Function called either at the end of per-repo configuration, or at the end of configuration of +# a super build. +# At the moment it is called before examples are configured in a per-repo build. We might want +# to change that at some point if needed. +function(qt_internal_qt_configure_end) + # If Qt is configued via the configure script, remove the marker variable, so that any future + # reconfigurations that are done by calling cmake directly don't trigger configure specific + # logic. + unset(QT_INTERNAL_CALLED_FROM_CONFIGURE CACHE) + + # Clean up stale feature input values. + qt_internal_clean_feature_inputs() +endfunction() + macro(qt_build_repo) qt_build_repo_begin(${ARGN}) diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake index 93f1ed81031..77b91e077cb 100644 --- a/cmake/QtFeature.cmake +++ b/cmake/QtFeature.cmake @@ -410,10 +410,15 @@ function(qt_evaluate_feature feature) qt_evaluate_config_expression(emit_if ${arg_EMIT_IF}) endif() - # If FEATURE_ is not defined trying to use INPUT_ variable to enable/disable feature. - if ((NOT DEFINED "FEATURE_${feature}") AND (DEFINED "INPUT_${feature}") - AND (NOT "${INPUT_${feature}}" STREQUAL "undefined") - AND (NOT "${INPUT_${feature}}" STREQUAL "")) + # If FEATURE_ is not defined try to use the INPUT_ variable to enable/disable feature. + # If FEATURE_ is defined and the configure script is being used (so + # QT_INTERNAL_CALLED_FROM_CONFIGURE is TRUE), ignore the FEATURE_ variable, and take into + # account the INPUT_ variable instead, because a command line argument takes priority over + # a pre-cached FEATURE_ variable. + if((NOT DEFINED FEATURE_${feature} OR QT_INTERNAL_CALLED_FROM_CONFIGURE) + AND DEFINED INPUT_${feature} + AND NOT "${INPUT_${feature}}" STREQUAL "undefined" + AND NOT "${INPUT_${feature}}" STREQUAL "") if(INPUT_${feature}) set(FEATURE_${feature} ON) else() @@ -906,6 +911,18 @@ function(qt_internal_detect_dirty_features) endif() endfunction() +function(qt_internal_clean_feature_inputs) + foreach(feature IN LISTS QT_KNOWN_FEATURES) + # Unset the INPUT_foo cache variables after they were used in feature evaluation, to + # ensure stale values don't influence features upon reconfiguration when + # QT_INTERNAL_CALLED_FROM_CONFIGURE is TRUE and the INPUT_foo variable is not passed. + # e.g. first configure -no-gui, then manually toggle FEATURE_gui to ON in + # CMakeCache.txt, then reconfigure (with the configure script) without -no-gui. + # Without this unset(), we'd have switched FEATURE_gui to OFF again. + unset(INPUT_${feature} CACHE) + endforeach() +endfunction() + function(qt_config_compile_test name) if(DEFINED "TEST_${name}") return() diff --git a/cmake/QtProcessConfigureArgs.cmake b/cmake/QtProcessConfigureArgs.cmake index 995f64a95fc..f8f6d309810 100644 --- a/cmake/QtProcessConfigureArgs.cmake +++ b/cmake/QtProcessConfigureArgs.cmake @@ -179,6 +179,10 @@ else() set(multi_config OFF) endif() +# Tell the build system we are configuring via the configure script so we can act on that. +# The cache variable is unset at the end of configuration. +push("-DQT_INTERNAL_CALLED_FROM_CONFIGURE:BOOL=TRUE") + if(FRESH_REQUESTED) push("-DQT_INTERNAL_FRESH_REQUESTED:BOOL=TRUE") if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24") diff --git a/cmake/QtSetup.cmake b/cmake/QtSetup.cmake index 5c9e56e6e6a..dfad3e77061 100644 --- a/cmake/QtSetup.cmake +++ b/cmake/QtSetup.cmake @@ -14,8 +14,10 @@ if(NOT QT_INTERNAL_IS_STANDALONE_TEST) "When this is present and set to true, it signals that we are building Qt from source.") endif() -# Pre-calculate the developer_build feature if it's set by the user via INPUT_developer_build -if(NOT DEFINED FEATURE_developer_build +# Pre-calculate the developer_build feature if it's set by the user via the INPUT_developer_build +# variable when using the configure script. When not using configure, don't take the INPUT variable +# into account, so that users can toggle the feature directly in the cache or via IDE. +if((NOT DEFINED FEATURE_developer_build OR QT_INTERNAL_CALLED_FROM_CONFIGURE) AND DEFINED INPUT_developer_build AND NOT "${INPUT_developer_build}" STREQUAL "undefined" AND NOT "${INPUT_developer_build}" STREQUAL "") @@ -28,7 +30,7 @@ endif() # Pre-calculate the no_prefix feature if it's set by configure via INPUT_no_prefix. # This needs to be done before qtbase/configure.cmake is processed. -if(NOT DEFINED FEATURE_no_prefix +if((NOT DEFINED FEATURE_no_prefix OR QT_INTERNAL_CALLED_FROM_CONFIGURE) AND DEFINED INPUT_no_prefix AND NOT "${INPUT_no_prefix}" STREQUAL "undefined" AND NOT "${INPUT_no_prefix}" STREQUAL "")