Skip to content

Commit

Permalink
Ladybird/Meta: Convert to CMake build
Browse files Browse the repository at this point in the history
  • Loading branch information
ADKaster committed Dec 25, 2022
1 parent da19b78 commit 74fda4a
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 43 deletions.
2 changes: 2 additions & 0 deletions Ladybird/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ Makefile
ladybird
*.o
moc_*
Build
build
61 changes: 61 additions & 0 deletions Ladybird/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
cmake_minimum_required(VERSION 3.16...3.22)

project(ladybird
VERSION 0.0.1
LANGUAGES CXX
DESCRIPTION "Ladybird Web Browser"
)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# See slide 100 of the following ppt :^)
# https://crascit.com/wp-content/uploads/2019/09/Deep-CMake-For-Library-Authors-Craig-Scott-CppCon-2019.pdf
if (NOT APPLE)
set(CMAKE_INSTALL_RPATH $ORIGIN)
endif()
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

include(cmake/EnableLLD.cmake)

# Lagom
include(FetchContent)
include(cmake/FetchLagom.cmake)

# Lagom warnings
include(${Lagom_SOURCE_DIR}/../CMake/lagom_compile_options.cmake)
add_compile_options(-Wno-expansion-to-defined)

set(CMAKE_AUTOMOC ON)
find_package(Qt6 REQUIRED COMPONENTS Core Widgets)

# FIXME: Stop using deprecated declarations from QT :^)
add_compile_options(-Wno-deprecated-declarations)

set(SOURCES
BrowserWindow.cpp
main.cpp
WebView.cpp
)

add_executable(ladybird ${SOURCES})
target_link_libraries(ladybird PRIVATE Qt6::Widgets Lagom::Web Lagom::HTTP Lagom::WebSocket Lagom::Main)

get_filename_component(
SERENITY_SOURCE_DIR "${Lagom_SOURCE_DIR}/../.."
ABSOLUTE
)

add_custom_target(run
COMMAND "${CMAKE_COMMAND}" -E env "SERENITY_SOURCE_DIR=${SERENITY_SOURCE_DIR}" "$<TARGET_FILE:ladybird>"
USES_TERMINAL
)

add_custom_target(debug
COMMAND "${CMAKE_COMMAND}" -E env "SERENITY_SOURCE_DIR=${SERENITY_SOURCE_DIR}" gdb "$<TARGET_FILE:ladybird>"
USES_TERMINAL
)

51 changes: 51 additions & 0 deletions Ladybird/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Ladybird Web Browser

The Ladybird Web Browser is a browser using the SerenityOS LibWeb engine with a QT GUI.

## Build Prerequisites

QT6 development packages and a c++20-enabled compiler are required. On Debian/Ubuntu required packages include, but are not limited to:

```
sudo apt install build-essential cmake ninja-build qt6-base-dev qt6-tools-dev-tools
```

For the c++ compiler, gcc-11 or clang-13 are required at a minimum for c++20 support.

For Ubuntu 20.04 and above, ensure that the QT6 Wayland packages are available:

```
sudo apt install qt6-wayland
```


## Build steps

Basic workflow, using serenity source dir cloned from github:

```
cmake -GNinja -B Build
cmake --build Build
ninja -C Build run
```

Advanced workflow, using pre-existing serenity checkout.

If you previously didn't set SERENITY_SOURCE_DIR, probably want to blast the Build directory before doing this:

```
cmake -GNinja -B Build -DSERENITY_SOURCE_DIR=/path/to/serenity
ninja -C Build run
```

To automatically run in gdb:
```
ninja -C Build debug
```

To run without ninja rule:
```
# or your existing serenity checkout /path/to/serenity
export SERENITY_SOURCE_DIR=${PWD}/Build/serenity
./Build/ladybird
```
20 changes: 16 additions & 4 deletions Ladybird/WebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
#include <QPaintEvent>
#include <QPainter>
#include <QScrollBar>
#include <stdlib.h>

String s_serenity_resource_root = [] {
auto const* source_dir = getenv("SERENITY_SOURCE_DIR");
if (source_dir) {
return String::formatted("{}/Base", source_dir);
}
auto* home = getenv("XDG_CONFIG_HOME") ?: getenv("HOME");
VERIFY(home);
return String::formatted("{}/.lagom", home);
}();

class HeadlessBrowserPageClient final : public Web::PageClient {
public:
Expand Down Expand Up @@ -271,7 +282,7 @@ WebView::WebView()

m_page_client = HeadlessBrowserPageClient::create(*this);

m_page_client->setup_palette(Gfx::load_system_theme("/home/kling/src/serenity/Base/res/themes/Default.ini"));
m_page_client->setup_palette(Gfx::load_system_theme(String::formatted("{}/res/themes/Default.ini", s_serenity_resource_root)));

// FIXME: Allow passing these values as arguments
m_page_client->set_viewport_rect({ 0, 0, 800, 600 });
Expand Down Expand Up @@ -794,12 +805,13 @@ void initialize_web_engine()
Web::ResourceLoader::initialize(HeadlessRequestServer::create());
Web::WebSockets::WebSocketClientManager::initialize(HeadlessWebSocketClientManager::create());

Web::FrameLoader::set_default_favicon_path("/home/kling/src/serenity/Base/res/icons/16x16/app-browser.png");
Web::FrameLoader::set_default_favicon_path(String::formatted("{}/res/icons/16x16/app-browser.png", s_serenity_resource_root));
dbgln("Set favoicon path to {}", String::formatted("{}/res/icons/16x16/app-browser.png", s_serenity_resource_root));

Gfx::FontDatabase::set_default_fonts_lookup_path("/home/kling/src/serenity/Base/res/fonts");
Gfx::FontDatabase::set_default_fonts_lookup_path(String::formatted("{}/res/fonts", s_serenity_resource_root));

Gfx::FontDatabase::set_default_font_query("Katica 10 400 0");
Gfx::FontDatabase::set_fixed_width_font_query("Csilla 10 400 0");

Web::FrameLoader::set_error_page_url("file:https:///home/kling/src/serenity/Base/res/html/error.html");
Web::FrameLoader::set_error_page_url(String::formatted("file:https://{}/res/html/error.html", s_serenity_resource_root));
}
14 changes: 14 additions & 0 deletions Ladybird/cmake/EnableLLD.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

option(LADYBIRD_USE_LLD "Use llvm lld to link application" ON)
if (LADYBIRD_USE_LLD AND NOT APPLE)
find_program(LLD_LINKER NAMES "ld.lld")
if (NOT LLD_LINKER)
message(INFO "LLD not found, cannot use to link. Disabling option...")
set(LADYBIRD_USE_LLD OFF CACHE BOOL "" FORCE)
endif()
endif()
if (LADYBIRD_USE_LLD AND NOT APPLE)
add_link_options(-fuse-ld=lld)
add_compile_options(-ggnu-pubnames)
add_link_options(LINKER:--gdb-index)
endif()
33 changes: 33 additions & 0 deletions Ladybird/cmake/FetchLagom.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2021, Andrew Kaster <[email protected]>
#
# SPDX-License-Identifier: MIT

# Fetch serenity, so that we can build Lagom from it
FetchContent_Declare(lagom
GIT_REPOSITORY https://github.com/SerenityOS/serenity.git
GIT_TAG origin/master
GIT_SHALLOW TRUE
SOURCE_DIR serenity
)

# Allow developers to skip download/update steps with local checkout
if (SERENITY_SOURCE_DIR)
set(FETCHCONTENT_SOURCE_DIR_LAGOM ${SERENITY_SOURCE_DIR} CACHE PATH "Developer's pre-existing serenity source directory" FORCE)
message(STATUS "Using pre-existing SERENITY_SOURCE_DIR: ${SERENITY_SOURCE_DIR}")
endif()

# Can't use FetchContent_MakeAvailable b/c we want to use the Lagom build, not the main build
# Populate source directory for lagom
FetchContent_GetProperties(lagom)
if (NOT lagom_POPULATED)
FetchContent_Populate(lagom)
set(BUILD_LAGOM ON CACHE INTERNAL "Build all Lagom targets")

# FIXME: Setting target_include_directories on Lagom libraries might make this unecessary?
include_directories(${lagom_SOURCE_DIR}/Userland/Libraries)
include_directories(${lagom_SOURCE_DIR})
include_directories(${lagom_BINARY_DIR})

# We set EXCLUDE_FROM_ALL to make sure that only required Lagom libraries are built
add_subdirectory(${lagom_SOURCE_DIR}/Meta/Lagom ${lagom_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
39 changes: 0 additions & 39 deletions Ladybird/ladybird.pro

This file was deleted.

0 comments on commit 74fda4a

Please sign in to comment.