<div dir="ltr">Hi list,<br><br>Hope you're doing well. I have a question about using CMake to patch the source code in a project I work on. This is the situation:<br><br>- Project includes C++ transpiled from a different specialized language<br>- That transpiler is not cross-platform, so we include transpiled C++ in our source tree<br>- The generated code does not compile with MSVC 2013 because of a bug (specifically <a href="https://support.microsoft.com/en-us/help/315481/bug-too-many-unnested-loops-incorrectly-causes-a-c1061-compiler-error">https://support.microsoft.com/en-us/help/315481/bug-too-many-unnested-loops-incorrectly-causes-a-c1061-compiler-error</a>)<br>- Vendor of transpiler will not patch for this case, so we need to modify the source ourselves<div><br></div><div>We don't want to _directly_ modify the source because that means we'll have to [remember to] do it on a regular basis, when new or updated source files are added. The patching is simple enough that it can be done with a regex. I am not very experienced with CMake, but I'm aware that two ways of modifying source files are:</div><div><br></div><div>1. configure_file(), which doesn't seem to give tools for this purpose.</div><div>2. file(READ ...) followed by file(WRITE ...). I've gotten my regex to work with it, but my attempt overwrites the source file in-place, unlike configure_file() which places the modified file in the build tree.</div><div><br></div><div>Is there a way to do (2) correctly? By which I mean, can I do a form of configure_file() using a regex? Or is there an altogether easier solution that's staring me in the face?</div><div><br></div><div>Thank you very much in advance for your help,</div><div><br></div><div>Brian H</div></div>