[CMake] Source modification using CMake

brian heim brianlheim at gmail.com
Mon Nov 6 10:34:52 EST 2017


Hi list,

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:

- Project includes C++ transpiled from a different specialized language
- That transpiler is not cross-platform, so we include transpiled C++ in
our source tree
- The generated code does not compile with MSVC 2013 because of a bug
(specifically
https://support.microsoft.com/en-us/help/315481/bug-too-many-unnested-loops-incorrectly-causes-a-c1061-compiler-error
)
- Vendor of transpiler will not patch for this case, so we need to modify
the source ourselves

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:

1. configure_file(), which doesn't seem to give tools for this purpose.
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.

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?

Thank you very much in advance for your help,

Brian H
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171106/13604d41/attachment.html>


More information about the CMake mailing list