pro2cmake: Handle QT_(MAJOR_|MINOR_|PATCH_)VERSION conditions

Task-number: QTBUG-98852
Change-Id: I4c86fff7bbcc6c42cd04094f2409c3d04779597c
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2022-03-04 12:49:44 +01:00
parent 0dc374c9d8
commit 928828b549
3 changed files with 38 additions and 0 deletions

View File

@ -1669,6 +1669,28 @@ def map_condition(condition: str) -> str:
pattern = r"(equals|greaterThan|lessThan)\(WINDOWS_SDK_VERSION,[ ]*([0-9]+)\)"
condition = re.sub(pattern, windows_sdk_version_handler, condition)
def qt_version_handler(match_obj: Match):
operator = match_obj.group(1)
if operator == "equals":
operator = "EQUAL"
elif operator == "greaterThan":
operator = "GREATER"
elif operator == "lessThan":
operator = "LESS"
operator_prefix = "VERSION_"
version_variable = "QT_VERSION"
version_flavor = match_obj.group(2)
if version_flavor:
version_variable += "_" + version_flavor[:-1]
operator_prefix = ""
version = match_obj.group(3)
return f"({version_variable} {operator_prefix}{operator} {version})"
pattern = r"(equals|greaterThan|lessThan)\(QT_(MAJOR_|MINOR_|PATCH_)?VERSION,[ ]*([0-9.]+)\)"
condition = re.sub(pattern, qt_version_handler, condition)
# Generic lessThan|equals|lessThan()
def generic_version_handler(match_obj: Match):

View File

@ -0,0 +1,8 @@
QT += core gui
SOURCES += main.cpp
greaterThan(QT_MAJOR_VERSION, 5):lessThan(QT_MINOR_VERSION, 1):equals(QT_PATCH_VERSION, 0) {
DEFINES += SUPER_FRESH_MAJOR_QT_RELEASE
}
greaterThan(QT_VERSION, 6.6.5):lessThan(QT_VERSION, 6.6.7):equals(QT_VERSION, 6.6.6): {
DEFINES += QT_VERSION_OF_THE_BEAST
}

View File

@ -81,3 +81,11 @@ def test_qt_modules():
assert(["find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)",
"find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Network Widgets)",
"find_package(Qt${QT_VERSION_MAJOR} OPTIONAL_COMPONENTS OpenGL)"] == find_package_lines)
def test_qt_version_check():
output = convert("qt_version_check")
interesting_lines = []
for line in output.split("\n"):
if line.startswith("if(") and "QT_VERSION" in line:
interesting_lines.append(line.strip())
assert(["if(( ( (QT_VERSION_MAJOR GREATER 5) ) AND (QT_VERSION_MINOR LESS 1) ) AND (QT_VERSION_PATCH EQUAL 0))", "if(( ( (QT_VERSION VERSION_GREATER 6.6.5) ) AND (QT_VERSION VERSION_LESS 6.6.7) ) AND (QT_VERSION VERSION_EQUAL 6.6.6))"] == interesting_lines)