diff --git a/cmake/QtPlatformSupport.cmake b/cmake/QtPlatformSupport.cmake index 20feb1cc4a9..2468932179b 100644 --- a/cmake/QtPlatformSupport.cmake +++ b/cmake/QtPlatformSupport.cmake @@ -38,3 +38,42 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8) elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) set(QT_32BIT TRUE) endif() + +# Parses a version string like "xx.yy.zz" and sets the major, minor and patch variables. +function(qt_parse_version_string version_string out_var_prefix) + string(REPLACE "." ";" version_list ${version_string}) + list(LENGTH version_list length) + + set(out_var "${out_var_prefix}_MAJOR") + set(value "") + if(length GREATER 0) + list(GET version_list 0 value) + list(REMOVE_AT version_list 0) + endif() + set(${out_var} "${value}" PARENT_SCOPE) + + set(out_var "${out_var_prefix}_MINOR") + set(value "") + if(length GREATER 0) + list(GET version_list 0 value) + set(${out_var} "${value}" PARENT_SCOPE) + list(REMOVE_AT version_list 0) + endif() + set(${out_var} "${value}" PARENT_SCOPE) + + set(out_var "${out_var_prefix}_PATCH") + set(value "") + if(length GREATER 0) + list(GET version_list 0 value) + set(${out_var} "${value}" PARENT_SCOPE) + list(REMOVE_AT version_list 0) + + endif() + set(${out_var} "${value}" PARENT_SCOPE) +endfunction() + +# Set up the separate version components for the compiler version, to allow mapping of qmake +# conditions like 'equals(QT_GCC_MAJOR_VERSION,5)'. +if(CMAKE_CXX_COMPILER_VERSION) + qt_parse_version_string("${CMAKE_CXX_COMPILER_VERSION}" "QT_COMPILER_VERSION") +endif() diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index b45f0e88054..dfe407da6d0 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)