Skip to content

Commit

Permalink
CMake: Add debug information for 'qt_evaluate_config_expression'
Browse files Browse the repository at this point in the history
Add '_qt_internal_dump_expression_values' function that dumps all
values evaluated by 'qt_evaluate_config_expression'.
'_qt_internal_dump_expression_values' doesn't evaluate undefined
features, only collect actual values.

Fixes: QTBUG-88476
Pick-to: 6.0
Change-Id: I9d09ffbd9f9fa91bc4f36536c58e7f118b06f9b9
Reviewed-by: Alexandru Croitor <[email protected]>
  • Loading branch information
semlanik committed Nov 30, 2020
1 parent abee4cd commit c140b26
Showing 1 changed file with 64 additions and 3 deletions.
67 changes: 64 additions & 3 deletions cmake/QtFeature.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,63 @@ function(qt_evaluate_config_expression resultVar)
set(${resultVar} ${result} PARENT_SCOPE)
endfunction()

function(_qt_internal_dump_expression_values expression_dump expression)
set(dump "")
set(skipNext FALSE)
set(isTargetExpression FALSE)

set(keywords "EQUAL" "LESS" "LESS_EQUAL" "GREATER" "GREATER_EQUAL" "STREQUAL" "STRLESS"
"STRLESS_EQUAL" "STRGREATER" "STRGREATER_EQUAL" "VERSION_EQUAL" "VERSION_LESS"
"VERSION_LESS_EQUAL" "VERSION_GREATER" "VERSION_GREATER_EQUAL" "MATCHES"
"EXISTS" "COMMAND" "DEFINED" "NOT" "AND" "OR" "TARGET" "EXISTS" "IN_LIST" "(" ")")

list(LENGTH expression length)
math(EXPR length "${length}-1")

if(${length} LESS 0)
return()
endif()

foreach(memberIdx RANGE ${length})
if(${skipNext})
set(skipNext FALSE)
continue()
endif()

list(GET expression ${memberIdx} member)
if(NOT "${member}" IN_LIST keywords)
string(FIND "${member}" "QT_FEATURE_" idx)
if(idx EQUAL 0)
if(NOT DEFINED ${member})
list(APPEND dump "${member} not evaluated")
else()
list(APPEND dump "${member} = \"${${member}}\"")
endif()
elseif(isTargetExpression)
set(targetExpression "TARGET;${member}")
if(${targetExpression})
list(APPEND dump "TARGET ${member} found")
else()
list(APPEND dump "TARGET ${member} not found")
endif()
else()
list(APPEND dump "${member} = \"${${member}}\"")
endif()
set(isTargetExpression FALSE)
set(skipNext FALSE)
elseif("${member}" STREQUAL "TARGET")
set(isTargetExpression TRUE)
elseif("${member}" STREQUAL "STREQUAL")
set(skipNext TRUE)
else()
set(skipNext FALSE)
set(isTargetExpression FALSE)
endif()
endforeach()
string(JOIN "\n " ${expression_dump} ${dump})
set(${expression_dump} "${${expression_dump}}" PARENT_SCOPE)
endfunction()

function(qt_feature_set_cache_value resultVar feature emit_if calculated label)
if (DEFINED "FEATURE_${feature}")
# Must set up the cache
Expand Down Expand Up @@ -200,11 +257,14 @@ function(qt_feature_set_cache_value resultVar feature emit_if calculated label)
set("${resultVar}" "${result}" PARENT_SCOPE)
endfunction()

macro(qt_feature_set_value feature cache condition label)
macro(qt_feature_set_value feature cache condition label conditionExpression)
set(result "${cache}")

if (NOT (condition) AND (cache))
message(SEND_ERROR "Feature \"${feature}\": Forcing to \"${cache}\" breaks its condition.")
_qt_internal_dump_expression_values(conditionDump "${conditionExpression}")
string(JOIN " " conditionString ${conditionExpression})
message(SEND_ERROR "Feature \"${feature}\": Forcing to \"${cache}\" breaks its condition:\
\n ${conditionString}\nCondition values dump:\n ${conditionDump}\n")
endif()

if (DEFINED "QT_FEATURE_${feature}")
Expand Down Expand Up @@ -285,7 +345,8 @@ function(qt_evaluate_feature feature)
endif()

qt_feature_set_cache_value(cache "${feature}" "${emit_if}" "${result}" "${arg_LABEL}")
qt_feature_set_value("${feature}" "${cache}" "${condition}" "${arg_LABEL}")
qt_feature_set_value("${feature}" "${cache}" "${condition}" "${arg_LABEL}"
"${arg_CONDITION}")

# Store each feature's label for summary info.
set(QT_FEATURE_LABEL_${feature} "${arg_LABEL}" CACHE INTERNAL "")
Expand Down

0 comments on commit c140b26

Please sign in to comment.