An open API service indexing awesome lists of open source software.

https://github.com/iohannrabeson/rescom

C++ resource compiler to embed files into executables
https://github.com/iohannrabeson/rescom

c-plus-plus c-plus-plus-17 cmake cpp cpp17 embedded-files linux osx resource-compiler resources tool tooling tools windows

Last synced: about 1 month ago
JSON representation

C++ resource compiler to embed files into executables

Awesome Lists containing this project

README

        

# rescom
[![CMake](https://github.com/IohannRabeson/rescom/actions/workflows/linux.yml/badge.svg)](https://github.com/IohannRabeson/rescom/actions/workflows/linux.yml)
[![CMake](https://github.com/IohannRabeson/rescom/actions/workflows/macos.yml/badge.svg)](https://github.com/IohannRabeson/rescom/actions/workflows/macos.yml)
[![CMake](https://github.com/IohannRabeson/rescom/actions/workflows/windows.yml/badge.svg)](https://github.com/IohannRabeson/rescom/actions/workflows/windows.yml)

C++ resource compiler using CMake to embed files into executables

- Tested on Windows, Linux and OSX
- Generated code does not produce warnings
- Easy to use and to integrate with CMake

## Requirements
- C++ compiler with C++17 support
- CMake 3.9 or later
- A project generator such as GNU Make, Ninja

## Tutorial

1 - Add this repository as submodule and use `add_subdirectory` in your CMakeLists.txt:
```cmake
add_subdirectory(rescom)
```
2 - Create a folder for the resources in your project, add it few files and list them in a text file (called the rescom file).
The file `rescom.list` contains the files to embed, one file per line, path must be relative to
the directory of the rescom file:
```shell
mkdir resources && echo "content.txt" > resources/rescom.list && cat "Hello world!" > content.txt
```
3 - In the CMakeLists.txt of your project, enable rescom:
```cmake
add_executable(your_project main.cpp)
# This line enable rescom, all the files listed in rescom.list will
# be embedded into the executable.
rescom_compile(your_project resources/rescom.list)
```
4 - You can now load the text file:
```c++
// `rescom.hpp` is generated by rescom driven by CMake.
#include

#include
#include

int main() {
std::cout << rescom::getText("content.txt") << "\n";
return 0;
}
```

The structure `rescom::Resource` contains the following fields:
```c++
// The unique key, it's the path of the file relative to the resources file list
char const* const key;
// Data of the resource. This address will never change during runtime.
char const* const bytes;
// Count of bytes
unsigned int const size;
```

You can see complete examples in the `tests` directory.

## How to build tests
You must set the CMake variable `RESCOM_TEST` to `ON`.