AUI Framework
develop
Cross-platform base for C++ UI apps
|
Assets (resource compiler) is a platform-agnostic feature provided by aui.toolbox
that embeds external files to the application's or library's binary, making them available from C++ regardless of file environment. You may want to use this if you need resources such as images, sounds or any other types of files to avoid the complexity of platform-specific means to package and locate those files.
This makes the application self-contained and reduces the surface of attack for your application and resources, as they can't be viewed or changed as easily as files lying around in user's filesystem.
To refer to an asset file, prefix the path with colon character. See AUrl for more info.
Assets can be enabled for your target with aui_compile_assets
function in your CMakeLists.txt
:
Then, create assets
directory alongside with CMakeLists.txt
:
Put your files to that dir:
Please invoke CMake configure to apply changes in assets/
:
From now, you can use the file from C++.
See also Minimal UI Template with Assets for a complete minimal example.
aui_compile_assets
adds a build time dependency to the specified target on aui.toolbox
that generates C++ files per each file found in assets/
directory. Those *.cpp
files are compiled along with your target. C++ files contain a byte array that is being registered automatically to AUI's ABuiltinFiles filesystem.
aui.toolbox
applies several transformations on a file before putting it into the *.cpp
:
Compresses the data. Although it may be redundant for already compressed file formats such as *.png
, it provides a decent compression ratio for textual files, such as *.svg
.
Also, this makes it harder to reverse engineer asset files from your binary. This is not entirely impossible, but thanks to the compression, textual files that appear in AUI assets can't be extracted with Windows Notepad.