Embed resources into a binary using CMake, C/C++ and assembler compilers depending on the target platfrom (Linux, Windows and MacOS are supported).
Unlike xxd_embed, the files are included into an assembly file as a data directly, which is fast even for very large files. In order to compile the assembly file, NASM is deployed on Windows/MacOS, and GNU AS on all other platforms.
- Add this
res_embed
project to your CMake project as a submodule:
cd some/path
git submodule add https://github.com/dmikushin/res_embed.git
- Integrate
res_embed
project into yourCMakeLists.txt
:
add_subdirectory(some/path/res_embed)
- Embed the following example resource file into an executable using
res_embed
macro:
$ cat resource
Hello, world!
add_executable(res_example "example.cpp")
res_embed(TARGET res_example NAME "resource" PATH ${CMAKE_CURRENT_SOURCE_DIR}/resource)
- Use the embedded resource in your program:
#include "res_embed.h"
#include <cstdio>
int main(int argc, char* argv[])
{
printf("%s", res::embed::get("resource"));
return 0;
}