Your First Application
On this page you'll learn how to setup your very first saucer project.
caution
Make sure you've read the previous pages and have the system dependencies installed!
CMake Setup
In this example I'll use CMake as my build system of choice and make saucer available through FetchContent.
CMakeLists.txt
cmake_minimum_required(VERSION 3.21)
project(your_awesome_app LANGUAGES CXX VERSION 1.0)
# --------------------------------------------------------------------------------------------------------
# Create executable
# --------------------------------------------------------------------------------------------------------
add_executable(${PROJECT_NAME} "main.cpp")
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_23)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 23 CXX_EXTENSIONS OFF CXX_STANDARD_REQUIRED ON)
# --------------------------------------------------------------------------------------------------------
# Link libraries
# --------------------------------------------------------------------------------------------------------
include(FetchContent)
FetchContent_Declare(
saucer
GIT_REPOSITORY "https://github.com/saucer/saucer"
GIT_TAG v4.2.0
)
FetchContent_MakeAvailable(saucer)
target_link_libraries(${PROJECT_NAME} PRIVATE saucer::saucer)
The Program
Now that you've setup your CMakeLists you can go ahead and create your first basic saucer application!
main.cpp
#include <saucer/smartview.hpp>
int main()
{
auto app = saucer::application::acquire({ // Instantiate application
.id = "hello-world", // Choose a suitable ID for your program
});
saucer::smartview smartview{{ // Instantiate smartview
.application = app,
}};
smartview.set_title("Hello World!"); // Set the window title to "Hello World!"
// Expose a synchronous native function "add_ten" using the default serializer
smartview.expose("add_ten", [](int i)
{
return i + 10;
});
smartview.set_url("https://google.com"); // Navigate to google.com
smartview.show(); // Show the smartview
app->run(); // And finally enter the run-loop.
return 0;
}
That's it, you've now created a really basic saucer application.