Skip to content

Embedding

This page documents the embedding process


Instead of always shipping the frontend files alongside your binary it is also possible to embed all the web-content into your saucer application.

Saucer offers a built-in utility to achieve this via CMake, but users are free to either generate the embedding files themselves or roll their own embedding mechanism by using custom schemes.

  • A static version of the web-page to embed

The recommended way to embed web-content is to use the saucer_embed CMake Function. Let’s assume you have a project structure similar to this:

  • Directoryout (created by e.g. pnpm run build)
    • Directorylogos
    • Directory_next
    • 404.html
    • icon.webp
    • index.html
  • package.json
  • CMakeLists.txt

Then conduct the following changes to your CMakeLists.txt:

Example: Embedding
12 collapsed lines
# --------------------------------------------------------------------------------------------------------
# Link libraries
# --------------------------------------------------------------------------------------------------------
include(FetchContent)
FetchContent_Declare(
saucer
GIT_REPOSITORY "https://github.com/saucer/saucer"
GIT_TAG $VERSION$
)
FetchContent_MakeAvailable(saucer)
saucer_embed("out")
target_link_libraries(${PROJECT_NAME} PRIVATE saucer::saucer saucer::embedded)

After linking against the generated saucer::embedded target you are all set to use the embedded files.

Example: Embedding
#include <saucer/smartview.hpp>
#include <saucer/embedded/all.hpp>
coco::stray start(saucer::application *)
{
1 collapsed line
// ...
webview->set_url("...");
webview->embed(saucer::embedded::all());
webview->serve("/index.html");
1 collapsed line
// ...
}