Do define generation after feature evaluation

Instead of generating defines guarded by feature ifdefs,
record the define information (condition, name, value, etc),
and generate the final define statement only if the feature
condition evaluated to true.

This removes the need to generate feature defines
(QT_FEATURE_foo) for features that have neither public nor
private outputs in the configure.json file.

Also note that all qt_feature_definition() calls
(which correspond to type:"define" outputs in json files)
now generate defines only in the public header, which seems
to be consistent with how qmake evaluates json files.

Change-Id: I5210b405d5735dd9df5f7a55d1ea9547bb7b1159
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
bb10
Alexandru Croitor 2019-03-14 11:27:38 +01:00
parent 64147fcb33
commit e5b2699750
1 changed files with 42 additions and 20 deletions

View File

@ -21,6 +21,8 @@ function(qt_feature_module_begin)
set(__QtFeature_private_extra "" PARENT_SCOPE)
set(__QtFeature_public_extra "" PARENT_SCOPE)
set(__QtFeature_define_definitions "" PARENT_SCOPE)
endfunction()
function(qt_feature feature)
@ -252,31 +254,44 @@ endfunction()
function(qt_feature_definition feature name)
qt_parse_all_arguments(arg "qt_feature_definition" "NEGATE" "VALUE" "" ${ARGN})
# Generate code:
set(expected 1)
if (arg_NEGATE)
set(expected -1)
endif()
set(msg "\n#if defined(QT_FEATURE_${feature}) && QT_FEATURE_${feature} == ${expected}\n")
if (arg_VALUE)
string(APPEND msg "# define ${name} ${arg_VALUE}\n")
else()
string(APPEND msg "# define ${name}\n")
endif()
string(APPEND msg "#endif\n")
# Store all the define related info in a unique variable key.
set(key_name "_QT_FEATURE_DEFINE_DEFINITION_${feature}_${name}")
set(${key_name} "FEATURE;${feature};NAME;${name};${ARGN}" PARENT_SCOPE)
# Store for later use:
list(FIND __QtFeature_public_features "${feature}" public_index)
if (public_index GREATER -1)
string(APPEND __QtFeature_public_extra "${msg}")
# Store the key for later evaluation and subsequent define generation:
list(APPEND __QtFeature_define_definitions "${key_name}")
set(__QtFeature_define_definitions ${__QtFeature_define_definitions} PARENT_SCOPE)
endfunction()
function(qt_evaluate_feature_definition key)
if(NOT DEFINED ${key})
qt_debug_print_variables(DEDUP MATCH "^_QT_FEATURE_DEFINE_DEFINITION")
message(FATAL_ERROR "Attempting to evaluate feature define ${key} but its definition is missing. ")
endif()
list(FIND __QtFeature_private_features "${feature}" private_index)
if (private_index GREATER -1)
string(APPEND __QtFeature_private_extra "${msg}")
cmake_parse_arguments(arg
"NEGATE;"
"FEATURE;NAME;VALUE;" "" ${${key}})
set(expected ON)
if (arg_NEGATE)
set(expected OFF)
endif()
set(msg "")
if(QT_FEATURE_${arg_FEATURE} STREQUAL expected)
if (arg_VALUE)
string(APPEND msg "#define ${arg_NAME} ${arg_VALUE}\n")
else()
string(APPEND msg "#define ${arg_NAME}\n")
endif()
string(APPEND __QtFeature_public_extra "${msg}")
endif()
set(__QtFeature_public_extra ${__QtFeature_public_extra} PARENT_SCOPE)
set(__QtFeature_private_extra ${__QtFeature_private_extra} PARENT_SCOPE)
endfunction()
function(qt_extra_definition name value)
@ -345,6 +360,11 @@ function(qt_feature_module_end target)
endif()
endforeach()
foreach(key ${__QtFeature_define_definitions})
qt_evaluate_feature_definition(${key})
unset(${key} PARENT_SCOPE)
endforeach()
foreach(feature ${all_features})
unset(_QT_FEATURE_DEFINITION_${feature} PARENT_SCOPE)
endforeach()
@ -386,6 +406,8 @@ function(qt_feature_module_end target)
unset(__QtFeature_private_extra PARENT_SCOPE)
unset(__QtFeature_public_extra PARENT_SCOPE)
unset(__QtFeature_define_definitions PARENT_SCOPE)
endfunction()
function(qt_config_compile_test name)