diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-06-03 17:42:43 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-06-04 08:37:26 +0000 |
commit | 962ee4ea37f23000bbc342c5d50838abf0bcdb8e (patch) | |
tree | e780826b3dc7efc78d35ce29e6ea4fbebf5d22f3 /util | |
parent | 6686774fdc3da8bd64ad2766e67966b3cabb29b7 (diff) |
Handle a few more condition types in pro2cmake
qtdeclarative has a few conditions that check the gcc version
via variables like QT_GCC_MAJOR_VERSION.
To handle that, parse the CMake compiler version using
qt_parse_version_string() into separate variables like
QT_COMPILER_VERSION_MAJOR, QT_COMPILER_VERSION_MINOR and
QT_COMPILER_VERSION_PATCH. We can then map the conditions
appropriately.
Also, handle isEqual(foo, bar), which is equivalent equals(foo,bar).
Change-Id: I74575c733b44f1f42451e00038b3f113fd353915
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'util')
-rwxr-xr-x | util/cmake/pro2cmake.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index b45f0e8805..dfe407da6d 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -898,12 +898,37 @@ def map_condition(condition: str) -> str: condition = re.sub(r'^qtConfig\(opengl\.\*\)$', r'QT_FEATURE_opengl', condition) condition = re.sub(r'^win\*$', r'win', condition) + def gcc_version_handler(match_obj: re.Match): + operator = match_obj.group(1) + version_type = match_obj.group(2) + if operator == 'equals': + operator = 'STREQUAL' + elif operator == 'greaterThan': + operator = 'STRGREATER' + elif operator == 'lessThan': + operator = 'STRLESS' + + version = match_obj.group(3) + return '(QT_COMPILER_VERSION_{} {} {})'.format(version_type, operator, version) + + # TODO: Possibly fix for other compilers. + pattern = r'(equals|greaterThan|lessThan)\(QT_GCC_([A-Z]+)_VERSION,[ ]*([0-9]+)\)' + condition = re.sub(pattern, gcc_version_handler, condition) + + # TODO: the current if(...) replacement makes the parentheses + # unbalanced when there are nested expressions. + # Need to fix this either with pypi regex recursive regexps, + # using pyparsing, or some other proper means of handling + # balanced parentheses. condition = re.sub(r'\bif\s*\((.*?)\)', r'\1', condition) + condition = re.sub(r'\bisEmpty\s*\((.*?)\)', r'\1_ISEMPTY', condition) condition = re.sub(r'\bcontains\s*\((.*?),\s*"?(.*?)"?\)', r'\1___contains___\2', condition) condition = re.sub(r'\bequals\s*\((.*?),\s*"?(.*?)"?\)', r'\1___equals___\2', condition) + condition = re.sub(r'\bisEqual\s*\((.*?),\s*"?(.*?)"?\)', + r'\1___equals___\2', condition) condition = re.sub(r'\s*==\s*', '___STREQUAL___', condition) condition = re.sub(r'\bexists\s*\((.*?)\)', r'EXISTS \1', condition) |