summaryrefslogtreecommitdiffstats
path: root/cmake/QtFeature.cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-03-14 11:27:38 +0100
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-03-18 15:34:13 +0000
commite5b26997500a56f42be920a509821358f60aaa53 (patch)
tree976776a10eb0db6c49348d4e099ac02be33d4fe0 /cmake/QtFeature.cmake
parent64147fcb3380244c0dcf744dc84f31ec917cc608 (diff)
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>
Diffstat (limited to 'cmake/QtFeature.cmake')
-rw-r--r--cmake/QtFeature.cmake58
1 files changed, 40 insertions, 18 deletions
diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake
index 030bcd90c9..38ff328de4 100644
--- a/cmake/QtFeature.cmake
+++ b/cmake/QtFeature.cmake
@@ -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)
+ # 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 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()
- 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")
+
+ cmake_parse_arguments(arg
+ "NEGATE;"
+ "FEATURE;NAME;VALUE;" "" ${${key}})
+
+ set(expected ON)
+ if (arg_NEGATE)
+ set(expected OFF)
endif()
- string(APPEND msg "#endif\n")
- # Store for later use:
- list(FIND __QtFeature_public_features "${feature}" public_index)
- if (public_index GREATER -1)
+ 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()
- list(FIND __QtFeature_private_features "${feature}" private_index)
- if (private_index GREATER -1)
- string(APPEND __QtFeature_private_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)