Skip to content

Latest commit

 

History

57 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple C/C++ resource compiler

The ircc program packages the target files into a key-value store that can be connected to a C++ and C program.

Installation

cmake -S . -B build
cmake --build build
cmake --install build

This installs the ircc binary and the ircc/ircc.h public header. Use --prefix with cmake --install to choose a custom installation prefix.

Example

helloworld.txt:

HelloWorld

foo.txt:

HelloUnderWorld

resources.txt:

/hello ./helloworld.txt
another_key ./foo.txt

Given helloworld.txt, foo.txt, and resources.txt, ircc generates a standalone C++ source file:

ircc resources.txt -o ircc_resources.gen.cpp
/// ... headers

const char* const IRCC_RESOURCES_0 = 
		"\x48\x65\x6C\x6C\x6F\x57\x6F\x72\x6C\x64";

const char* const IRCC_RESOURCES_1 = 
		"\x48\x65\x6C\x6C\x6F\x55\x6E\x64\x65\x72\x57\x6F\x72\x6C\x64";

/// ... key_value_size type

struct key_value_size IRCC_RESOURCES_[] = {
	{"/hello", IRCC_RESOURCES_0, 10},
	{"another_key", IRCC_RESOURCES_1, 15},
	{NULL, NULL, 0}};

/// ... helper functions 

It can be used in program:

#include <iostream>
#include <ircc/ircc.h>

int main()
{
    std::string resource = ircc_string("/hello");
    std::cout << resource << std::endl;
    return 0;
}

List of access methods:

extern std::string ircc_string(const std::string &key);
extern std::vector<uint8_t> ircc_vector(const std::string &key);
extern std::pair<const char*, size_t> ircc_pair(const std::string &key);
extern "C" const char *ircc_c_string(const char *key, size_t *sizeptr);

Keys iteration methods:

extern std::vector<std::string> ircc_keys();
extern "C" const char *ircc_name_by_no(size_t no);

C style

ircc can generate C source with --c_only. Only the C API is emitted:

ircc resources.txt -o ircc_resources.gen.c --c_only 

CMake example

It can be used with CMake through add_custom_command:

cmake_minimum_required(VERSION 3.10)
project(my_app LANGUAGES CXX)

find_program(IRCC_EXECUTABLE NAMES ircc)
if(NOT IRCC_EXECUTABLE)
    message(FATAL_ERROR "Could not find the ircc executable")
endif()

set(RESOURCE_MANIFEST "${CMAKE_CURRENT_SOURCE_DIR}/resources.txt")
set(GENERATED_RESOURCES "${CMAKE_CURRENT_BINARY_DIR}/ircc_resources.gen.cpp")

execute_process(
    COMMAND "${IRCC_EXECUTABLE}" --sources-cmake "${RESOURCE_MANIFEST}"
    WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
    OUTPUT_VARIABLE RESOURCE_LIST
    OUTPUT_STRIP_TRAILING_WHITESPACE
)
add_custom_command(
    OUTPUT "${GENERATED_RESOURCES}"
    COMMAND "${IRCC_EXECUTABLE}" "${RESOURCE_MANIFEST}" -o "${GENERATED_RESOURCES}"
    DEPENDS "${IRCC_EXECUTABLE}" "${RESOURCE_MANIFEST}" ${RESOURCE_LIST}
    WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
    VERBATIM
)

add_executable(my_app main.cpp "${GENERATED_RESOURCES}")

Comments and directory syntax

If you have project tree like

/
	web/
		index.html
		foo.json
		bar.json
	resources.txt
	...

then resources.txt

# It is directory syntax
/web/ ./web/

will have the same effect as

/web/index.html ./web/index.html
/web/foo.json ./web/foo.json
/web/bar.json ./web/bar.json

About

IRCC. Simple c/c++ resource compiller.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages