Recommended way(s) to pre-process certain files before building/running
I'm using Qt(Creator) on Linux for C++/OpenGL projects. Before building/running, I'd like to pre-process certain files (in more detail — some GLSL files might contain lines like #pragma include snippet.glsl, these lines should be replaced by the actual contents of snippet.glsl using e.g. sed/regex or some other way — in other words, it's basically a custom include function).
I've read a bit about adding Build Steps ('Custom Process Step'), and possibly similar ways of accomplishing a pre-process step ('QMAKE_EXTRA_COMPILERS'), but I'd like some suggestions (or even better, examples) before I spend days to figure out how to do this properly.
@Ailurus Are you sure that the normal #include "snippet.glsl" can't be used? Based on quick glance at https://en.wikipedia.org/wiki/OpenGL_Shading_Language and http://en.cppreference.com/w/cpp/language/translation_phases (esp. Phase 4) I would try that first.
Can you clarify when these files should be processed? Do you plan to deploy the source files (that include the pragmas) or the processed results (with files already copy-pasted)?
Build steps are executed at , well, build time. Do you mean the actual app at runtime should use the already processed files or do the copy-pasting when a given file is used?
In any case the premise is - load the files and give them string names, then for each of them look for the pragmas with that name and replace with the loaded string. Some care needs to be taken not to fall into include loops but it should be pretty easy.
It's also worth checking if your targets support the GL_ARB_shading_language_include extension, which does exactly what I just described.
Sorry for the slow reply. Thanks both for your responses! I've had a quick look at GLSL #include before — I'm not exactly sure how to use it (this is a start though) — but apart from that, I'd prefer a way to do this in Qt, possibly more customizable and also driver-independent (e.g. I'm not sure if all graphics drivers support this GLSL extension). In addition to that, it would be a good feature to share with my students who might use Qt also for later/future projects.
I'm developing the software in an academic setting — when the (to be included) GLSL files have changed, things need to be (pre)processed again. Basically I wondered whether it's possible to automatically check .glsl files with a preprocessor for some tag (#pragma seems a good choice) and act on it, in this case use some sed/regex line to replace the mentioned file by the contents of that file. This could happen before every Build, or even before every Run (depending on how straightforward it is to save the copy-pasted version after Building and re-use it when Running, or just do this before every Run).