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
- Host: GitHub
- URL: https://github.com/iohannrabeson/rescom
- Owner: IohannRabeson
- Created: 2021-05-14T20:38:21.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-07T04:33:42.000Z (about 2 years ago)
- Last Synced: 2025-03-24T17:52:41.657Z (about 2 months ago)
- Topics: c-plus-plus, c-plus-plus-17, cmake, cpp, cpp17, embedded-files, linux, osx, resource-compiler, resources, tool, tooling, tools, windows
- Language: C++
- Homepage:
- Size: 128 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rescom
[](https://github.com/IohannRabeson/rescom/actions/workflows/linux.yml)
[](https://github.com/IohannRabeson/rescom/actions/workflows/macos.yml)
[](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
#includeint 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`.