Skip to content

dmikushin/res_embed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;
}

About

Embed resources into CMake targets in a cross-platform way

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •