Skip to content

Latest commit

 

History

History
47 lines (32 loc) · 1.21 KB

README.md

File metadata and controls

47 lines (32 loc) · 1.21 KB

Embed resources into CMake targets in a cross-platform way

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.

Example

  1. 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
  1. Integrate res_embed project into your CMakeLists.txt:
add_subdirectory(some/path/res_embed)
  1. 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)
  1. 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;
}