diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2022-03-04 11:06:58 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2022-03-08 03:45:30 +0100 |
commit | 3954b7385ef401a1ee9be76376e421bf1b54c298 (patch) | |
tree | 556098ea847ceb5e6d4d3fca68c72df2bbd8cd77 /util | |
parent | eab2a57b3758af4c8a08194d072ddd47a63fe6dd (diff) |
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>
Diffstat (limited to 'util')
-rwxr-xr-x | util/cmake/pro2cmake.py | 16 | ||||
-rwxr-xr-x | util/cmake/tests/test_conversion.py | 8 |
2 files changed, 19 insertions, 5 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 7ae1e0610f..63dd35ccb5 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -3738,6 +3738,7 @@ def write_find_package_section( indent: int = 0, is_required: bool = True, end_with_extra_newline: bool = True, + qt_package_name: str = "Qt6", ): packages = [] # type: List[LibraryMapping] all_libs = public_libs + private_libs @@ -3752,8 +3753,10 @@ def write_find_package_section( if p.components is not None: qt_components += p.components if qt_components: + if "Core" in qt_components: + qt_components.remove("Core") 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: qt_package.extra = ["REQUIRED"] cm_fh.write( @@ -3908,11 +3911,19 @@ def write_example( handle_source_subtractions(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. # We consider packages as required if they appear at the top-level scope. (public_libs, private_libs) = extract_cmake_libraries(scope, is_example=True) 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. @@ -3934,6 +3945,7 @@ def write_example( indent=indent, is_required=False, end_with_extra_newline=False, + qt_package_name="Qt${QT_VERSION_MAJOR}", ) cm_fh.write("\n") diff --git a/util/cmake/tests/test_conversion.py b/util/cmake/tests/test_conversion.py index ad4a852012..54ddd35d9c 100755 --- a/util/cmake/tests/test_conversion.py +++ b/util/cmake/tests/test_conversion.py @@ -70,12 +70,14 @@ def test_qt_modules(): for line in output.split("\n"): if "find_package(" in line: 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") find_package_lines = [] for line in output.split("\n"): if "find_package(" in line: find_package_lines.append(line.strip()) - assert(["find_package(Qt6 REQUIRED COMPONENTS Core Network Widgets)", - "find_package(Qt6 OPTIONAL_COMPONENTS OpenGL)"] == 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(Qt${QT_VERSION_MAJOR} OPTIONAL_COMPONENTS OpenGL)"] == find_package_lines) |