diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-09-25 14:16:57 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-09-27 08:43:16 +0000 |
commit | 6f5b1dd9ab257542c9f1d0be324968a487e9a77b (patch) | |
tree | e17d1cd3d9b9ca8f3fcb275da0d1e1198403abed | |
parent | 316353b3e00a08cbf9bb93d2d94e9e9693d3b5a5 (diff) |
pro2cmake: Handle WINDOWS_SDK_VERSION and simplifications
Add custom code to handle WINDOWS_SDK_VERSION comparisons,
similar to how it was done for QT_GCC_MAJOR_VERSION.
Also fix simplify_condition to do mapping of conditions to unified
tokens, similar how it was done for target conditions, so that the
simplification process does not fail because of whitespace.
Change-Id: Ia0cec6e1ffeed4c7859bb2a44423d0160222f425
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rwxr-xr-x | util/cmake/pro2cmake.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 46cce9b78b..b842e9fcc3 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -1507,6 +1507,21 @@ def map_condition(condition: str) -> str: pattern = r"(equals|greaterThan|lessThan)\(QT_GCC_([A-Z]+)_VERSION,[ ]*([0-9]+)\)" condition = re.sub(pattern, gcc_version_handler, condition) + def windows_sdk_version_handler(match_obj: Match): + operator = match_obj.group(1) + if operator == "equals": + operator = "STREQUAL" + elif operator == "greaterThan": + operator = "STRGREATER" + elif operator == "lessThan": + operator = "STRLESS" + + version = match_obj.group(2) + return f"(QT_WINDOWS_SDK_VERSION {operator} {version})" + + pattern = r"(equals|greaterThan|lessThan)\(WINDOWS_SDK_VERSION,[ ]*([0-9]+)\)" + condition = re.sub(pattern, windows_sdk_version_handler, condition) + # Handle if(...) conditions. condition = unwrap_if(condition) @@ -2205,6 +2220,16 @@ def simplify_condition(condition: str) -> str: target_symbol_mapping[target_condition_symbol_name] = target_condition condition = re.sub(target_condition, target_condition_symbol_name, condition) + # Do similar token mapping for comparison operators. + pattern = re.compile(r"([a-zA-Z_0-9]+ (?:STRLESS|STREQUAL|STRGREATER) [a-zA-Z_0-9]+)") + comparison_symbol_mapping = {} + all_comparisons = re.findall(pattern, condition) + for comparison in all_comparisons: + # Replace spaces and colons with underscores. + comparison_symbol_name = re.sub("[ ]", "_", comparison) + comparison_symbol_mapping[comparison_symbol_name] = comparison + condition = re.sub(comparison, comparison_symbol_name, condition) + try: # Generate and simplify condition using sympy: condition_expr = simplify_logic(condition) @@ -2214,6 +2239,10 @@ def simplify_condition(condition: str) -> str: for symbol_name in target_symbol_mapping: condition = re.sub(symbol_name, target_symbol_mapping[symbol_name], condition) + # Restore comparisons. + for comparison in comparison_symbol_mapping: + condition = re.sub(comparison, comparison_symbol_mapping[comparison], condition) + # Map back to CMake syntax: condition = condition.replace("~", "NOT ") condition = condition.replace("&", "AND") |