pro2cmake: Generate find_package call for Qt5/Qt6 for examples
This makes the QT_VERSION_(MAJOR|MINOR|PATH) variables available. Task-number: QTBUG-98852 Change-Id: I7e40f2a7ac09975ce21e45cda384af928e1fa629 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
parent
eab2a57b37
commit
3954b7385e
@ -3738,6 +3738,7 @@ def write_find_package_section(
|
|||||||
indent: int = 0,
|
indent: int = 0,
|
||||||
is_required: bool = True,
|
is_required: bool = True,
|
||||||
end_with_extra_newline: bool = True,
|
end_with_extra_newline: bool = True,
|
||||||
|
qt_package_name: str = "Qt6",
|
||||||
):
|
):
|
||||||
packages = [] # type: List[LibraryMapping]
|
packages = [] # type: List[LibraryMapping]
|
||||||
all_libs = public_libs + private_libs
|
all_libs = public_libs + private_libs
|
||||||
@ -3752,8 +3753,10 @@ def write_find_package_section(
|
|||||||
if p.components is not None:
|
if p.components is not None:
|
||||||
qt_components += p.components
|
qt_components += p.components
|
||||||
if qt_components:
|
if qt_components:
|
||||||
|
if "Core" in qt_components:
|
||||||
|
qt_components.remove("Core")
|
||||||
qt_components = sorted(qt_components)
|
qt_components = sorted(qt_components)
|
||||||
qt_package = LibraryMapping("unknown", "Qt6", "unknown", components=qt_components)
|
qt_package = LibraryMapping("unknown", qt_package_name, "unknown", components=qt_components)
|
||||||
if is_required:
|
if is_required:
|
||||||
qt_package.extra = ["REQUIRED"]
|
qt_package.extra = ["REQUIRED"]
|
||||||
cm_fh.write(
|
cm_fh.write(
|
||||||
@ -3908,11 +3911,19 @@ def write_example(
|
|||||||
handle_source_subtractions(scopes)
|
handle_source_subtractions(scopes)
|
||||||
scopes = merge_scopes(scopes)
|
scopes = merge_scopes(scopes)
|
||||||
|
|
||||||
|
# Write find_package call for Qt5/Qt6 and make it available as package QT.
|
||||||
|
cm_fh.write("find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)\n")
|
||||||
|
|
||||||
# Write find_package calls for required packages.
|
# Write find_package calls for required packages.
|
||||||
# We consider packages as required if they appear at the top-level scope.
|
# We consider packages as required if they appear at the top-level scope.
|
||||||
(public_libs, private_libs) = extract_cmake_libraries(scope, is_example=True)
|
(public_libs, private_libs) = extract_cmake_libraries(scope, is_example=True)
|
||||||
write_find_package_section(
|
write_find_package_section(
|
||||||
cm_fh, public_libs, private_libs, indent=indent, end_with_extra_newline=False
|
cm_fh,
|
||||||
|
public_libs,
|
||||||
|
private_libs,
|
||||||
|
indent=indent,
|
||||||
|
end_with_extra_newline=False,
|
||||||
|
qt_package_name="Qt${QT_VERSION_MAJOR}",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Write find_package calls for optional packages.
|
# Write find_package calls for optional packages.
|
||||||
@ -3934,6 +3945,7 @@ def write_example(
|
|||||||
indent=indent,
|
indent=indent,
|
||||||
is_required=False,
|
is_required=False,
|
||||||
end_with_extra_newline=False,
|
end_with_extra_newline=False,
|
||||||
|
qt_package_name="Qt${QT_VERSION_MAJOR}",
|
||||||
)
|
)
|
||||||
|
|
||||||
cm_fh.write("\n")
|
cm_fh.write("\n")
|
||||||
|
@ -70,12 +70,14 @@ def test_qt_modules():
|
|||||||
for line in output.split("\n"):
|
for line in output.split("\n"):
|
||||||
if "find_package(" in line:
|
if "find_package(" in line:
|
||||||
find_package_lines.append(line.strip())
|
find_package_lines.append(line.strip())
|
||||||
assert(["find_package(Qt6 REQUIRED COMPONENTS Core Network Widgets)"] == find_package_lines)
|
assert(["find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)",
|
||||||
|
"find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Network Widgets)"] == find_package_lines)
|
||||||
|
|
||||||
output = convert("optional_qt_modules")
|
output = convert("optional_qt_modules")
|
||||||
find_package_lines = []
|
find_package_lines = []
|
||||||
for line in output.split("\n"):
|
for line in output.split("\n"):
|
||||||
if "find_package(" in line:
|
if "find_package(" in line:
|
||||||
find_package_lines.append(line.strip())
|
find_package_lines.append(line.strip())
|
||||||
assert(["find_package(Qt6 REQUIRED COMPONENTS Core Network Widgets)",
|
assert(["find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)",
|
||||||
"find_package(Qt6 OPTIONAL_COMPONENTS OpenGL)"] == find_package_lines)
|
"find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Network Widgets)",
|
||||||
|
"find_package(Qt${QT_VERSION_MAJOR} OPTIONAL_COMPONENTS OpenGL)"] == find_package_lines)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user