Skip to content

Truly independent web browser

Meta: Explicitly find Qt plugins before importing them

Timothy Flynn61fe640c73b4
diff --git a/Meta/CMake/utils.cmake b/Meta/CMake/utils.cmake
index 2431e6053c3..b631e12d00e 100644
--- a/Meta/CMake/utils.cmake
+++ b/Meta/CMake/utils.cmake
@@ -1,4 +1,3 @@
-
include(${CMAKE_CURRENT_LIST_DIR}/code_generators.cmake)
function(ladybird_generated_sources target_name)
@@ -275,3 +274,18 @@ function(add_lagom_library_install_rules target_name)
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endfunction()
+
+function(ladybird_import_qt_plugin target_name plugin_name)
+ # Some Qt installations (such as Ubuntu's) do not automatically load plugin CMake targets. Find the plugin
+ # explicitly so qt_import_plugins can recognize it.
+ if (NOT TARGET Qt6::${plugin_name})
+ find_package(Qt6${plugin_name} QUIET
+ PATHS "${Qt6Gui_DIR}"
+ NO_DEFAULT_PATH
+ )
+ endif()
+
+ if (TARGET Qt6::${plugin_name})
+ qt_import_plugins(${target_name} INCLUDE Qt6::${plugin_name})
+ endif()
+endfunction()
diff --git a/Tests/UI/Qt/CMakeLists.txt b/Tests/UI/Qt/CMakeLists.txt
index ba675a8d62d..ea3265f085e 100644
--- a/Tests/UI/Qt/CMakeLists.txt
+++ b/Tests/UI/Qt/CMakeLists.txt
@@ -10,7 +10,7 @@ if (Qt6_FOUND)
"${LADYBIRD_SOURCE_DIR}/Libraries/LibTest/AssertionHandler.cpp"
)
target_link_libraries(QtTestMain PRIVATE AK LibCore LibTest Qt::Core Qt::Gui Qt::Widgets)
- ladybird_test_suite(UI/Qt CUSTOM_MAIN "$<TARGET_OBJECTS:QtTestMain>")
+ ladybird_test_suite(UI/Qt NO_TEST CUSTOM_MAIN "$<TARGET_OBJECTS:QtTestMain>")
target_link_libraries(TestUIQt PRIVATE LibCore LibFileSystem LibGfx LibIPC LibURL LibWeb LibWebCommon LibWebView Qt::Core Qt::Gui Qt::Widgets)
else()
ladybird_test_suite(UI/Qt)
@@ -120,13 +120,17 @@ set_target_properties(TestUIQt PROPERTIES AUTOMOC ON)
# QtTestMain runs on the offscreen platform plugin. Static Qt needs it imported explicitly, and Windows needs it
# copied alongside the default platform plugin deployed by the ladybird target.
-qt_import_plugins(TestUIQt INCLUDE Qt6::QOffscreenIntegrationPlugin)
-if (WIN32)
- add_custom_command(TARGET TestUIQt POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:TestUIQt>/platforms"
- COMMAND ${CMAKE_COMMAND} -E copy_if_different
- "$<TARGET_FILE:Qt6::QOffscreenIntegrationPlugin>"
- "$<TARGET_FILE_DIR:TestUIQt>/platforms/"
- VERBATIM
- )
+ladybird_import_qt_plugin(TestUIQt QOffscreenIntegrationPlugin)
+if (TARGET Qt6::QOffscreenIntegrationPlugin)
+ add_test(NAME TestUIQt COMMAND TestUIQt WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+
+ if (WIN32)
+ add_custom_command(TARGET TestUIQt POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:TestUIQt>/platforms"
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ "$<TARGET_FILE:Qt6::QOffscreenIntegrationPlugin>"
+ "$<TARGET_FILE_DIR:TestUIQt>/platforms/"
+ VERBATIM
+ )
+ endif()
endif()
diff --git a/UI/Qt/CMakeLists.txt b/UI/Qt/CMakeLists.txt
index 00192b8ee2a..86d6f569f30 100644
--- a/UI/Qt/CMakeLists.txt
+++ b/UI/Qt/CMakeLists.txt
@@ -276,7 +276,10 @@ if (BUILD_TESTING AND NOT BUILD_BROWSER_TESTS_ONLY)
set_target_properties(TestPerformanceMonitorWidget PROPERTIES AUTOMOC ON)
target_include_directories(TestPerformanceMonitorWidget PRIVATE ${LADYBIRD_SOURCE_DIR})
target_link_libraries(TestPerformanceMonitorWidget PRIVATE Qt6::Widgets LibWebView LibURL AK)
- qt_import_plugins(TestPerformanceMonitorWidget INCLUDE Qt6::QOffscreenIntegrationPlugin)
- add_test(NAME TestPerformanceMonitorWidget COMMAND TestPerformanceMonitorWidget)
- set_tests_properties(TestPerformanceMonitorWidget PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen")
+
+ ladybird_import_qt_plugin(TestPerformanceMonitorWidget QOffscreenIntegrationPlugin)
+ if (TARGET Qt6::QOffscreenIntegrationPlugin)
+ add_test(NAME TestPerformanceMonitorWidget COMMAND TestPerformanceMonitorWidget)
+ set_tests_properties(TestPerformanceMonitorWidget PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen")
+ endif()
endif()