CMake: Fix reconfiguration when -no-opengl is specified

In a previous change, we ensured that all INPUT_foo cache variables are
unset at the end of configuration, so they don't influence feature
re-evaluation in case if a command line flag like -no-gui is not
specified upon second reconfiguration and a FEATURE_foo is manually
toggled in the CMakeCache.txt, effectively getting rid of
stale INPUT_foo values.

Unfortunately that causes an issue when configuring with -no-opengl
and then trying to reconfigure with 'cmake .'

Specifically various feature options like ENABLE / DISABLE use
INPUT_foo variables in their expressions.
qt_configure_add_report_entry CONDITIONs also use them.

These expect the INPUT_foo variables to be persisted, and if they are
removed, the expressions might be re-evaluated to a different value,
and cause re-configuration to fail or unexpectedly toggle features.

To support both cases described above, instead of removing all INPUT
variables when configuration ends, only unset those INPUT variables
whose corresponding FEATURE_foo variable has been manually toggled in
CMakeCache.txt or via an IDE.

Toggling a FEATURE_foo manually is intentional, which means the
INPUT_foo value should be discarded. Whereas pre-existing INPUT_bar
variables will persist, thus not breaking cases like the -no-opengl
report CONDITION.

Amends 2799391703

Pick-to: 6.6
Fixes: QTBUG-116973
Task-number: QTBUG-112957
Change-Id: I5851255bfa41a9a1d116630a5d9f7b9a74aa93ed
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Alexandru Croitor 2023-09-12 16:57:56 +02:00
parent 47a42b9c6a
commit d1a17d9655
2 changed files with 17 additions and 15 deletions

View File

@ -106,6 +106,8 @@ endif()
include(QtPlatformSupport)
# Set FEATURE_${feature} if INPUT_${feature} is set in certain circumstances.
# Set FEATURE_${feature}_computed_from_input to TRUE or FALSE depending on whether the
# INPUT_${feature} value has overridden the FEATURE_${feature} variable.
#
# Needs to be in QtBuildInternalsConfig.cmake instead of QtFeature.cmake because it's used in
# qt_build_internals_disable_pkg_config_if_needed.
@ -126,6 +128,9 @@ function(qt_internal_compute_feature_value_from_possible_input feature)
endif()
set(FEATURE_${feature} "${FEATURE_${feature}}" PARENT_SCOPE)
set(FEATURE_${feature}_computed_from_input TRUE PARENT_SCOPE)
else()
set(FEATURE_${feature}_computed_from_input FALSE PARENT_SCOPE)
endif()
endfunction()
@ -635,9 +640,6 @@ function(qt_internal_qt_configure_end)
# 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)

View File

@ -883,6 +883,18 @@ function(qt_internal_detect_dirty_features)
"to ${FEATURE_${feature}}")
set(dirty_build TRUE)
set_property(GLOBAL APPEND PROPERTY _qt_dirty_features "${feature}")
# If the user changed the value of the feature directly (e.g by editing
# CMakeCache.txt), and not via its associated INPUT variable, unset the INPUT cache
# variable before it is used in feature evaluation, to ensure a stale value doesn't
# influence other feature values, especially 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.
if(NOT FEATURE_${feature}_computed_from_input)
unset("INPUT_${feature}" CACHE)
endif()
endif()
unset("QT_FEATURE_${feature}" CACHE)
endforeach()
@ -899,18 +911,6 @@ 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()