This script will work for your simple input. It will require extra escaping work if you need to embed double quotes or backslashes. And I do not claim it is correct for all arbitrary input. But.... it's a starting point, in the CMake language. Let me know if it gives you any troubles.<div>
<br></div><div><br></div><div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo"><span style="color: #c22a9f">set</span>(input_file <span style="color: #da2e24">"<a href="http://square.cl">square.cl</a>"</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo"><span style="color: #c22a9f">set</span>(output_file <span style="color: #da2e24">"square.h"</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"># Read the whole input file:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419">#</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #c22a9f">file</span><span style="color: #000000">(</span><span style="color: #c22a9f">READ</span><span style="color: #000000"> </span>"${input_file}"<span style="color: #000000"> contents)</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"># Split it into lines:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"># (insert line-ending 'E' chars to allow lines to be blank or end with</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"># semi-colons but still be iterate-able via CMake foreach...)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419">#</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #c22a9f">string</span><span style="color: #000000">(</span><span style="color: #c22a9f">REGEX</span><span style="color: #000000"> </span><span style="color: #c22a9f">REPLACE</span><span style="color: #000000"> </span>";"<span style="color: #000000"> </span>"\\\\;"<span style="color: #000000"> contents </span>"${contents}"<span style="color: #000000">)</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #c22a9f">string</span><span style="color: #000000">(</span><span style="color: #c22a9f">REGEX</span><span style="color: #000000"> </span><span style="color: #c22a9f">REPLACE</span><span style="color: #000000"> </span>"\n"<span style="color: #000000"> </span>"E;"<span style="color: #000000"> contents </span>"${contents}"<span style="color: #000000">)</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"># Open output file:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419">#</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #c22a9f">file</span><span style="color: #000000">(</span><span style="color: #c22a9f">WRITE</span><span style="color: #000000"> </span>"${output_file}"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #000000"> </span>"const char *KernelSource =\n"<span style="color: #000000">)</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"># Send each line to output file:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419">#</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo"><span style="color: #c22a9f">foreach</span>(lineE ${contents})</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"><span style="color: #000000"> </span># Get rid of the trailing 'E':</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo"> <span style="color: #008419">#</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #000000"> </span><span style="color: #c22a9f">string</span><span style="color: #000000">(</span><span style="color: #c22a9f">REGEX</span><span style="color: #000000"> </span><span style="color: #c22a9f">REPLACE</span><span style="color: #000000"> </span>"^(.*)E$"<span style="color: #000000"> </span>"\\1"<span style="color: #000000"> line </span>"${lineE}"<span style="color: #000000">)</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #000000"> </span><span style="color: #c22a9f">file</span><span style="color: #000000">(</span><span style="color: #c22a9f">APPEND</span><span style="color: #000000"> </span>"${output_file}"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #000000"> </span>" \"${line}\"\n"<span style="color: #000000">)</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #c22a9f">endforeach<span style="color: #000000">()</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"># Close output file:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419">#</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #c22a9f">file</span><span style="color: #000000">(</span><span style="color: #c22a9f">APPEND</span><span style="color: #000000"> </span>"${output_file}"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #000000"> </span>";\n"<span style="color: #000000">)</span></p><div><font class="Apple-style-span" face="Menlo" size="4"><span class="Apple-style-span" style="font-size: 14px;"><br>
</span></font></div></div><div><br></div><div>Cheers,</div><div>David</div><div><br><br><div class="gmail_quote">On Tue, Jun 15, 2010 at 5:24 PM, David Cole <span dir="ltr"><<a href="mailto:david.cole@kitware.com">david.cole@kitware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div><div></div><div class="h5">On Tue, Jun 15, 2010 at 5:13 PM, Daniel Blezek <span dir="ltr"><<a href="mailto:Blezek.Daniel@mayo.edu" target="_blank">Blezek.Daniel@mayo.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">
<div>
<font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size:11pt">Hi,<br>
<br>
We would like to convert an OpenCL program written in a separate file to a C++ header (essentially a long string).<br>
<br>
For example, if my OpenCL program is in the file Square.cl<br>
<br>
__kernel square( <br>
__global float* input, <br>
__global float* output, <br>
const unsigned int count) <br>
{ <br>
int i = get_global_id(0); <br>
if(i < count) <br>
output[i] = input[i] * input[i]; <br>
} <br>
<br>
I’d like to turn it into something like this in Square.h:<br>
<br>
const char *KernelSource = "\n" \<br>
"__kernel square( \n" \<br>
" __global float* input, \n" \<br>
" __global float* output, \n" \<br>
" const unsigned int count) \n" \<br>
"{ \n" \<br>
" int i = get_global_id(0); \n" \<br>
" if(i < count) \n" \<br>
" output[i] = input[i] * input[i]; \n" \<br>
"} \n" \<br>
"\n";<br>
<br>
So that my OpenCL code can be directly compiled into my executable. This is also useful for OpenGL shaders.<br>
<br>
The question: is this something that CMake could do? If so, any examples where to begin looking?<br></span></font></div></blockquote></div></div><div><br><br>It is. CMake can definitely do that. I know I've written code like this somewhere... I have to dash off at the moment, but when I get back to a computer, I'll see if I can look it up and pass along a function that does something similar.<br>
<br>Unless somebody else beats me to it. :-)<br><br>- David<br></div></div><br>
</blockquote></div><br></div>