Greetings CMake forum! This place looks familiar because I’m a member of another Discourse-powered forum
Here’s my situation. I wrote several SFML projects for my own amusement, and hardcoded paths to all the resource files. Now I’m trying publish the projects on GitHub and I’d like to embed the resources.
So far I have successfully used xxd -i
to turn “image1.png” into “image1.hpp” which contains the identifiers image1_png
and image1_png_len
, and so on for other resources. I can #include "image1.hpp"
etc. and have access to the identifiers and byte arrays.
However, my existing code contains many lists of filenames (without paths). These are used something like this:
for (auto& fname : resourceList) {
Texture tx;
tx.loadFromFile(fname);
textures.push_back(tx);
}
What I need to convert to (hopefully without having to handwrite the identifiers for hundreds of resource files) is something like:
tx.loadFromMemory(identMap[fname], identLenMap[fname]);
So, for every loadFromFile("image.png")
I need loadFromMemory(image_png, image_png_len)
, but the values would be coming from a loop variable.
Stack Overflow indicated that you could “have the build process fill out the initializer of this vector with pairs of file names and names of the byte arrays”, and I assumed they meant CMake by that. Can I somehow point CMake to a list of filename strings and have it give me a map/vector-of-pairs/whatever so that I can supply arguments to loadFromMemory
? Should I just be doing this with a rexReplace in an editor?
Thanks!
(By the way, mods: as I write in this topic box, my active line is so close to the bottom of the box that I can’t see underscores as I type (when using the return key: I can manually swipe further). Can there be a little bit more padding after hitting return? Just a suggestion! )