Optional C++ namespaces (#4759)

Co-authored-by: Michael Winkelmann <michael@winkelmann.site>
This commit is contained in:
Wilston Oreo 2024-03-06 19:43:11 +01:00 committed by GitHub
parent 43266f7f76
commit bef532b5fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 148 additions and 19 deletions

View file

@ -5,23 +5,26 @@
## `slint_target_sources`
```
slint_target_sources(<target> <files>....)
slint_target_sources(<target> <files>.... [NAMESPACE namespace])
```
Use this function to tell cmake about the .slint files of your application, similar to the builtin cmake [target_sources](https://cmake.org/cmake/help/latest/command/target_sources.html) function.
The function takes care of running the slint-compiler to convert `.slint` files to `.h` files in the build directory,
and extend the include directories of your target so that the generated file is found when including it in your application.
The optional NAMESPACE argument will put the generated components in the given C++ namespace.
Given a file called `the_window.slint`, the following example will create a file called `the_window.h` that can
be included from your .cpp file.
be included from your .cpp file. Assuming the `the_window.slint` contains a component `TheWindow`, the output
C++ class will be put in the namespace `ui`, resulting to `ui::TheWindow`.
```cmake
add_executable(my_application main.cpp)
target_link_libraries(my_application PRIVATE Slint::Slint)
slint_target_sources(my_application the_window.slint)
slint_target_sources(my_application the_window.slint NAMESPACE ui)
```
## Resource Embedding
By default, images from [`@image-url()`](slint-reference:src/language/syntax/types#images) or fonts that your Slint files reference are loaded from disk at run-time. This minimises build times, but requires that the directory structure with the files remains stable. If you want to build a program that runs anywhere, then you can configure the Slint compiler to embed such sources into the binary.