Skip to content

Commit

Permalink
CMake: Handle INPUT_foo values when detecting dirty builds
Browse files Browse the repository at this point in the history
Before this change, the dirty feature code only checked for
differences between FEATURE_foo and QT_FEATURE_foo, without taking
into account modified INPUT_foo values that might passed via the
configure script.
This led to issues in certain scenarios when reconfiguring with the
configure script.

For example configuring with -gui / -DINPUT_gui=ON and then with
-no-gui / -DINPUT_gui=OFF would fail saying
  'Feature "widgets": Forcing to "ON" breaks its condition'

This happens because the widgets feature depends on gui being
available, but because INPUT_gui modifications don't trigger the dirty
feature re-eval code, we don't recompute the value of widgets.

Extract the code that takes into account the INPUT_foo variables into
a separate function, and use it both when computing feature values and
also when detecting dirty features.

This means any non-matching INPUT_foo variables will now also trigger
dirty feature checking.

Use the same function to replace the duplicate code we have to early
initialize the developer-build, no-prefix and pkg-config features.

Pick-to: 6.6
Task-number: QTBUG-112957
Change-Id: I775cf70b48291a659b0fecf7cb9570ec12735bca
Reviewed-by: Alexey Edelev <[email protected]>
  • Loading branch information
alcroito committed Sep 6, 2023
1 parent 2799391 commit 4d86ca8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 45 deletions.
35 changes: 25 additions & 10 deletions cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,30 @@ endif()
# build.
include(QtPlatformSupport)

# Set FEATURE_${feature} if INPUT_${feature} is set in certain circumstances.
#
# Needs to be in QtBuildInternalsConfig.cmake instead of QtFeature.cmake because it's used in
# qt_build_internals_disable_pkg_config_if_needed.
function(qt_internal_compute_feature_value_from_possible_input feature)
# 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()
set(FEATURE_${feature} OFF)
endif()

set(FEATURE_${feature} "${FEATURE_${feature}}" PARENT_SCOPE)
endif()
endfunction()

function(qt_build_internals_disable_pkg_config_if_needed)
# pkg-config should not be used by default on Darwin and Windows platforms (and QNX), as defined
# in the qtbase/configure.json. Unfortunately by the time the feature is evaluated there are
Expand All @@ -131,16 +155,7 @@ 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" 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()
set(FEATURE_pkg_config OFF)
endif()
endif()
qt_internal_compute_feature_value_from_possible_input(pkg_config)

# If user explicitly specified a value for the feature, honor it, even if it might break
# the build.
Expand Down
18 changes: 3 additions & 15 deletions cmake/QtFeature.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -410,21 +410,7 @@ function(qt_evaluate_feature feature)
qt_evaluate_config_expression(emit_if ${arg_EMIT_IF})
endif()

# 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()
set(FEATURE_${feature} OFF)
endif()
endif()
qt_internal_compute_feature_value_from_possible_input("${feature}")

# Warn about a feature which is not emitted, but the user explicitly provided a value for it.
if(NOT emit_if AND DEFINED FEATURE_${feature})
Expand Down Expand Up @@ -889,6 +875,8 @@ function(qt_internal_detect_dirty_features)
message(STATUS "Checking for feature set changes")
set_property(GLOBAL PROPERTY _qt_feature_clean TRUE)
foreach(feature ${QT_KNOWN_FEATURES})
qt_internal_compute_feature_value_from_possible_input("${feature}")

if(DEFINED "FEATURE_${feature}" AND
NOT "${QT_FEATURE_${feature}}" STREQUAL "${FEATURE_${feature}}")
message(" '${feature}' was changed from ${QT_FEATURE_${feature}} "
Expand Down
22 changes: 2 additions & 20 deletions cmake/QtSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,11 @@ endif()
# 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 "")
if(INPUT_developer_build)
set(FEATURE_developer_build ON)
else()
set(FEATURE_developer_build OFF)
endif()
endif()
qt_internal_compute_feature_value_from_possible_input(developer_build)

# 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 OR QT_INTERNAL_CALLED_FROM_CONFIGURE)
AND DEFINED INPUT_no_prefix
AND NOT "${INPUT_no_prefix}" STREQUAL "undefined"
AND NOT "${INPUT_no_prefix}" STREQUAL "")
if(INPUT_no_prefix)
set(FEATURE_no_prefix ON)
else()
set(FEATURE_no_prefix OFF)
endif()
endif()
qt_internal_compute_feature_value_from_possible_input(no_prefix)

set(_default_build_type "Release")
if(FEATURE_developer_build)
Expand Down

0 comments on commit 4d86ca8

Please sign in to comment.