A header only c++ library for resource injection
CmakeLists.txt:
INJECT_RESOURCES(
TARGET target_name
GENERATED_DIR <some pah>
RESOURCES_DIR <resources dir>
RESOURCES
res.txt AS NAME1
res2.txt AS NAME2
COMPILE_TIME_RESOURCES
compile_time.txt AS NAME3
)
Code.cpp:
auto stream1 = get_resource_stream<injected_resources::NAME1>();
// The resource "NAME1" will be copied and linked to the binary file.
// If NAME2 is not used in the code, then the resource "NAME2" will NOT
// be copied and linked to the binary file. (*)
constinit auto stream2 =
get_resource_stream<constinit_injected_resources::NAME3>();
// The NAME3 resource will be injected at compile time
// (*) If compilation flags "-fdata-sections -ffunction-sections -Wl,--gc-sections" are used
- Compile time stream
auto ct_lambda = [] {
using namespace injector;
auto fib_ct = injector::get_resource_stream<constinit_injected_resources::FIBONACCI_CT>();
int x = fib_value;
for (int expected : {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377}) {
fib_ct >> fib_value;
if (fib_value != expected) return false;
}
return true;
};
static_assert(ct_lambda());
- Injected enum parsing
injector::injected_resources resource;
auto s = injector::get_resource_stream<...>(); /* file content: "FIBONACCI lorem ipsum" */
s >> resource;
assert(resource == injector::injected_resources::FIBONACCI);
- via Cmake
mkdir -p build && \ cmake -B build && \ cmake --build build --target test && \ sudo cmake --build build --target install
- via Conan:
- add remote repo:
conan remote add zhekehz-conan https://zhekehz.jfrog.io/artifactory/api/conan/zhekehz-conan
- Configure CMake project:
see the exmaple subproject for more details
conan_cmake_run(REQUIRES resource-injector/0.1@zhekehz/stable) conan_basic_setup() find_package(resource-injector)
- add remote repo:
- add alignment
- refactor compile-time parsers
- ??? support binary files for COMPILE_TIME_RESOURCES