Ladybird: Add configuration option to build without Qt

This should open the door for adding more GUI chromes to the repository
This commit is contained in:
Andrew Kaster 2023-08-07 19:42:06 -06:00 committed by Andrew Kaster
parent 1d78e07f6b
commit 79108f615d
Notes: sideshowbarker 2024-07-16 20:05:14 +09:00
3 changed files with 101 additions and 57 deletions

View file

@ -70,10 +70,18 @@ add_compile_options(-DAK_DONT_REPLACE_STD)
add_compile_options(-Wno-expansion-to-defined) add_compile_options(-Wno-expansion-to-defined)
add_compile_options(-Wno-user-defined-literals) add_compile_options(-Wno-user-defined-literals)
set(CMAKE_AUTOMOC ON) serenity_option(ENABLE_QT ON CACHE BOOL "Build ladybird application using Qt GUI")
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON) if (APPLE AND NOT ENABLE_QT)
find_package(Qt6 REQUIRED COMPONENTS Core Widgets Network Multimedia) message(FATAL_ERROR "Non-Qt builds not supported on macOS yet!")
endif()
if (ENABLE_QT)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt6 REQUIRED COMPONENTS Core Widgets Network Multimedia)
endif()
set(BROWSER_SOURCE_DIR ${SERENITY_SOURCE_DIR}/Userland/Applications/Browser/) set(BROWSER_SOURCE_DIR ${SERENITY_SOURCE_DIR}/Userland/Applications/Browser/)
@ -83,6 +91,11 @@ set(SOURCES
${BROWSER_SOURCE_DIR}/History.cpp ${BROWSER_SOURCE_DIR}/History.cpp
HelperProcess.cpp HelperProcess.cpp
Utilities.cpp Utilities.cpp
)
if (ENABLE_QT)
qt_add_executable(ladybird ${SOURCES})
target_sources(ladybird PRIVATE
Qt/BrowserWindow.cpp Qt/BrowserWindow.cpp
Qt/ConsoleWidget.cpp Qt/ConsoleWidget.cpp
Qt/EventLoopImplementationQt.cpp Qt/EventLoopImplementationQt.cpp
@ -98,10 +111,25 @@ set(SOURCES
Qt/WebContentView.cpp Qt/WebContentView.cpp
Qt/ladybird.qrc Qt/ladybird.qrc
Qt/main.cpp Qt/main.cpp
) )
target_link_libraries(ladybird PRIVATE Qt::Core Qt::Gui Qt::Network Qt::Widgets)
qt_add_executable(ladybird ${SOURCES}) # FIXME: Set these for non-qt executables as well, when those exist
target_link_libraries(ladybird PRIVATE Qt::Core Qt::Gui Qt::Network Qt::Widgets LibCore LibFileSystem LibGfx LibGUI LibIPC LibJS LibMain LibWeb LibWebView LibSQL LibProtocol) set_target_properties(ladybird PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER org.SerenityOS.Ladybird
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist"
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER org.SerenityOS.Ladybird
)
else()
# TODO: Check for other GUI frameworks here when we move them in-tree
# For now, we can export a static library of common files for chromes to link to
add_library(ladybird STATIC ${SOURCES})
endif()
target_link_libraries(ladybird PRIVATE LibCore LibFileSystem LibGfx LibGUI LibIPC LibJS LibMain LibWeb LibWebView LibSQL LibProtocol)
target_include_directories(ladybird PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(ladybird PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(ladybird PRIVATE ${SERENITY_SOURCE_DIR}/Userland/) target_include_directories(ladybird PRIVATE ${SERENITY_SOURCE_DIR}/Userland/)
@ -117,16 +145,6 @@ add_executable(headless-browser
target_include_directories(headless-browser PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(headless-browser PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(headless-browser PRIVATE LibWeb LibWebView LibWebSocket LibCrypto LibFileSystem LibGemini LibHTTP LibJS LibGfx LibMain LibTLS LibIPC LibDiff LibProtocol) target_link_libraries(headless-browser PRIVATE LibWeb LibWebView LibWebSocket LibCrypto LibFileSystem LibGemini LibHTTP LibJS LibGfx LibMain LibTLS LibIPC LibDiff LibProtocol)
set_target_properties(ladybird PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER org.SerenityOS.Ladybird
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist"
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER org.SerenityOS.Ladybird
)
if (ANDROID) if (ANDROID)
include(cmake/AndroidExtras.cmake) include(cmake/AndroidExtras.cmake)
link_android_libs(headless-browser) link_android_libs(headless-browser)

View file

@ -10,6 +10,12 @@ set(WEBCONTENT_SOURCES
../HelperProcess.cpp ../HelperProcess.cpp
../ImageCodecPlugin.cpp ../ImageCodecPlugin.cpp
../Utilities.cpp ../Utilities.cpp
main.cpp
)
if (ENABLE_QT)
qt_add_executable(WebContent ${WEBCONTENT_SOURCES})
target_sources(WebContent PRIVATE
../Qt/AudioCodecPluginQt.cpp ../Qt/AudioCodecPluginQt.cpp
../Qt/AudioThread.cpp ../Qt/AudioThread.cpp
../Qt/EventLoopImplementationQt.cpp ../Qt/EventLoopImplementationQt.cpp
@ -19,14 +25,16 @@ set(WEBCONTENT_SOURCES
../Qt/WebSocketClientManagerQt.cpp ../Qt/WebSocketClientManagerQt.cpp
../Qt/WebSocketQt.cpp ../Qt/WebSocketQt.cpp
../Qt/WebSocketImplQt.cpp ../Qt/WebSocketImplQt.cpp
main.cpp )
) target_link_libraries(WebContent PRIVATE Qt::Core Qt::Network Qt::Multimedia)
target_compile_definitions(WebContent PRIVATE HAVE_QT=1)
qt_add_executable(WebContent ${WEBCONTENT_SOURCES}) else()
add_executable(WebContent ${WEBCONTENT_SOURCES})
endif()
target_include_directories(WebContent PRIVATE ${SERENITY_SOURCE_DIR}/Userland/Services/) target_include_directories(WebContent PRIVATE ${SERENITY_SOURCE_DIR}/Userland/Services/)
target_include_directories(WebContent PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/..) target_include_directories(WebContent PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/..)
target_link_libraries(WebContent PRIVATE Qt::Core Qt::Network Qt::Multimedia LibAudio LibCore LibFileSystem LibGfx LibIPC LibJS LibMain LibWeb LibWebSocket LibProtocol LibSQL LibWebView) target_link_libraries(WebContent PRIVATE LibAudio LibCore LibFileSystem LibGfx LibIPC LibJS LibMain LibWeb LibWebSocket LibProtocol LibSQL LibWebView)
if (ANDROID) if (ANDROID)
link_android_libs(WebContent) link_android_libs(WebContent)
endif() endif()

View file

@ -8,10 +8,6 @@
#include <Ladybird/FontPlugin.h> #include <Ladybird/FontPlugin.h>
#include <Ladybird/HelperProcess.h> #include <Ladybird/HelperProcess.h>
#include <Ladybird/ImageCodecPlugin.h> #include <Ladybird/ImageCodecPlugin.h>
#include <Ladybird/Qt/AudioCodecPluginQt.h>
#include <Ladybird/Qt/EventLoopImplementationQt.h>
#include <Ladybird/Qt/RequestManagerQt.h>
#include <Ladybird/Qt/WebSocketClientManagerQt.h>
#include <Ladybird/Utilities.h> #include <Ladybird/Utilities.h>
#include <LibAudio/Loader.h> #include <LibAudio/Loader.h>
#include <LibCore/ArgsParser.h> #include <LibCore/ArgsParser.h>
@ -33,19 +29,29 @@
#include <LibWeb/WebSockets/WebSocket.h> #include <LibWeb/WebSockets/WebSocket.h>
#include <LibWebView/RequestServerAdapter.h> #include <LibWebView/RequestServerAdapter.h>
#include <LibWebView/WebSocketClientAdapter.h> #include <LibWebView/WebSocketClientAdapter.h>
#include <QCoreApplication>
#include <WebContent/ConnectionFromClient.h> #include <WebContent/ConnectionFromClient.h>
#include <WebContent/PageHost.h> #include <WebContent/PageHost.h>
#include <WebContent/WebDriverConnection.h> #include <WebContent/WebDriverConnection.h>
#if defined(HAVE_QT)
# include <Ladybird/Qt/AudioCodecPluginQt.h>
# include <Ladybird/Qt/EventLoopImplementationQt.h>
# include <Ladybird/Qt/RequestManagerQt.h>
# include <Ladybird/Qt/WebSocketClientManagerQt.h>
# include <QCoreApplication>
#endif
static ErrorOr<void> load_content_filters(); static ErrorOr<void> load_content_filters();
static ErrorOr<void> load_autoplay_allowlist(); static ErrorOr<void> load_autoplay_allowlist();
static ErrorOr<void> initialize_lagom_networking();
ErrorOr<int> serenity_main(Main::Arguments arguments) ErrorOr<int> serenity_main(Main::Arguments arguments)
{ {
#if defined(HAVE_QT)
QCoreApplication app(arguments.argc, arguments.argv); QCoreApplication app(arguments.argc, arguments.argv);
Core::EventLoopManager::install(*new Ladybird::EventLoopManagerQt); Core::EventLoopManager::install(*new Ladybird::EventLoopManagerQt);
#endif
Core::EventLoop event_loop; Core::EventLoop event_loop;
platform_init(); platform_init();
@ -56,8 +62,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Web::Platform::AudioCodecPlugin::install_creation_hook([](auto loader) { Web::Platform::AudioCodecPlugin::install_creation_hook([](auto loader) {
#if defined(HAVE_PULSEAUDIO) #if defined(HAVE_PULSEAUDIO)
return Web::Platform::AudioCodecPluginAgnostic::create(move(loader)); return Web::Platform::AudioCodecPluginAgnostic::create(move(loader));
#else #elif defined(HAVE_QT)
return Ladybird::AudioCodecPluginQt::create(move(loader)); return Ladybird::AudioCodecPluginQt::create(move(loader));
#else
# error "Don't know how to initialize audio in this configuration!"
#endif #endif
}); });
@ -73,17 +81,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_option(use_lagom_networking, "Enable Lagom servers for networking", "use-lagom-networking", 0); args_parser.add_option(use_lagom_networking, "Enable Lagom servers for networking", "use-lagom-networking", 0);
args_parser.parse(arguments); args_parser.parse(arguments);
if (use_lagom_networking) { #if defined(HAVE_QT)
auto candidate_request_server_paths = TRY(get_paths_for_helper_process("RequestServer"sv)); if (!use_lagom_networking) {
auto request_server_client = TRY(launch_request_server_process(candidate_request_server_paths, s_serenity_resource_root));
Web::ResourceLoader::initialize(TRY(WebView::RequestServerAdapter::try_create(move(request_server_client))));
auto candidate_web_socket_paths = TRY(get_paths_for_helper_process("WebSocket"sv));
auto web_socket_client = TRY(launch_web_socket_process(candidate_web_socket_paths, s_serenity_resource_root));
Web::WebSockets::WebSocketClientManager::initialize(TRY(WebView::WebSocketClientManagerAdapter::try_create(move(web_socket_client))));
} else {
Web::ResourceLoader::initialize(Ladybird::RequestManagerQt::create()); Web::ResourceLoader::initialize(Ladybird::RequestManagerQt::create());
Web::WebSockets::WebSocketClientManager::initialize(Ladybird::WebSocketClientManagerQt::create()); Web::WebSockets::WebSocketClientManager::initialize(Ladybird::WebSocketClientManagerQt::create());
} else
#endif
{
TRY(initialize_lagom_networking());
} }
Web::HTML::Window::set_internals_object_exposed(is_layout_test_mode); Web::HTML::Window::set_internals_object_exposed(is_layout_test_mode);
@ -168,3 +173,16 @@ static ErrorOr<void> load_autoplay_allowlist()
return {}; return {};
} }
static ErrorOr<void> initialize_lagom_networking()
{
auto candidate_request_server_paths = TRY(get_paths_for_helper_process("RequestServer"sv));
auto request_server_client = TRY(launch_request_server_process(candidate_request_server_paths, s_serenity_resource_root));
Web::ResourceLoader::initialize(TRY(WebView::RequestServerAdapter::try_create(move(request_server_client))));
auto candidate_web_socket_paths = TRY(get_paths_for_helper_process("WebSocket"sv));
auto web_socket_client = TRY(launch_web_socket_process(candidate_web_socket_paths, s_serenity_resource_root));
Web::WebSockets::WebSocketClientManager::initialize(TRY(WebView::WebSocketClientManagerAdapter::try_create(move(web_socket_client))));
return {};
}