Skip to content

IohannRabeson/rescom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rescom

CMake CMake CMake

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:

   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:

mkdir resources && echo "content.txt" > resources/rescom.list && cat "Hello world!" > content.txt

3 - In the CMakeLists.txt of your project, enable rescom:

   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:

// `rescom.hpp` is generated by rescom driven by CMake.
#include <rescom.hpp>  

#include <iostream>
#include <string>

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

The structure rescom::Resource contains the following fields:

// 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.