I have an online generator used to create header files used to embed assets into firmware.
It is here: https://honeythecodewitch.com/gfx/converter
The issue is due to web considerations, it's problematic to generate both a header file and an implementation file for one bit of content.
To that end I've included the implementation of each in the header itself wrapped with a #define based guard.
// Add #define DISCONNECTED_ICON_IMPLEMENTATION
// to exactly one CPP file before including this file
#pragma once
#include <stdint.h>
#include <gfx.hpp>
extern const uint8_t disconnected_icon_data[];
extern gfx::const_buffer_stream disconnected_icon_stream;
extern const gfx::svg_doc disconnected_icon;
#ifdef DISCONNECTED_ICON_IMPLEMENTATION
const uint8_t disconnected_icon_data[] = {
... (omitted)
};
... etc
#endif // DISCONNECTED_ICON_IMPLEMENTATION
My question is two parts.
- Is there a better way to accomplish what I need than above and
- I was thinking of adding the following to the header
#ifndef DISCONNECTED_ICON_IMPLEMENTATION
#define DISCONNECTED_ICON_IMPLEMENTATION
#endif // !DISCONNECTED_ICON_IMPLEMENTATION
Such that it would automagically include the source in exactly one implementation file.
Can anyone see any issues with this in terms of causing problems with compilation or anything? Like any scenario that would break it?