Skip to content

dmikushin/xxd_embed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Embed resources into binary with XXD and CMake

Embed resources into binary with XXD and CMake in a cross-platform way (Linux, Windows and Mac support).

XXD converts the data file into a C array, which is slow to compile for large files, due to the way how compiler represents the array internally. In order to embed large files, please use res_embed instead.

Example

  1. Add this xxd project to your CMake project as a submodule:
cd some/path
git submodule add https://github.com/dmikushin/xxd.git
  1. Integrate xxd project into your CMakeLists.txt:
add_subdirectory(some/path/xxd)
  1. Embed the following example resource file into an executable using xxd_embed macro:
$ cat resource 
Hello, world!
set(SRCS "example.cpp")
xxd_embed("resource", ${CMAKE_CURRENT_SOURCE_DIR}/resource SRCS)

add_executable(example ${SRCS})
target_link_libraries(example xxd::xxd)
  1. Use the embedded resource in your program:
#include "xxd.h"

#include <cstdio>

int main(int argc, char* argv[])
{
	printf("%s", xxd::get("resource"));
	return 0;
}

Credits

This code uses the original public domain xxd utility, which is

(c) 1990-1998 by Juergen Weigert

About

Embed resources into binary with XXD and CMake in a cross-platform way

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors