Skip to content

Commit

Permalink
CMake: Use a helper file to find GL and EGL in a platform agnostic way
Browse files Browse the repository at this point in the history
Also add a flag to turn off accelerated graphics entirely.
  • Loading branch information
ADKaster committed Oct 31, 2023
1 parent bec1c1f commit 49d2161
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions Documentation/AdvancedBuildInstructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ There are some optional features that can be enabled during compilation that are
- `BUILD_EVERYTHING`: builds all optional components, overrides other `BUILD_<component>` flags when enabled
- `SERENITY_CACHE_DIR`: sets the location of a shared cache of downloaded files. Should not need to be set unless managing a distribution package.
- `ENABLE_NETWORK_DOWNLOADS`: allows downloading files from the internet during the build. Default on, turning off enables offline builds. For offline builds, the structure of the SERENITY_CACHE_DIR must be set up the way that the build expects.
- `ENABLE_ACCELERATED_GRAPHICS`: builds features that use accelerated graphics APIs to speed up painting and drawing using native graphics libraries.

Many parts of the SerenityOS codebase have debug functionality, mostly consisting of additional messages printed to the debug console. This is done via the `<component_name>_DEBUG` macros, which can be enabled individually at build time. They are listed in [this file](../Meta/CMake/all_the_debug_macros.cmake).

Expand Down
14 changes: 14 additions & 0 deletions Meta/CMake/accelerated_graphics.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
if (NOT ENABLE_ACCELERATED_GRAPHICS OR EMSCRIPTEN)
# FIXME: Enable GL emulation in emscripten: https://emscripten.org/docs/porting/multimedia_and_graphics/OpenGL-support.html
set(HAS_ACCELERATED_GRAPHICS OFF CACHE BOOL "" FORCE)
return()
endif()

find_package(OpenGL COMPONENTS OpenGL EGL)

if (OPENGL_FOUND)
set(HAS_ACCELERATED_GRAPHICS ON CACHE BOOL "" FORCE)
set(ACCEL_GFX_LIBS OpenGL::OpenGL OpenGL::EGL CACHE STRING "" FORCE)
else()
set(HAS_ACCELERATED_GRAPHICS OFF CACHE BOOL "" FORCE)
endif()
1 change: 1 addition & 0 deletions Meta/CMake/common_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ serenity_option(ENABLE_PUBLIC_SUFFIX_DOWNLOAD ON CACHE BOOL "Enable download of
serenity_option(INCLUDE_WASM_SPEC_TESTS OFF CACHE BOOL "Download and include the WebAssembly spec testsuite")
serenity_option(INCLUDE_FLAC_SPEC_TESTS OFF CACHE BOOL "Download and include the FLAC spec testsuite")
serenity_option(ENABLE_CACERT_DOWNLOAD ON CACHE BOOL "Enable download of cacert.pem at build time")
serenity_option(ENABLE_ACCELERATED_GRAPHICS ON CACHE BOOL "Enable use of accelerated graphics APIs")

serenity_option(HACKSTUDIO_BUILD OFF CACHE BOOL "Automatically enabled when building from HackStudio")

Expand Down
6 changes: 4 additions & 2 deletions Userland/Libraries/LibAccelGfx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
if (LINUX)
include(accelerated_graphics)

if (HAS_ACCELERATED_GRAPHICS)
set(SOURCES
Canvas.cpp
Context.cpp
Painter.cpp
)

serenity_lib(LibAccelGfx accelgfx)
target_link_libraries(LibAccelGfx PRIVATE LibGfx GL EGL)
target_link_libraries(LibAccelGfx PRIVATE LibGfx ${ACCEL_GFX_LIBS})
endif()
8 changes: 3 additions & 5 deletions Userland/Libraries/LibWeb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include(libweb_generators)
include(accelerated_graphics)

set(SOURCES
ARIA/AriaData.cpp
Expand Down Expand Up @@ -626,10 +627,6 @@ set(SOURCES
XML/XMLDocumentBuilder.cpp
)

if (LINUX)
list(APPEND SOURCES Painting/PaintingCommandExecutorGPU.cpp)
endif()

invoke_generator(
"AriaRoles.cpp"
Lagom::GenerateAriaRoles
Expand Down Expand Up @@ -663,7 +660,8 @@ serenity_lib(LibWeb web)
target_link_libraries(LibWeb PRIVATE LibCore LibCrypto LibJS LibMarkdown LibHTTP LibGemini LibGL LibGUI LibGfx LibIPC LibLocale LibRegex LibSoftGPU LibSyntax LibTextCodec LibUnicode LibAudio LibVideo LibWasm LibXML LibIDL)
link_with_locale_data(LibWeb)

if (LINUX)
if (HAS_ACCELERATED_GRAPHICS)
target_sources(LibWeb PRIVATE Painting/PaintingCommandExecutorGPU.cpp)
target_link_libraries(LibWeb PRIVATE LibAccelGfx)
endif()

Expand Down

0 comments on commit 49d2161

Please sign in to comment.